diff --git a/src/domain/desktop/appTaskDraftLineGuards.test.ts b/src/domain/desktop/appTaskDraftLineGuards.test.ts index 72e5d233cb9..a01f294b2c8 100644 --- a/src/domain/desktop/appTaskDraftLineGuards.test.ts +++ b/src/domain/desktop/appTaskDraftLineGuards.test.ts @@ -5,6 +5,12 @@ import { textView } from "./stateFormats.js"; const FILE = "Documents/trip.txt"; +const expectedPresentLine = (line: string) => ({ + kind: "lines_present", + file: FILE, + lines: [line], +}); + /** A text file's lines, as a mind map exported to text keeps topics with the ids and times the app assigns. */ const lines = (...added: string[]) => [ @@ -31,9 +37,7 @@ describe("draftTaskFiles for lines holding values the app generates", () => { it("checks a reference number in ordinary text", () => { const line = "Reference: ABC_123456"; const file = drafted("# Instructions", `# Instructions\n${line}`); - expect(file.suggested).toEqual([ - { kind: "lines_present", file: FILE, lines: [line] }, - ]); + expect(file.suggested).toEqual([expectedPresentLine(line)]); expect(passingLines(file, "# Instructions\nReference: WRONG")).toEqual([ false, ]); @@ -41,9 +45,7 @@ describe("draftTaskFiles for lines holding values the app generates", () => { it("keeps an unquoted assignment in ordinary prose exact", () => { const line = "Set created=2025550123 and save"; const file = drafted("# Instructions", `# Instructions\n${line}`); - expect(file.suggested).toEqual([ - { kind: "lines_present", file: FILE, lines: [line] }, - ]); + expect(file.suggested).toEqual([expectedPresentLine(line)]); expect( passingLines(file, "# Instructions\nSet created=WRONG and save"), ).toEqual([false]); @@ -51,17 +53,13 @@ describe("draftTaskFiles for lines holding values the app generates", () => { it("keeps assignment-like text quoted in a translation", () => { const translation = 'msgstr "Set created=2025550123 and save"'; const file = drafted(lines(), lines(translation)); - expect(file.suggested).toEqual([ - { kind: "lines_present", file: FILE, lines: [translation] }, - ]); + expect(file.suggested).toEqual([expectedPresentLine(translation)]); }); it("keeps quoted ID-like text exact", () => { const line = 'msgstr "Enter ID_329023692"'; const file = drafted('msgid "Enter"', `msgid "Enter"\n${line}`); - expect(file.suggested).toEqual([ - { kind: "lines_present", file: FILE, lines: [line] }, - ]); + expect(file.suggested).toEqual([expectedPresentLine(line)]); expect(passingLines(file, 'msgid "Enter"\nmsgstr "Enter WRONG"')).toEqual([ false, ]); @@ -70,9 +68,7 @@ describe("draftTaskFiles for lines holding values the app generates", () => { it("keeps an escaped quote inside ordinary text", () => { const translation = 'msgstr "Set \\\"created=2025550123 and save"'; const file = drafted('msgid "Hello"', `msgid "Hello"\n${translation}`); - expect(file.suggested).toEqual([ - { kind: "lines_present", file: FILE, lines: [translation] }, - ]); + expect(file.suggested).toEqual([expectedPresentLine(translation)]); }); }); @@ -102,9 +98,7 @@ describe("draftTaskFiles for XML text views", () => { const line = ''; const file = drafted(`${opening}`, `${opening}${line}\n`); - expect(file.suggested).toEqual([ - { kind: "lines_present", file: FILE, lines: [line] }, - ]); + expect(file.suggested).toEqual([expectedPresentLine(line)]); const altered = line.replace("2025550123", "WRONG"); const results = passingLines(file, `${opening}${altered}\n`); expect(results).toEqual([false]); @@ -150,9 +144,7 @@ describe("draftTaskFiles for markup boundaries and incomplete XML", () => { const line = ' msgstr "Set \\\"created=2025550123 and save"'; const file = drafted("# Note", `# Note\n${line}`); - expect(file.suggested).toEqual([ - { kind: "lines_present", file: FILE, lines: [line] }, - ]); + expect(file.suggested).toEqual([expectedPresentLine(line)]); }); it("recognizes attributes after a comment inside the DTD", () => { @@ -221,9 +213,7 @@ describe("draftTaskFiles for added lines", () => { it("requires the exact caller-supplied UUID in ordinary text", () => { const line = "Tracking id: 123e4567-e89b-12d3-a456-426614174000"; const file = drafted("# Notes", `# Notes\n${line}`); - expect(file.suggested).toEqual([ - { kind: "lines_present", file: FILE, lines: [line] }, - ]); + expect(file.suggested).toEqual([expectedPresentLine(line)]); const results = passingLines(file, "# Notes\nTracking id: WRONG"); expect(results).toEqual([false]); }); @@ -250,17 +240,13 @@ describe("draftTaskFiles for added lines", () => { const opening = `<${link}>\n`; const line = 'msgstr "Set \\\"created=2025550123 and save"'; const file = drafted(opening, `${opening}${line}`); - expect(file.suggested).toEqual([ - { kind: "lines_present", file: FILE, lines: [line] }, - ]); + expect(file.suggested).toEqual([expectedPresentLine(line)]); }); it("keeps long ordinary text as a whole line", () => { const text = `msgstr "${"ordinary words ".repeat(3000)}"`; const file = drafted(lines(), lines(text)); - expect(file.suggested).toEqual([ - { kind: "lines_present", file: FILE, lines: [text] }, - ]); + expect(file.suggested).toEqual([expectedPresentLine(text)]); }); it("keeps assignment-like text exact when no XML structure identifies metadata", () => { const phone = 'topic TEXT="Call 2025550123"'; @@ -298,9 +284,7 @@ describe("draftTaskFiles for added lines", () => { it("keeps an ID-like token without a generated ID field", () => { const line = "ID_329023692 1793955250671"; const file = drafted(lines(), lines(line)); - expect(file.suggested).toEqual([ - { kind: "lines_present", file: FILE, lines: [line] }, - ]); + expect(file.suggested).toEqual([expectedPresentLine(line)]); }); it("guards a kept line beside a new one, never a lone closing tag any such file holds", () => {