Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

elicitationForm.test.ts

47 lines1.6 KB

1import { assert, describe, it } from "@effect/vitest";
2​
3import { parseElicitationForm } from "./elicitationForm.ts";
4​
5describe("parseElicitationForm", () => {
6 for (const type of ["string", "array"] as const) {
7 it.each([
8 { values: [" padded ", "", "plain"], labels: ["padded", '""', "plain"] },
9 { values: [" a", "a", "b"], labels: ['" a"', '"a"', "b"] },
10 { values: [" a", "a", '"a"'], labels: ['" a"', '"a"', '"\\"a\\""'] },
11 ])(
12 `preserves ${type} enum values with distinct readable labels: $values`,
13 ({ values, labels }) => {
14 const form = parseElicitationForm(
15 {
16 type: "object",
17 properties: {
18 answer:
19 type === "array"
20 ? { type, items: { type: "string", enum: values } }
21 : { type, enum: values },
22 },
23 required: ["answer"],
24 },
25 "Choose",
26 );
27 assert(form !== undefined);
28 const question = form.questions[0];
29 assert(question !== undefined);
30 assert.deepStrictEqual(
31 question.options.map((option) => option.label),
32 labels,
33 );
34 assert.deepStrictEqual(
35 question.options.map((option) => option.value),
36 values,
37 );
38 assert.strictEqual(question.allowCustomAnswer, false);
39 assert.strictEqual(question.multiSelect, type === "array" ? true : undefined);
40 for (const value of values) {
41 const answer = type === "array" ? [value] : value;
42 assert.deepStrictEqual(form.content({ answer }), { answer });
43 }
44 },
45 );
46 }
47});