feat(ui): support custom answers in preview questions

This commit is contained in:
Erik Kotsiuba
2026-04-25 20:01:43 +02:00
parent 1ce721094c
commit 7cca5eb54d
9 changed files with 135 additions and 19 deletions
+31 -2
View File
@@ -93,9 +93,13 @@ test("preview questions keep their type and option previews", () => {
assert.equal(state.questions[0].options[0].preview, "Example");
assert.equal(
getRenderableOptions(state.questions[0]).at(-1)?.isCustomOption,
undefined
true
);
assert.equal(getRenderableOptions(state.questions[0]).length, 1);
assert.equal(
getRenderableOptions(state.questions[0]).at(-1)?.label,
"Type your own"
);
assert.equal(getRenderableOptions(state.questions[0]).length, 2);
});
test("createInitialState rejects duplicate question ids", () => {
@@ -529,6 +533,31 @@ test("preview questions can store selected option notes for submission", () => {
});
});
test("preview questions support custom answers", () => {
let state = createInitialState({
questions: [
{
id: "preview",
prompt: "Pick layout",
type: "preview",
options: [{ value: "compact", label: "Compact", preview: "A" }],
},
],
});
state = applyNumberShortcut(state, 2);
state = submitCustomAnswer(state, "Something else");
assert.deepEqual(toAskResult(state).answers.preview, {
values: ["Something else"],
labels: ["Something else"],
indices: [],
customText: "Something else",
note: undefined,
optionNotes: undefined,
});
});
test("tab navigation wraps including submit tab", () => {
let state = createInitialState(sampleParams());
state = moveTab(state, -1);