Skip to content
Source
Sign inSign up
fuko/trytanstackdb.com
Open History to see the last commit

note-body.test.ts

35 lines1.4 KB

1import { expect, test } from "vite-plus/test";
2​
3import { countWords, noteSnippet, parseNoteBody } from "./note-body";
4​
5test("parseNoteBody", () => {
6 expect(parseNoteBody("Intro\n# Goals\n- one\n[ ] todo\n[x] done\n\n")).toEqual([
7 { type: "paragraph", text: "Intro" },
8 { type: "heading", text: "Goals" },
9 { type: "bullet", text: "one" },
10 { type: "checklist", text: "todo", checked: false },
11 { type: "checklist", text: "done", checked: true },
12 ]);
13});
14​
15test("noteSnippet uses the first block without its marker", () => {
16 expect(noteSnippet("[ ] Passport\n[ ] Chargers")).toBe("Passport");
17 expect(noteSnippet("")).toBe("No additional text");
18});
19​
20test("countWords counts what the editor shows, not the block markers", () => {
21 const body = "[ ] Buy milk\n[x] Call Sam\n# Plans\n- Bread";
22 // Buy, milk, Call, Sam, Plans, Bread
23 expect(countWords({ title: "", body })).toBe(6);
24 // Weekend, shopping + the 6 above
25 expect(countWords({ title: "Weekend shopping", body })).toBe(8);
26 // A paragraph, extra spaces and blank lines
27 expect(countWords({ title: " Ideas ", body: "one two\n\n\nthree" })).toBe(4);
28});
29​
30test("countWords of an empty note is 0", () => {
31 expect(countWords({ title: "", body: "" })).toBe(0);
32 expect(countWords({ title: " ", body: "\n\n" })).toBe(0);
33 // Markers alone (an empty heading, bullet or to-do) aren't words.
34 expect(countWords({ title: "", body: "# \n- \n[ ] \n[x] " })).toBe(0);
35});