From 31f93961ba87eec3217a9a5fd0de0608df1883ec Mon Sep 17 00:00:00 2001 From: Vincent Koc Date: Sat, 5 Dec 2026 09:11:11 +0800 Subject: [PATCH] test(desktop): share reading-list expected value checks (#16885) --- src/domain/desktop/appTaskDraftJson.test.ts | 95 ++++++++------------- 1 file changed, 35 insertions(+), 60 deletions(-) diff --git a/src/domain/desktop/appTaskDraftJson.test.ts b/src/domain/desktop/appTaskDraftJson.test.ts index 7b82d1cf8bf..32892d2e309 100644 --- a/src/domain/desktop/appTaskDraftJson.test.ts +++ b/src/domain/desktop/appTaskDraftJson.test.ts @@ -14,6 +14,13 @@ import type { DesktopTaskCheckInput } from "./appTask.js"; const FILE = "Documents/reading-list.trln"; +const expectedValueCheck = (pointer: string, value: string) => ({ + kind: "value_equals", + file: FILE, + pointer, + value, +}); + /** A TreeLine outline: nodes saved sorted by their generated uid1, each with its kind (`format`), data and children's uids. */ const outline = ( books: readonly (readonly [string, string])[], @@ -147,12 +154,7 @@ describe("draftTaskFiles for records in a JSON array, as TreeLine saves its node const guns = "/nodes/[uid=812403bed9f511f19fc4edd4f1920549]"; expect(file.suggested).toEqual([ - { - kind: "value_equals", - file: FILE, - pointer: `${guns}/data/Title`, - value: "The Guns of August, revised", - }, + expectedValueCheck(`${guns}/data/Title`, "The Guns of August, revised"), ]); expect(file.guards).toEqual([ { kind: "member_count", file: FILE, pointer: "/nodes", equals: 3 }, @@ -172,12 +174,7 @@ describe("draftTaskFiles for records in a JSON array, as TreeLine saves its node const silk = "/nodes/[format=BOOK][>data~1Title=The Silk Roads]"; expect(file.suggested).toEqual([ - { - kind: "value_equals", - file: FILE, - pointer: `${silk}/data/Year`, - value: "2015", - }, + expectedValueCheck(`${silk}/data/Year`, "2015"), { kind: "member_count", file: FILE, @@ -396,12 +393,10 @@ describe("draftTaskFiles for a new JSON record named by a field inside it", () = const OLD = note("812403bed9f511f19fc4edd4f1920549", "Old"); const nodes = (...members: unknown[]) => ({ nodes: members }) as unknown as JsonValue; - const titled = { - kind: "value_equals", - file: FILE, - pointer: "/nodes/[>data~1Title=New]/data/Title", - value: "New", - }; + const titled = expectedValueCheck( + "/nodes/[>data~1Title=New]/data/Title", + "New", + ); const first = drafted(nodes(), nodes(NEW)); const joined = drafted(nodes(OLD), nodes(OLD, NEW)); @@ -566,18 +561,14 @@ describe("draftTaskFiles for a book added under a category, as TreeLine saved on const file = drafted(seed, end); expect(file.suggested).toEqual([ - { - kind: "value_equals", - file: FILE, - pointer: `${book("The Clockwork Ocean")}/data/Author`, - value: "Priya Lindqvist", - }, - { - kind: "value_equals", - file: FILE, - pointer: `${book("The Clockwork Ocean")}/data/Copyright`, - value: "2020", - }, + expectedValueCheck( + `${book("The Clockwork Ocean")}/data/Author`, + "Priya Lindqvist", + ), + expectedValueCheck( + `${book("The Clockwork Ocean")}/data/Copyright`, + "2020", + ), { kind: "member_count", file: FILE, @@ -593,30 +584,19 @@ describe("draftTaskFiles for a book added under a category, as TreeLine saved on }, ]); expect(file.guards).toEqual([ - { - kind: "value_equals", - file: FILE, - pointer: `${book("Small Engines of Life")}/data/Author`, - value: "Dev Ramanathan", - }, - { - kind: "value_equals", - file: FILE, - pointer: `${book("The Quiet Glacier")}/data/Author`, - value: "Ines Halvorsen", - }, - { - kind: "value_equals", - file: FILE, - pointer: `${book("Small Engines of Life")}/data/Copyright`, - value: "2021", - }, - { - kind: "value_equals", - file: FILE, - pointer: `${book("The Quiet Glacier")}/data/Copyright`, - value: "2018", - }, + expectedValueCheck( + `${book("Small Engines of Life")}/data/Author`, + "Dev Ramanathan", + ), + expectedValueCheck( + `${book("The Quiet Glacier")}/data/Author`, + "Ines Halvorsen", + ), + expectedValueCheck( + `${book("Small Engines of Life")}/data/Copyright`, + "2021", + ), + expectedValueCheck(`${book("The Quiet Glacier")}/data/Copyright`, "2018"), ]); expect(passing(seed, file.suggested)).toEqual([false, false, false, false]); expect(passing(end, file.suggested)).toEqual([true, true, true, true]); @@ -696,12 +676,7 @@ describe("draftTaskFiles for a book added under a category, as TreeLine saved on ); expect(file.guards).toEqual([ - { - kind: "value_equals", - file: FILE, - pointer: `${book("Volume 24")}/data/Author`, - value: "Author 24", - }, + expectedValueCheck(`${book("Volume 24")}/data/Author`, "Author 24"), ]); }); });