feat(ask): add question and option notes
This commit is contained in:
@@ -4,6 +4,9 @@ import { renderResultText } from "../src/result.ts";
|
||||
import {
|
||||
applyNumberShortcut,
|
||||
createInitialState,
|
||||
enterOptionNoteMode,
|
||||
enterQuestionNoteMode,
|
||||
saveNote,
|
||||
submitCustomAnswer,
|
||||
summarizeResult,
|
||||
toAskResult,
|
||||
@@ -54,6 +57,95 @@ test("summaries include custom text answers", () => {
|
||||
);
|
||||
});
|
||||
|
||||
test("summaries and result text include question and selected option notes", () => {
|
||||
let state = createInitialState({
|
||||
questions: [
|
||||
{
|
||||
id: "framework",
|
||||
label: "Framework",
|
||||
prompt: "Pick a framework",
|
||||
options: [
|
||||
{ value: "react", label: "React" },
|
||||
{ value: "vue", label: "Vue" },
|
||||
],
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
state = enterQuestionNoteMode(state, "framework");
|
||||
state = saveNote(state, "Need SSR support");
|
||||
state = enterOptionNoteMode(state, "framework", "vue");
|
||||
state = saveNote(state, "Team has prior experience");
|
||||
state = applyNumberShortcut(state, 2);
|
||||
const result = toAskResult(state);
|
||||
|
||||
assert.equal(
|
||||
summarizeResult(result),
|
||||
[
|
||||
"Framework: Vue",
|
||||
"Framework note: Need SSR support",
|
||||
"Framework / Vue note: Team has prior experience",
|
||||
].join("\n"),
|
||||
);
|
||||
assert.equal(
|
||||
renderResultText(result),
|
||||
[
|
||||
"✓ Framework: Vue",
|
||||
" note: Need SSR support",
|
||||
" Vue note: Team has prior experience",
|
||||
].join("\n"),
|
||||
);
|
||||
});
|
||||
|
||||
test("unselected option notes are omitted from the submitted result", () => {
|
||||
let state = createInitialState({
|
||||
questions: [
|
||||
{
|
||||
id: "framework",
|
||||
label: "Framework",
|
||||
prompt: "Pick a framework",
|
||||
options: [
|
||||
{ value: "react", label: "React" },
|
||||
{ value: "vue", label: "Vue" },
|
||||
],
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
state = enterOptionNoteMode(state, "framework", "react");
|
||||
state = saveNote(state, "Only for legacy projects");
|
||||
state = applyNumberShortcut(state, 2);
|
||||
const result = toAskResult(state);
|
||||
|
||||
assert.equal(result.answers.framework.optionNotes, undefined);
|
||||
assert.equal(renderResultText(result), "✓ Framework: Vue");
|
||||
});
|
||||
|
||||
test("question-note-only results still render note content", () => {
|
||||
const result = {
|
||||
title: "Interview",
|
||||
cancelled: false,
|
||||
questions: [
|
||||
{
|
||||
id: "scope",
|
||||
label: "Scope",
|
||||
prompt: "What should we focus on?",
|
||||
type: "single" as const,
|
||||
},
|
||||
],
|
||||
answers: {
|
||||
scope: {
|
||||
values: [],
|
||||
labels: [],
|
||||
indices: [],
|
||||
note: "Prefer incremental changes",
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
assert.equal(renderResultText(result), " note: Prefer incremental changes");
|
||||
});
|
||||
|
||||
test("cancelled result renders as cancelled", () => {
|
||||
const result = {
|
||||
title: "Interview",
|
||||
|
||||
Reference in New Issue
Block a user