fix: preserve multi-select choices with custom answers
This commit is contained in:
@@ -56,6 +56,39 @@ test("summaries include custom text answers", () => {
|
||||
);
|
||||
});
|
||||
|
||||
test("multi-select summaries include selected options and custom text", () => {
|
||||
let state = createInitialState({
|
||||
questions: [
|
||||
{
|
||||
id: "frameworks",
|
||||
label: "Frameworks",
|
||||
prompt: "Which frameworks?",
|
||||
type: "multi",
|
||||
options: [
|
||||
{ value: "react", label: "React" },
|
||||
{ value: "vue", label: "Vue" },
|
||||
],
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
state = applyNumberShortcut(state, 1);
|
||||
state = applyNumberShortcut(state, 3);
|
||||
state = submitCustomAnswer(state, "SolidStart");
|
||||
const result = toAskResult(state);
|
||||
|
||||
assert.deepEqual(result.answers.frameworks, {
|
||||
values: ["react", "SolidStart"],
|
||||
labels: ["React", "SolidStart"],
|
||||
indices: [1],
|
||||
customText: "SolidStart",
|
||||
note: undefined,
|
||||
optionNotes: undefined,
|
||||
});
|
||||
assert.equal(summarizeResult(result), "Frameworks: React, SolidStart");
|
||||
assert.equal(renderResultText(result), "✓ Frameworks: React, SolidStart");
|
||||
});
|
||||
|
||||
test("summaries and result text include question and selected option notes", () => {
|
||||
let state = createInitialState({
|
||||
questions: [
|
||||
|
||||
@@ -185,6 +185,68 @@ test("escape saves typed custom answer without advancing", () => {
|
||||
assert.equal(state.answers.q1.customText, "my draft answer");
|
||||
});
|
||||
|
||||
test("multi-select keeps existing selections when leaving custom input empty", () => {
|
||||
let state = createInitialState({
|
||||
questions: [
|
||||
{
|
||||
id: "q1",
|
||||
prompt: "Pick frameworks",
|
||||
type: "multi",
|
||||
options: [
|
||||
{ value: "react", label: "React" },
|
||||
{ value: "vue", label: "Vue" },
|
||||
{ value: "svelte", label: "Svelte" },
|
||||
],
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
state = moveOption(state, 1);
|
||||
state = toggleCurrentMultiOption(state);
|
||||
state = moveOption(state, 1);
|
||||
state = toggleCurrentMultiOption(state);
|
||||
state = applyNumberShortcut(state, 4);
|
||||
state = saveCustomAnswer(state, " ");
|
||||
|
||||
assert.deepEqual(
|
||||
state.answers.q1.selected.map((selection) => selection.value),
|
||||
["vue", "svelte"]
|
||||
);
|
||||
assert.equal(state.answers.q1.customText, undefined);
|
||||
});
|
||||
|
||||
test("multi-select keeps existing selections when saving custom text", () => {
|
||||
let state = createInitialState({
|
||||
questions: [
|
||||
{
|
||||
id: "q1",
|
||||
prompt: "Pick frameworks",
|
||||
type: "multi",
|
||||
options: [
|
||||
{ value: "react", label: "React" },
|
||||
{ value: "vue", label: "Vue" },
|
||||
],
|
||||
},
|
||||
{
|
||||
id: "q2",
|
||||
prompt: "Anything else?",
|
||||
options: [{ value: "a", label: "A" }],
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
state = toggleCurrentMultiOption(state);
|
||||
state = applyNumberShortcut(state, 3);
|
||||
state = submitCustomAnswer(state, "SolidStart");
|
||||
|
||||
assert.equal(state.activeTabIndex, 1);
|
||||
assert.deepEqual(
|
||||
state.answers.q1.selected.map((selection) => selection.value),
|
||||
["react"]
|
||||
);
|
||||
assert.equal(state.answers.q1.customText, "SolidStart");
|
||||
});
|
||||
|
||||
test("empty custom draft clears the stored answer but preserves notes", () => {
|
||||
let state = createInitialState({
|
||||
questions: [
|
||||
@@ -304,6 +366,32 @@ test("deselecting an option keeps its note in state but omits it from submission
|
||||
});
|
||||
});
|
||||
|
||||
test("multi-select keeps custom text when toggling additional options", () => {
|
||||
let state = createInitialState({
|
||||
questions: [
|
||||
{
|
||||
id: "q1",
|
||||
prompt: "Pick frameworks",
|
||||
type: "multi",
|
||||
options: [
|
||||
{ value: "react", label: "React" },
|
||||
{ value: "vue", label: "Vue" },
|
||||
],
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
state = applyNumberShortcut(state, 3);
|
||||
state = saveCustomAnswer(state, "SolidStart");
|
||||
state = applyNumberShortcut(state, 1);
|
||||
|
||||
assert.equal(state.answers.q1.customText, "SolidStart");
|
||||
assert.deepEqual(
|
||||
state.answers.q1.selected.map((selection) => selection.value),
|
||||
["react"]
|
||||
);
|
||||
});
|
||||
|
||||
test("preview questions can store selected option notes for submission", () => {
|
||||
let state = createInitialState({
|
||||
questions: [
|
||||
|
||||
Reference in New Issue
Block a user