Skip to content

Commit e396a61

Browse files
la14-1louisgvclaude
authored
test: add unit tests for parsePickerInput in picker.ts (#2421)
Agent: test-engineer Co-authored-by: B <6723574+louisgv@users.noreply.github.com> Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 9a35227 commit e396a61

1 file changed

Lines changed: 105 additions & 0 deletions

File tree

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
import { describe, expect, it } from "bun:test";
2+
import { parsePickerInput } from "../picker";
3+
4+
describe("parsePickerInput", () => {
5+
it("parses three-field tab-separated lines (value, label, hint)", () => {
6+
const result = parsePickerInput("us-east-1\tVirginia\tRecommended");
7+
expect(result).toEqual([
8+
{
9+
value: "us-east-1",
10+
label: "Virginia",
11+
hint: "Recommended",
12+
},
13+
]);
14+
});
15+
16+
it("parses two-field lines (value, label) with no hint", () => {
17+
const result = parsePickerInput("us-east-1\tVirginia");
18+
expect(result).toEqual([
19+
{
20+
value: "us-east-1",
21+
label: "Virginia",
22+
},
23+
]);
24+
});
25+
26+
it("uses value as label when only value is provided", () => {
27+
const result = parsePickerInput("us-east-1");
28+
expect(result).toEqual([
29+
{
30+
value: "us-east-1",
31+
label: "us-east-1",
32+
},
33+
]);
34+
});
35+
36+
it("filters empty and whitespace-only lines", () => {
37+
const result = parsePickerInput("a\tAlpha\n\n \nb\tBeta\n");
38+
expect(result).toEqual([
39+
{
40+
value: "a",
41+
label: "Alpha",
42+
},
43+
{
44+
value: "b",
45+
label: "Beta",
46+
},
47+
]);
48+
});
49+
50+
it("handles mixed field counts in a single input", () => {
51+
const input = [
52+
"val1\tLabel1\tHint1",
53+
"val2\tLabel2",
54+
"val3",
55+
].join("\n");
56+
const result = parsePickerInput(input);
57+
expect(result).toEqual([
58+
{
59+
value: "val1",
60+
label: "Label1",
61+
hint: "Hint1",
62+
},
63+
{
64+
value: "val2",
65+
label: "Label2",
66+
},
67+
{
68+
value: "val3",
69+
label: "val3",
70+
},
71+
]);
72+
});
73+
74+
it("returns empty array for empty input", () => {
75+
expect(parsePickerInput("")).toEqual([]);
76+
expect(parsePickerInput(" ")).toEqual([]);
77+
expect(parsePickerInput("\n\n")).toEqual([]);
78+
});
79+
80+
it("trims whitespace from fields", () => {
81+
const result = parsePickerInput(" val \t Label \t Hint ");
82+
expect(result).toEqual([
83+
{
84+
value: "val",
85+
label: "Label",
86+
hint: "Hint",
87+
},
88+
]);
89+
});
90+
91+
it("parses multiple lines correctly", () => {
92+
const input = "us-central1-a\tIowa\nus-east1-b\tVirginia";
93+
const result = parsePickerInput(input);
94+
expect(result).toEqual([
95+
{
96+
value: "us-central1-a",
97+
label: "Iowa",
98+
},
99+
{
100+
value: "us-east1-b",
101+
label: "Virginia",
102+
},
103+
]);
104+
});
105+
});

0 commit comments

Comments
 (0)