fix(ui): tighten ask layout rendering

This commit is contained in:
Erik Kotsiuba
2026-04-25 20:26:07 +02:00
parent 8206be370e
commit 351509838c
8 changed files with 301 additions and 133 deletions
+1 -1
View File
@@ -10,7 +10,7 @@ export const UI_DIMENSIONS = {
previewLeftMaxWidth: 34, previewLeftMaxWidth: 34,
previewLeftRatio: 0.34, previewLeftRatio: 0.34,
submitWideMinWidth: 64, submitWideMinWidth: 64,
submitActionsWidth: 24, submitMinReviewWidth: 24,
} as const; } as const;
export const UI_TEXT = { export const UI_TEXT = {
+60 -64
View File
@@ -45,6 +45,10 @@ export function renderFrameFooter(args: {
add(theme.fg("accent", "─".repeat(Math.max(1, width)))); add(theme.fg("accent", "─".repeat(Math.max(1, width))));
} }
const TAB_PREFIX = " ← ";
const TAB_SUFFIX = " →";
const TAB_SEPARATOR_WIDTH = visibleWidth(" ");
function renderTabs(state: AskState, theme: Theme, width: number): string { function renderTabs(state: AskState, theme: Theme, width: number): string {
const tabs = state.questions.map((question, index) => { const tabs = state.questions.map((question, index) => {
const active = state.activeTabIndex === index; const active = state.activeTabIndex === index;
@@ -70,18 +74,25 @@ function renderTabs(state: AskState, theme: Theme, width: number): string {
}); });
const activeIndex = Math.min(state.activeTabIndex, tabs.length - 1); const activeIndex = Math.min(state.activeTabIndex, tabs.length - 1);
const availableTabWidth = Math.max(
1,
width - visibleWidth(TAB_PREFIX) - visibleWidth(TAB_SUFFIX)
);
const { start, end } = getVisibleTabRange( const { start, end } = getVisibleTabRange(
tabs.map((tab) => tab.width), tabs.map((tab) => tab.width),
activeIndex, activeIndex,
Math.max(1, width - 2) availableTabWidth
); );
const leftArrow = theme.fg("dim", "← "); const leftArrow = theme.fg("dim", TAB_PREFIX.trimStart());
const rightArrow = theme.fg("dim", " →"); const rightArrow = theme.fg("dim", TAB_SUFFIX);
const visibleTabs = tabs const visibleTabs = tabs
.slice(start, end + 1) .slice(start, end + 1)
.map((tab) => tab.render) .map((tab) => tab.render)
.join(" "); .join(" ");
return truncateToWidth(` ${leftArrow}${visibleTabs}${rightArrow}`, width); return truncateToWidth(
`${TAB_PREFIX[0]}${leftArrow}${visibleTabs}${rightArrow}`,
width
);
} }
function getVisibleTabRange( function getVisibleTabRange(
@@ -95,92 +106,76 @@ function getVisibleTabRange(
const totalWidth = const totalWidth =
widths.reduce((sum, width) => sum + width, 0) + widths.reduce((sum, width) => sum + width, 0) +
Math.max(0, widths.length - 1); Math.max(0, widths.length - 1) * TAB_SEPARATOR_WIDTH;
if (totalWidth <= availableWidth) { if (totalWidth <= availableWidth) {
return { start: 0, end: widths.length - 1 }; return { start: 0, end: widths.length - 1 };
} }
const zone = activeIndex / Math.max(1, widths.length - 1);
const mode = getViewportMode(zone);
return expandTabs(widths, activeIndex, availableWidth, mode);
}
function getViewportMode(zone: number): "left" | "right" | "balanced" {
if (zone <= 0.33) {
return "right";
}
if (zone >= 0.67) {
return "left";
}
return "balanced";
}
function expandTabs(
widths: number[],
activeIndex: number,
availableWidth: number,
mode: "left" | "right" | "balanced"
): { start: number; end: number } {
const range = { start: activeIndex, end: activeIndex }; const range = { start: activeIndex, end: activeIndex };
let usedWidth = widths[activeIndex] ?? 0; let usedWidth = widths[activeIndex] ?? 0;
let preferRight = mode !== "left"; let preferRight = activeIndex <= widths.length - activeIndex - 1;
while (true) { while (true) {
const directions = getGrowthDirections(mode, preferRight); const expansion = getExpandableTab(
const grew = directions.some((direction) => { widths,
const nextWidth = getNextTabWidth(widths, range, direction); range,
if ( availableWidth,
nextWidth === undefined || usedWidth,
usedWidth + 1 + nextWidth > availableWidth preferRight
) { );
return false; if (!expansion) {
}
usedWidth += 1 + nextWidth;
growRange(range, direction);
return true;
});
if (!grew) {
return range; return range;
} }
if (mode === "balanced") { usedWidth += TAB_SEPARATOR_WIDTH + expansion.width;
preferRight = !preferRight; applyTabGrowth(range, expansion.nextIndex, expansion.direction);
} preferRight = !preferRight;
} }
} }
function getGrowthDirections( function getExpandableTab(
mode: "left" | "right" | "balanced", widths: number[],
range: { start: number; end: number },
availableWidth: number,
usedWidth: number,
preferRight: boolean preferRight: boolean
): Array<"left" | "right"> { ):
if (mode === "left") { | { direction: "left" | "right"; nextIndex: number; width: number }
return ["left", "right"]; | undefined {
} for (const direction of getGrowthDirections(preferRight)) {
if (mode === "right") { const nextIndex = getNextTabIndex(range, direction);
return ["right", "left"]; const nextWidth = widths[nextIndex];
if (
nextWidth === undefined ||
usedWidth + TAB_SEPARATOR_WIDTH + nextWidth > availableWidth
) {
continue;
}
return { direction, nextIndex, width: nextWidth };
} }
return;
}
function getGrowthDirections(preferRight: boolean): Array<"left" | "right"> {
return preferRight ? ["right", "left"] : ["left", "right"]; return preferRight ? ["right", "left"] : ["left", "right"];
} }
function getNextTabWidth( function getNextTabIndex(
widths: number[],
range: { start: number; end: number }, range: { start: number; end: number },
direction: "left" | "right" direction: "left" | "right"
): number | undefined { ): number {
if (direction === "left") { return direction === "left" ? range.start - 1 : range.end + 1;
return widths[range.start - 1];
}
return widths[range.end + 1];
} }
function growRange( function applyTabGrowth(
range: { start: number; end: number }, range: { start: number; end: number },
nextIndex: number,
direction: "left" | "right" direction: "left" | "right"
) { ) {
if (direction === "left") { if (direction === "left") {
range.start -= 1; range.start = nextIndex;
return; return;
} }
range.end += 1; range.end = nextIndex;
} }
function renderFooter(state: AskState, width: number): string[] { function renderFooter(state: AskState, width: number): string[] {
@@ -195,10 +190,10 @@ function renderFooter(state: AskState, width: number): string[] {
const question = getCurrentQuestion(state); const question = getCurrentQuestion(state);
footer = renderFooterText(question?.type === "multi" ? "multi" : "default"); footer = renderFooterText(question?.type === "multi" ? "multi" : "default");
} }
return wrapFooterHints(footer, width); return wrapDelimitedFooterHints(footer, width);
} }
function wrapFooterHints(footer: string, width: number): string[] { function wrapDelimitedFooterHints(footer: string, width: number): string[] {
return footer.split(" · ").reduce<string[]>((lines, chunk) => { return footer.split(" · ").reduce<string[]>((lines, chunk) => {
const current = lines.at(-1) ?? ""; const current = lines.at(-1) ?? "";
const next = current ? `${current} · ${chunk}` : chunk; const next = current ? `${current} · ${chunk}` : chunk;
@@ -217,6 +212,7 @@ function wrapFooterHints(footer: string, width: number): string[] {
lines.push(...wrappedChunk); lines.push(...wrappedChunk);
return lines; return lines;
} }
lines.push(current);
lines.push(...wrappedChunk); lines.push(...wrappedChunk);
return lines; return lines;
}, []); }, []);
+13
View File
@@ -330,6 +330,19 @@ export function measurePreviewLeftWidth(
); );
} }
export function getSavedNotePrefixes(
theme: Theme,
args: { indent: string; label?: string }
) {
const title = args.label
? `${args.label} ${UI_TEXT.questionNoteTitle}`
: UI_TEXT.questionNoteTitle;
return {
prefix: `${args.indent}${theme.fg("syntaxString", title)} `,
continuationPrefix: `${args.indent}${" ".repeat(visibleWidth(title) + 1)}`,
};
}
export function renderFooterText( export function renderFooterText(
mode: "input" | "note" | "submit" | "multi" | "default" mode: "input" | "note" | "submit" | "multi" | "default"
) { ) {
+12 -12
View File
@@ -11,6 +11,7 @@ import {
import type { AskDisplayOption } from "../types.ts"; import type { AskDisplayOption } from "../types.ts";
import { UI_DIMENSIONS, UI_TEXT } from "./constants.ts"; import { UI_DIMENSIONS, UI_TEXT } from "./constants.ts";
import { import {
getSavedNotePrefixes,
measurePreviewLeftWidth, measurePreviewLeftWidth,
mergeColumns, mergeColumns,
pushWrappedText, pushWrappedText,
@@ -57,14 +58,17 @@ function renderQuestionNote(context: QuestionRenderContext): boolean {
if (!existingNote) { if (!existingNote) {
return false; return false;
} }
const { prefix, continuationPrefix } = getSavedNotePrefixes(theme, {
indent: " ",
});
pushWrappedText( pushWrappedText(
lines, lines,
existingNote, existingNote,
width, width,
theme, theme,
"muted", "muted",
getSavedNotePrefix(theme, " "), prefix,
getSavedNoteContinuationPrefix(" ") continuationPrefix
); );
lines.push(""); lines.push("");
return true; return true;
@@ -154,6 +158,7 @@ function renderPreviewQuestion(context: QuestionRenderContext) {
answer, answer,
option: selectedOption, option: selectedOption,
selected: true, selected: true,
// Custom preview options already render their inline editor/content above.
withGap: !selectedOption?.isCustomOption, withGap: !selectedOption?.isCustomOption,
}); });
} }
@@ -370,14 +375,17 @@ function renderSavedOptionNote(
return; return;
} }
const { lines, theme, width } = context; const { lines, theme, width } = context;
const { prefix, continuationPrefix } = getSavedNotePrefixes(theme, {
indent: " ",
});
pushWrappedText( pushWrappedText(
lines, lines,
optionNote, optionNote,
width, width,
theme, theme,
"muted", "muted",
getSavedNotePrefix(theme, " "), prefix,
getSavedNoteContinuationPrefix(" ") continuationPrefix
); );
} }
@@ -429,14 +437,6 @@ function renderIndentedEditor(
}); });
} }
function getSavedNotePrefix(theme: Theme, indent: string): string {
return `${indent}${theme.fg("syntaxString", UI_TEXT.questionNoteTitle)} `;
}
function getSavedNoteContinuationPrefix(indent: string): string {
return `${indent}${" ".repeat(visibleWidth(UI_TEXT.questionNoteTitle) + 1)}`;
}
function getOptionPrefix( function getOptionPrefix(
questionType: QuestionRenderContext["question"]["type"], questionType: QuestionRenderContext["question"]["type"],
option: AskDisplayOption, option: AskDisplayOption,
+37 -28
View File
@@ -3,7 +3,11 @@ import { SUBMIT_CHOICES } from "../constants.ts";
import { serializeAnswer } from "../state/answers.ts"; import { serializeAnswer } from "../state/answers.ts";
import type { AskResult, AskState, AskStateAnswer } from "../types.ts"; import type { AskResult, AskState, AskStateAnswer } from "../types.ts";
import { UI_DIMENSIONS, UI_TEXT } from "./constants.ts"; import { UI_DIMENSIONS, UI_TEXT } from "./constants.ts";
import { mergeColumns, pushWrappedText } from "./render-helpers.ts"; import {
getSavedNotePrefixes,
mergeColumns,
pushWrappedText,
} from "./render-helpers.ts";
import type { Theme } from "./render-types.ts"; import type { Theme } from "./render-types.ts";
type ReviewAnswer = AskResult["answers"][string] & { type ReviewAnswer = AskResult["answers"][string] & {
@@ -20,21 +24,21 @@ export function renderSubmitScreen(
width: number width: number
) { ) {
const showAllNotes = state.activeSubmitActionIndex === 1; const showAllNotes = state.activeSubmitActionIndex === 1;
const actionColumnWidth = getSubmitActionColumnWidth();
if (shouldUseWideSubmitLayout(width)) { if (shouldUseWideSubmitLayout(width, actionColumnWidth)) {
const leftWidth = UI_DIMENSIONS.submitActionsWidth; const rightWidth = Math.max(1, width - actionColumnWidth - 2);
const rightWidth = Math.max(1, width - leftWidth - 2);
const reviewLines = renderSubmitReviewLines( const reviewLines = renderSubmitReviewLines(
state, state,
theme, theme,
rightWidth, rightWidth,
showAllNotes showAllNotes
); );
const actionLines = renderSubmitActionLines(state, theme, leftWidth); const actionLines = renderSubmitActions(state, theme, actionColumnWidth);
for (const line of mergeColumns( for (const line of mergeColumns(
actionLines, actionLines,
reviewLines, reviewLines,
leftWidth, actionColumnWidth,
width width
)) { )) {
lines.push(line); lines.push(line);
@@ -48,7 +52,7 @@ export function renderSubmitScreen(
width, width,
showAllNotes showAllNotes
); );
const actionLines = renderSubmitActionLines(state, theme, width); const actionLines = renderSubmitActions(state, theme, width);
lines.push(...reviewLines); lines.push(...reviewLines);
lines.push(""); lines.push("");
lines.push(...actionLines); lines.push(...actionLines);
@@ -81,18 +85,22 @@ function renderSubmitReviewLines(
return lines; return lines;
} }
function renderSubmitActionLines( function getSubmitActionColumnWidth(): number {
state: AskState, return Math.max(
theme: Theme, ...SUBMIT_CHOICES.map((choice, index) =>
width: number visibleWidth(`❯ ${index + 1}. ${choice}`)
): string[] { )
const lines: string[] = []; );
renderSubmitActions(lines, state, theme, width);
return lines;
} }
function shouldUseWideSubmitLayout(width: number): boolean { function shouldUseWideSubmitLayout(
return width >= UI_DIMENSIONS.submitWideMinWidth; width: number,
actionColumnWidth: number
): boolean {
return (
width >= UI_DIMENSIONS.submitWideMinWidth &&
width - actionColumnWidth - 2 >= UI_DIMENSIONS.submitMinReviewWidth
);
} }
function renderSubmittedQuestion( function renderSubmittedQuestion(
@@ -188,16 +196,16 @@ function renderSubmittedNote(
theme: Theme, theme: Theme,
width: number width: number
) { ) {
const indent = " "; const { prefix, continuationPrefix } = getSavedNotePrefixes(theme, {
const notePrefix = `${indent}${theme.fg("syntaxString", UI_TEXT.questionNoteTitle)} `; indent: " ",
const continuationPrefix = `${indent}${" ".repeat(visibleWidth(UI_TEXT.questionNoteTitle) + 1)}`; });
pushWrappedText( pushWrappedText(
lines, lines,
note, note,
width, width,
theme, theme,
"muted", "muted",
notePrefix, prefix,
continuationPrefix continuationPrefix
); );
} }
@@ -209,17 +217,17 @@ function renderLabeledSubmittedNote(
theme: Theme, theme: Theme,
width: number width: number
) { ) {
const indent = " "; const { prefix, continuationPrefix } = getSavedNotePrefixes(theme, {
const title = `${label} ${UI_TEXT.questionNoteTitle}`; indent: " ",
const notePrefix = `${indent}${theme.fg("syntaxString", title)} `; label,
const continuationPrefix = `${indent}${" ".repeat(visibleWidth(title) + 1)}`; });
pushWrappedText( pushWrappedText(
lines, lines,
note, note,
width, width,
theme, theme,
"muted", "muted",
notePrefix, prefix,
continuationPrefix continuationPrefix
); );
} }
@@ -282,11 +290,11 @@ function toReviewAnswer(
} }
function renderSubmitActions( function renderSubmitActions(
lines: string[],
state: AskState, state: AskState,
theme: Theme, theme: Theme,
width: number width: number
) { ): string[] {
const lines: string[] = [];
for (let index = 0; index < SUBMIT_CHOICES.length; index++) { for (let index = 0; index < SUBMIT_CHOICES.length; index++) {
const selected = index === state.activeSubmitActionIndex; const selected = index === state.activeSubmitActionIndex;
const prefix = selected ? "❯ " : " "; const prefix = selected ? "❯ " : " ";
@@ -300,4 +308,5 @@ function renderSubmitActions(
prefix prefix
); );
} }
return lines;
} }
+102 -7
View File
@@ -28,6 +28,20 @@ function mockEditor() {
} as never; } as never;
} }
function plainTheme() {
return {
fg(_color: string, text: string) {
return text;
},
bg(_color: string, text: string) {
return text;
},
bold(text: string) {
return text;
},
} as never;
}
test("tab strip always shows dimmed framing arrows on wide screens", () => { test("tab strip always shows dimmed framing arrows on wide screens", () => {
const state = createInitialState({ const state = createInitialState({
title: "Demo", title: "Demo",
@@ -98,13 +112,15 @@ test("narrow tab strip keeps active middle tab visible", () => {
const lines = renderAskScreen({ const lines = renderAskScreen({
state, state,
theme: mockTheme(), theme: plainTheme(),
width: 28, width: 28,
editor: mockEditor(), editor: mockEditor(),
}); });
assert(lines.some((line) => line.includes("Three"))); const tabLine = lines.find((line) => line.includes("← "));
assert(!lines.some((line) => line.includes("{selectedBg}<text> One "))); assert.ok(tabLine);
assert(tabLine.includes("Three"));
assert(!tabLine.includes("One"));
}); });
test("narrow tab strip keeps submit tab visible when active", () => { test("narrow tab strip keeps submit tab visible when active", () => {
@@ -136,13 +152,69 @@ test("narrow tab strip keeps submit tab visible when active", () => {
const lines = renderAskScreen({ const lines = renderAskScreen({
state, state,
theme: mockTheme(), theme: plainTheme(),
width: 24, width: 24,
editor: mockEditor(), editor: mockEditor(),
}); });
assert(lines.some((line) => line.includes("Submit"))); const tabLine = lines.find((line) => line.includes("Submit"));
assert(lines.some((line) => line.includes("←") || line.includes("→"))); assert.ok(tabLine);
assert(tabLine.includes("Submit"));
assert(tabLine.includes("←") || tabLine.includes("→"));
});
test("tab strip avoids truncation at narrow boundary widths", () => {
const state = createInitialState({
title: "Demo",
questions: [
{
id: "q1",
label: "One",
prompt: "One",
options: [{ value: "a", label: "A" }],
},
{
id: "q2",
label: "Two",
prompt: "Two",
options: [{ value: "a", label: "A" }],
},
{
id: "q3",
label: "Three",
prompt: "Three",
options: [{ value: "a", label: "A" }],
},
{
id: "q4",
label: "Four",
prompt: "Four",
options: [{ value: "a", label: "A" }],
},
{
id: "q5",
label: "Five",
prompt: "Five",
options: [{ value: "a", label: "A" }],
},
],
});
state.activeTabIndex = 2;
for (const width of [28, 29, 30, 31, 32]) {
const lines = renderAskScreen({
state,
theme: plainTheme(),
width,
editor: mockEditor(),
});
const tabLine = lines.find((line) => line.includes("← "));
assert.ok(tabLine);
assert(tabLine.includes("Three"));
assert(!tabLine.includes("..."));
assert(!tabLine.includes("Fou..."));
assert(!tabLine.includes("Fi..."));
}
}); });
test("footer hints wrap on narrow screens instead of truncating", () => { test("footer hints wrap on narrow screens instead of truncating", () => {
@@ -160,7 +232,7 @@ test("footer hints wrap on narrow screens instead of truncating", () => {
const lines = renderAskScreen({ const lines = renderAskScreen({
state, state,
theme: mockTheme(), theme: plainTheme(),
width: 26, width: 26,
editor: mockEditor(), editor: mockEditor(),
}); });
@@ -169,3 +241,26 @@ test("footer hints wrap on narrow screens instead of truncating", () => {
assert(lines.some((line) => line.includes("Enter continue"))); assert(lines.some((line) => line.includes("Enter continue")));
assert(lines.some((line) => line.includes("N/Shift+N note"))); assert(lines.some((line) => line.includes("N/Shift+N note")));
}); });
test("footer keeps earlier hint chunks when later chunks wrap", () => {
const state = createInitialState({
questions: [
{
id: "q1",
label: "One",
prompt: "One",
options: [{ value: "a", label: "A" }],
},
],
});
const lines = renderAskScreen({
state,
theme: plainTheme(),
width: 22,
editor: mockEditor(),
});
assert(lines.some((line) => line.includes("⇆ tab · ↑↓ select")));
assert(lines.some((line) => line.includes("Enter confirm")));
});
+1 -1
View File
@@ -210,5 +210,5 @@ test("preview custom option reuses the normal inline editor", () => {
const optionIndex = lines.findIndex((line) => line.includes("Type your own")); const optionIndex = lines.findIndex((line) => line.includes("Type your own"));
const inputIndex = lines.findIndex((line) => line.includes("Type answer...")); const inputIndex = lines.findIndex((line) => line.includes("Type answer..."));
assert.equal(inputIndex, optionIndex + 1); assert.equal(inputIndex, optionIndex + 1);
assert(!lines.some((line) => line.includes("asdasddasdasdasdere"))); assert(!lines.some((line) => line.includes("Preview A")));
}); });
+75 -20
View File
@@ -7,15 +7,16 @@ import {
enterQuestionNoteMode, enterQuestionNoteMode,
saveNote, saveNote,
} from "../src/state/transitions.ts"; } from "../src/state/transitions.ts";
import { UI_DIMENSIONS } from "../src/ui/constants.ts";
import { renderSubmitScreen } from "../src/ui/render-submit.ts"; import { renderSubmitScreen } from "../src/ui/render-submit.ts";
function mockTheme() { function plainTheme() {
return { return {
fg(color: string, text: string) { fg(_color: string, text: string) {
return `<${color}>${text}</${color}>`; return text;
}, },
bg(color: string, text: string) { bg(_color: string, text: string) {
return `{${color}}${text}{/${color}}`; return text;
}, },
bold(text: string) { bold(text: string) {
return text; return text;
@@ -36,7 +37,12 @@ test("submit screen uses shorter action labels without extra prompt text", () =>
}); });
const lines: string[] = []; const lines: string[] = [];
renderSubmitScreen(lines, state, mockTheme(), 80); renderSubmitScreen(
lines,
state,
plainTheme(),
UI_DIMENSIONS.submitWideMinWidth + 16
);
assert(!lines.some((line) => line.includes("Submit answers?"))); assert(!lines.some((line) => line.includes("Submit answers?")));
assert(lines.some((line) => line.includes("1. Submit"))); assert(lines.some((line) => line.includes("1. Submit")));
@@ -58,7 +64,12 @@ test("submit screen uses side-by-side layout on wide screens", () => {
}); });
const lines: string[] = []; const lines: string[] = [];
renderSubmitScreen(lines, state, mockTheme(), 120); renderSubmitScreen(
lines,
state,
plainTheme(),
UI_DIMENSIONS.submitWideMinWidth + 16
);
assert( assert(
lines.some( lines.some(
@@ -83,7 +94,12 @@ test("submit screen stacks review above actions on narrow screens", () => {
}); });
const lines: string[] = []; const lines: string[] = [];
renderSubmitScreen(lines, state, mockTheme(), 50); renderSubmitScreen(
lines,
state,
plainTheme(),
UI_DIMENSIONS.submitWideMinWidth - 14
);
const reviewIndex = lines.findIndex((line) => const reviewIndex = lines.findIndex((line) =>
line.includes("Review answers") line.includes("Review answers")
@@ -127,11 +143,14 @@ test("submit screen shows notes only for answered questions in submit mode", ()
state = saveNote(state, "Second note"); state = saveNote(state, "Second note");
const lines: string[] = []; const lines: string[] = [];
renderSubmitScreen(lines, state, mockTheme(), 140); renderSubmitScreen(
lines,
const firstQuestionIndex = lines.findIndex((line) => state,
line.includes("<text>Single</text>") plainTheme(),
UI_DIMENSIONS.submitWideMinWidth + 76
); );
const firstQuestionIndex = lines.findIndex((line) => line.includes("Single"));
const firstQuestionNoteIndex = lines.findIndex((line) => const firstQuestionNoteIndex = lines.findIndex((line) =>
line.includes("Question note") line.includes("Question note")
); );
@@ -141,9 +160,7 @@ test("submit screen shows notes only for answered questions in submit mode", ()
const optionNoteIndex = lines.findIndex((line) => const optionNoteIndex = lines.findIndex((line) =>
line.includes("Option note") line.includes("Option note")
); );
const secondQuestionIndex = lines.findIndex((line) => const secondQuestionIndex = lines.findIndex((line) => line.includes("Multi"));
line.includes("<text>Multi</text>")
);
assert.notEqual(firstQuestionIndex, -1); assert.notEqual(firstQuestionIndex, -1);
assert.notEqual(firstQuestionNoteIndex, -1); assert.notEqual(firstQuestionNoteIndex, -1);
@@ -155,9 +172,7 @@ test("submit screen shows notes only for answered questions in submit mode", ()
assert(lines[firstQuestionNoteIndex]?.startsWith(" ")); assert(lines[firstQuestionNoteIndex]?.startsWith(" "));
assert(lines[optionNoteIndex]?.startsWith(" ")); assert(lines[optionNoteIndex]?.startsWith(" "));
assert.equal(lines[secondQuestionIndex - 1]?.trim(), ""); assert.equal(lines[secondQuestionIndex - 1]?.trim(), "");
assert( assert(lines.some((line) => line.includes("Note:")));
lines.some((line) => line.includes("<syntaxString>Note:</syntaxString>"))
);
assert(!lines.some((line) => line.includes("Second note"))); assert(!lines.some((line) => line.includes("Second note")));
assert(!lines.some((line) => line.includes("Question note:"))); assert(!lines.some((line) => line.includes("Question note:")));
assert(!lines.some((line) => line.includes("Code demo note:"))); assert(!lines.some((line) => line.includes("Code demo note:")));
@@ -200,7 +215,12 @@ test("submit screen shows all notes when elaborate action is selected", () => {
state = { ...state, activeSubmitActionIndex: 1 }; state = { ...state, activeSubmitActionIndex: 1 };
const lines: string[] = []; const lines: string[] = [];
renderSubmitScreen(lines, state, mockTheme(), 120); renderSubmitScreen(
lines,
state,
plainTheme(),
UI_DIMENSIONS.submitWideMinWidth + 16
);
assert(lines.some((line) => line.includes("Question note"))); assert(lines.some((line) => line.includes("Question note")));
assert(lines.some((line) => line.includes("Selected option note"))); assert(lines.some((line) => line.includes("Selected option note")));
@@ -233,7 +253,12 @@ test("submit screen renders multi-select option notes under their related answer
state = saveNote(state, "Second note"); state = saveNote(state, "Second note");
const lines: string[] = []; const lines: string[] = [];
renderSubmitScreen(lines, state, mockTheme(), 140); renderSubmitScreen(
lines,
state,
plainTheme(),
UI_DIMENSIONS.submitWideMinWidth + 76
);
const firstAnswerIndex = lines.findIndex((line) => const firstAnswerIndex = lines.findIndex((line) =>
line.includes("→ Follow-up action") line.includes("→ Follow-up action")
@@ -254,3 +279,33 @@ test("submit screen renders multi-select option notes under their related answer
assert(firstNoteIndex < secondAnswerIndex); assert(firstNoteIndex < secondAnswerIndex);
assert(secondAnswerIndex < secondNoteIndex); assert(secondAnswerIndex < secondNoteIndex);
}); });
test("submit action column fits all action labels at the wide breakpoint", () => {
const state = createInitialState({
questions: [
{
id: "q1",
label: "Color",
prompt: "Pick one color.",
options: [{ value: "blue", label: "Blue" }],
},
],
});
const lines: string[] = [];
renderSubmitScreen(
lines,
state,
plainTheme(),
UI_DIMENSIONS.submitWideMinWidth
);
assert(
lines.some(
(line) => line.includes("1. Submit") && line.includes("Review answers")
)
);
assert(lines.some((line) => line.includes("2. Elaborate")));
assert(lines.some((line) => line.includes("3. Cancel")));
assert(!lines.some((line) => line.includes("Elaborat\n")));
});