Spaces:
Paused
Paused
Download apps/web/tests/documentReader.test.ts from nathycodes/presentercoach: direct link, hf CLI and curl.
- Browser
- Download file 1.7 kB
-
https://huggingface.co/spaces/nathycodes/presentercoach/resolve/main/apps/web/tests/documentReader.test.ts
- Command line
-
hf download hf://spaces/nathycodes/presentercoach/apps/web/tests/documentReader.test.ts
-
curl -L -o documentReader.test.ts https://huggingface.co/spaces/nathycodes/presentercoach/resolve/main/apps/web/tests/documentReader.test.ts
1.7 kB
| import { describe, expect, it } from "vitest"; | |
| import { buildDocumentBlocks, findBestMatchingDocumentBlock, normalizeDocumentText } from "@/lib/documentReader"; | |
| describe("document reader utilities", () => { | |
| it("normalizes punctuation and casing for matching", () => { | |
| expect(normalizeDocumentText("Hello, WORLD!")).toBe("hello world"); | |
| }); | |
| it("splits source text into readable blocks", () => { | |
| const blocks = buildDocumentBlocks(` | |
| First paragraph with enough words to stay together for reading. | |
| Second paragraph. It has two sentences so it can still be highlighted clearly. | |
| `); | |
| expect(blocks.length).toBeGreaterThan(1); | |
| expect(blocks[0].index).toBe(0); | |
| expect(blocks[0].text).toContain("First paragraph"); | |
| }); | |
| it("finds the best forward document block from recent speech", () => { | |
| const blocks = buildDocumentBlocks(` | |
| Welcome to the introduction paragraph. | |
| This section explains the migration strategy and rollout details. | |
| Final section covers testing and cleanup. | |
| `); | |
| const nextIndex = findBestMatchingDocumentBlock( | |
| blocks, | |
| [{ startMs: 0, endMs: 1500, text: "This section explains the migration strategy in more detail" }], | |
| "", | |
| 0 | |
| ); | |
| expect(nextIndex).toBe(1); | |
| }); | |
| it("keeps the current block when no confident match exists", () => { | |
| const blocks = buildDocumentBlocks(` | |
| First block about metrics. | |
| Second block about transcript analysis. | |
| `); | |
| const nextIndex = findBestMatchingDocumentBlock( | |
| blocks, | |
| [{ startMs: 0, endMs: 1200, text: "Completely unrelated words here" }], | |
| "", | |
| 0 | |
| ); | |
| expect(nextIndex).toBe(0); | |
| }); | |
| }); | |