Skip to content

Commit f217ab1

Browse files
committed
refactor: share VALUE label key helper
1 parent b805216 commit f217ab1

File tree

2 files changed

+19
-9
lines changed

2 files changed

+19
-9
lines changed

src/preflight/RequirementCollector.test.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { describe, it, expect } from "vitest";
22
import { RequirementCollector } from "./RequirementCollector";
3-
import { parseValueToken } from "src/utils/valueSyntax";
3+
import { buildValueVariableKey } from "src/utils/valueSyntax";
44

55
// Light stubs for app/plugin
66
const makeApp = () => ({
@@ -37,10 +37,13 @@ describe("RequirementCollector", () => {
3737

3838
expect(byId["title"].label).toBe("title");
3939
expect(byId["title"].description).toBe("Snake cased name");
40-
const parsed = parseValueToken(multiToken);
41-
expect(parsed).not.toBeNull();
42-
expect(byId[parsed!.variableKey].label).toBe("Priority");
43-
expect(byId[parsed!.variableKey].type).toBe("dropdown");
40+
const variableKey = buildValueVariableKey(
41+
"low,medium,high",
42+
"Priority",
43+
true,
44+
);
45+
expect(byId[variableKey].label).toBe("Priority");
46+
expect(byId[variableKey].type).toBe("dropdown");
4447
});
4548

4649
it("collects VDATE with format and default", async () => {

src/utils/valueSyntax.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,16 @@ export type ParsedValueToken = {
1414
hasOptions: boolean;
1515
};
1616

17+
export function buildValueVariableKey(
18+
variableName: string,
19+
label: string | undefined,
20+
hasOptions: boolean,
21+
): string {
22+
return hasOptions && label
23+
? `${variableName}${VALUE_LABEL_KEY_DELIMITER}${label}`
24+
: variableName;
25+
}
26+
1727
type ParsedOptions = {
1828
label?: string;
1929
defaultValue: string;
@@ -125,10 +135,7 @@ export function parseValueToken(raw: string): ParsedValueToken | null {
125135
defaultValue = allowCustomInput ? "" : legacyDefault;
126136
}
127137

128-
const variableKey =
129-
hasOptions && label
130-
? `${variablePart}${VALUE_LABEL_KEY_DELIMITER}${label}`
131-
: variablePart;
138+
const variableKey = buildValueVariableKey(variablePart, label, hasOptions);
132139

133140
return {
134141
raw,

0 commit comments

Comments
 (0)