Files
TJWaterFrontend_Refine/src/components/chat/speechStartOptions.test.ts
T
jiang cf6386d209
Build Push and Deploy / docker-image (push) Failing after 1m17s
Build Push and Deploy / deploy-fallback-log (push) Successful in 0s
feat(chat): add Edge TTS playback
2026-07-08 18:39:49 +08:00

32 lines
1.1 KiB
TypeScript

import {
findSpeechSelectionStartOffset,
splitSpeechTextIntoChunks,
} from "./speechStartOptions";
describe("findSpeechSelectionStartOffset", () => {
it("finds the reading start from selected reply text", () => {
const text = "第一段内容。\n\n第二段 包含空格。\n第三段内容。";
expect(findSpeechSelectionStartOffset(text, "第二段 包含空格")).toBe(
text.indexOf("第二段"),
);
expect(findSpeechSelectionStartOffset(text, "第三段")).toBe(text.indexOf("第三段"));
expect(findSpeechSelectionStartOffset(text, "不存在")).toBeNull();
});
});
describe("splitSpeechTextIntoChunks", () => {
it("splits long text into bounded chunks", () => {
const text = Array.from({ length: 80 }, (_, index) => `第${index}句内容足够长。`).join("");
const chunks = splitSpeechTextIntoChunks(text);
expect(chunks.length).toBeGreaterThan(1);
expect(chunks.every((chunk) => chunk.length <= 520)).toBe(true);
expect(chunks.join("")).toBe(text);
});
it("keeps short text as one chunk", () => {
expect(splitSpeechTextIntoChunks("短句。")).toEqual(["短句。"]);
});
});