|
1 | 1 | import { beforeEach, describe, expect, it, vi } from "vitest"; |
2 | 2 |
|
| 3 | +type SettingsTreeNode = { |
| 4 | + text: string; |
| 5 | + children?: SettingsTreeNode[]; |
| 6 | +}; |
| 7 | + |
| 8 | +type GetSettingValueArgs = { |
| 9 | + tree?: SettingsTreeNode[]; |
| 10 | + key: string; |
| 11 | +}; |
| 12 | + |
3 | 13 | vi.mock("roamjs-components/util/getSubTree", () => ({ |
4 | 14 | default: vi.fn(), |
5 | 15 | })); |
6 | 16 | vi.mock("roamjs-components/util/getSettingValueFromTree", () => ({ |
7 | 17 | default: vi.fn( |
8 | | - ({ tree, key }) => |
| 18 | + ({ tree = [], key }: GetSettingValueArgs): string => |
9 | 19 | tree.find((t: { text: string }) => t.text === key)?.children?.[0]?.text || |
10 | 20 | "", |
11 | 21 | ), |
@@ -42,23 +52,36 @@ describe("parseQuery", () => { |
42 | 52 | ], |
43 | 53 | }; |
44 | 54 | mockedGetSubTree.mockImplementation(({ key }) => { |
45 | | - if (key === "conditions") return { uid: "conditions-uid", children: [] }; |
| 55 | + if (key === "conditions") { |
| 56 | + return { uid: "conditions-uid", text: "conditions", children: [] }; |
| 57 | + } |
46 | 58 | if (key === "selections") { |
47 | 59 | return { |
48 | 60 | uid: "selections-uid", |
| 61 | + text: "selections", |
49 | 62 | children: [ |
50 | | - { uid: "sel-node", text: "node", children: [{ text: "Title" }] }, |
| 63 | + { |
| 64 | + uid: "sel-node", |
| 65 | + text: "node", |
| 66 | + children: [{ uid: "title-label", text: "Title", children: [] }], |
| 67 | + }, |
51 | 68 | { |
52 | 69 | uid: "sel-created", |
53 | 70 | text: "created", |
54 | | - children: [{ text: "Created" }], |
| 71 | + children: [ |
| 72 | + { uid: "created-label", text: "Created", children: [] }, |
| 73 | + ], |
55 | 74 | }, |
56 | 75 | ], |
57 | 76 | }; |
58 | 77 | } |
59 | 78 | return { |
60 | 79 | uid: "custom-uid", |
61 | | - children: [{ text: "[:find ?x]" }, { text: "enabled" }], |
| 80 | + text: "custom", |
| 81 | + children: [ |
| 82 | + { uid: "custom-query", text: "[:find ?x]", children: [] }, |
| 83 | + { uid: "custom-enabled", text: "enabled", children: [] }, |
| 84 | + ], |
62 | 85 | }; |
63 | 86 | }); |
64 | 87 |
|
|
0 commit comments