-
-
Notifications
You must be signed in to change notification settings - Fork 178
Expand file tree
/
Copy pathRequirementCollector.test.ts
More file actions
107 lines (90 loc) · 3.83 KB
/
RequirementCollector.test.ts
File metadata and controls
107 lines (90 loc) · 3.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
import { describe, it, expect } from "vitest";
import { RequirementCollector } from "./RequirementCollector";
import { buildValueVariableKey } from "src/utils/valueSyntax";
// Light stubs for app/plugin
const makeApp = () => ({
workspace: { getActiveFile: () => null },
vault: { getAbstractFileByPath: () => null, cachedRead: async () => "" },
} as any);
const makePlugin = (overrides: Record<string, unknown> = {}) =>
({
settings: {
inputPrompt: "single-line",
globalVariables: {},
...overrides,
},
} as any);
describe("RequirementCollector", () => {
it("collects VALUE with default and options", async () => {
const app = makeApp();
const plugin = makePlugin();
const rc = new RequirementCollector(app, plugin);
await rc.scanString("{{VALUE:title|Untitled}} and {{VALUE:low,medium,high}}" );
const reqs = Array.from(rc.requirements.values());
const byId = Object.fromEntries(reqs.map(r => [r.id, r]));
expect(byId["title"].defaultValue).toBe("Untitled");
expect(byId["low,medium,high"].type).toBe("dropdown");
});
it("collects VALUE labels for single and multi inputs", async () => {
const app = makeApp();
const plugin = makePlugin();
const rc = new RequirementCollector(app, plugin);
const multiToken = "low,medium,high|label:Priority";
await rc.scanString(
`{{VALUE:title|label:Snake cased name}} and {{VALUE:${multiToken}}}`,
);
const reqs = Array.from(rc.requirements.values());
const byId = Object.fromEntries(reqs.map((r) => [r.id, r]));
expect(byId["title"].label).toBe("title");
expect(byId["title"].description).toBe("Snake cased name");
const variableKey = buildValueVariableKey(
"low,medium,high",
"Priority",
true,
);
expect(byId[variableKey].label).toBe("Priority");
expect(byId[variableKey].type).toBe("dropdown");
});
it("collects VDATE with format and default", async () => {
const app = makeApp();
const plugin = makePlugin();
const rc = new RequirementCollector(app, plugin);
await rc.scanString("{{VDATE:due, YYYY-MM-DD|tomorrow}}" );
const [due] = Array.from(rc.requirements.values()).filter(r => r.id === "due");
expect(due.type).toBe("date");
expect(due.dateFormat).toBe("YYYY-MM-DD");
expect(due.defaultValue).toBe("tomorrow");
});
it("records TEMPLATE references for recursive scanning", async () => {
const app = makeApp();
const plugin = makePlugin();
const rc = new RequirementCollector(app, plugin);
await rc.scanString("{{TEMPLATE:Templates/Note}}" );
expect(rc.templatesToScan.size === 0 || rc.templatesToScan.has("Templates/Note")).toBe(true);
});
it("uses textarea for VALUE tokens with type:multiline", async () => {
const app = makeApp();
const plugin = makePlugin({ inputPrompt: "single-line" });
const rc = new RequirementCollector(app, plugin);
await rc.scanString("{{VALUE:Body|type:multiline}}" );
const requirement = rc.requirements.get("Body");
expect(requirement?.type).toBe("textarea");
});
it("uses textarea for unnamed VALUE with type:multiline", async () => {
const app = makeApp();
const plugin = makePlugin({ inputPrompt: "single-line" });
const rc = new RequirementCollector(app, plugin);
await rc.scanString("{{VALUE|type:multiline|label:Notes}}" );
const requirement = rc.requirements.get("value");
expect(requirement?.type).toBe("textarea");
expect(requirement?.description).toBe("Notes");
});
it("respects global multiline setting for named VALUE tokens", async () => {
const app = makeApp();
const plugin = makePlugin({ inputPrompt: "multi-line" });
const rc = new RequirementCollector(app, plugin);
await rc.scanString("{{VALUE:title}}" );
const requirement = rc.requirements.get("title");
expect(requirement?.type).toBe("textarea");
});
});