Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions packages/client-runtime/src/state/pendingUserInput.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,19 @@ const nativeChoiceQuestion = {
} as const;

describe("resolvePendingUserInputAnswer", () => {
it("accepts no selections for multi-select questions while single-select stays unanswered", () => {
const question = { ...singleSelectQuestion, multiSelect: true };
expect(buildPendingUserInputAnswers([question], {})).toEqual({ scope: [] });
expect(resolvePendingUserInputAnswer(question, { selectedOptionValues: [] })).toEqual([]);
expect(resolvePendingUserInputAnswer(question, { customAnswer: " " })).toEqual([]);
expect(resolvePendingUserInputAnswer(question, { customAnswer: "Something else" })).toBe(
"Something else",
);
expect(resolvePendingUserInputAnswer(question, { attachmentCount: 1 })).toBe("");
expect(resolvePendingUserInputAnswer(question, { attachmentsBlocked: true })).toBeNull();
expect(resolvePendingUserInputAnswer(singleSelectQuestion, undefined)).toBeNull();
});

it("preserves exact editor text, including a deliberately cleared answer", () => {
const question = { ...singleSelectQuestion, initialAnswer: " Proposed message\n" };
expect(resolvePendingUserInputAnswer(question, { customAnswer: question.initialAnswer })).toBe(
Expand Down Expand Up @@ -124,6 +137,11 @@ describe("togglePendingUserInputOptionSelection", () => {
expect(buildPendingUserInputAnswers([question], { result: secondSelected })).toEqual({
result: ["second"],
});

const noneSelected = togglePendingUserInputOptionSelection(question, secondSelected, "second");
expect(buildPendingUserInputAnswers([question], { result: noneSelected })).toEqual({
result: [],
});
});

it("submits raw option values and leaves the draft alone for an unknown option", () => {
Expand Down
4 changes: 3 additions & 1 deletion packages/client-runtime/src/state/pendingUserInput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@ export function resolvePendingUserInputAnswer(
return selectedOptionValues.length > 0
? selectedOptionValues
: (customAnswer ??
(question.allowCustomAnswer !== false && (draft?.attachmentCount ?? 0) > 0 ? "" : null));
(question.allowCustomAnswer !== false && (draft?.attachmentCount ?? 0) > 0
? ""
: selectedOptionValues));
}
return (
selectedOptionValues[0] ??
Expand Down
Loading