+36
![github-actions[bot]](/assets/img/avatar_default.png)








Julius Marminge
maria-rcks
Bilal Bakr
shivam
Vitalii Yehorov
Jake Leventhal
Claude Opus 5
Alex Southwell
github-actions[bot]
Nicholas Wasmiller
PB
Exotic
Yash Singh
Devin
Theo Browne
Gabriel De Andrade
Dara Adedeji
scratchyone
Dominic Roy
chukfinley
Primož Ajdišek
benthecarman
NaveDanan
aaditagrawal
Aditya Garud
Nick Anisimov
MacKinley Smith
Yordis Prieto
t3-code[bot]
AKolenda
Guillermo Casanova
Otavio Salvador
Shirish Pothi
Ishaan Kothari
Bob Fowler
Anton Bezdenezhnykh
ValeraZSD
Ephraim
Ryan Ilano
Alex
maco
Cursor
Tristan Knight
PR Batch Tester
oliver
kamkm
de34391427
Co-authored-by: maria-rcks <[email protected]> Co-authored-by: Bilal Bakr <[email protected]> Co-authored-by: shivam <[email protected]> Co-authored-by: Vitalii Yehorov <[email protected]> Co-authored-by: Jake Leventhal <[email protected]> Co-authored-by: Claude Opus 5 (1M context) <[email protected]> Co-authored-by: Alex Southwell <[email protected]> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Nicholas Wasmiller <[email protected]> Co-authored-by: PB <[email protected]> Co-authored-by: Exotic <[email protected]> Co-authored-by: Yash Singh <[email protected]> Co-authored-by: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com> Co-authored-by: Theo Browne <[email protected]> Co-authored-by: Gabriel De Andrade <[email protected]> Co-authored-by: Dara Adedeji <[email protected]> Co-authored-by: scratchyone <[email protected]> Co-authored-by: Dominic Roy <[email protected]> Co-authored-by: chukfinley <[email protected]> Co-authored-by: Primož Ajdišek <[email protected]> Co-authored-by: benthecarman <[email protected]> Co-authored-by: NaveDanan <[email protected]> Co-authored-by: aaditagrawal <[email protected]> Co-authored-by: Aditya Garud <[email protected]> Co-authored-by: Nick Anisimov <[email protected]> Co-authored-by: MacKinley Smith <[email protected]> Co-authored-by: Yordis Prieto <[email protected]> Co-authored-by: t3-code[bot] <269035359+t3-code[bot]@users.noreply.github.com> Co-authored-by: AKolenda <[email protected]> Co-authored-by: Guillermo Casanova <[email protected]> Co-authored-by: Otavio Salvador <[email protected]> Co-authored-by: Shirish Pothi <[email protected]> Co-authored-by: Ishaan Kothari <[email protected]> Co-authored-by: Bob Fowler <[email protected]> Co-authored-by: Anton Bezdenezhnykh <[email protected]> Co-authored-by: ValeraZSD <[email protected]> Co-authored-by: Ephraim <[email protected]> Co-authored-by: Ryan Ilano <[email protected]> Co-authored-by: Alex <[email protected]> Co-authored-by: maco <[email protected]> Co-authored-by: Cursor <[email protected]> Co-authored-by: Tristan Knight <[email protected]> Co-authored-by: PR Batch Tester <[email protected]> Co-authored-by: oliver <[email protected]> Co-authored-by: kamkm <[email protected]> Signed-off-by: Yordis Prieto <[email protected]>
368 lines
10 KiB
TypeScript
368 lines
10 KiB
TypeScript
import { describe, expect, it } from "vite-plus/test";
|
|
|
|
import {
|
|
buildPendingUserInputAnswers,
|
|
carryDisplacedCustomAnswerIntoPrompt,
|
|
countAnsweredPendingUserInputQuestions,
|
|
derivePendingUserInputProgress,
|
|
findFirstUnansweredPendingUserInputQuestionIndex,
|
|
resolvePendingUserInputAnswer,
|
|
setPendingUserInputCustomAnswer,
|
|
togglePendingUserInputOptionSelection,
|
|
} from "./pendingUserInput";
|
|
|
|
const singleSelectQuestion = {
|
|
id: "scope",
|
|
header: "Scope",
|
|
question: "What should the plan target first?",
|
|
options: [
|
|
{
|
|
label: "Orchestration-first",
|
|
description: "Focus on orchestration first",
|
|
},
|
|
],
|
|
multiSelect: false,
|
|
} as const;
|
|
|
|
const multiSelectQuestion = {
|
|
id: "areas",
|
|
header: "Areas",
|
|
question: "Which areas should this change cover?",
|
|
options: [
|
|
{
|
|
label: "Server",
|
|
description: "Server",
|
|
},
|
|
{
|
|
label: "Web",
|
|
description: "Web",
|
|
},
|
|
],
|
|
multiSelect: true,
|
|
} as const;
|
|
|
|
const nativeChoiceQuestion = {
|
|
id: "result",
|
|
header: "Result",
|
|
question: "Which result should be used?",
|
|
options: [
|
|
{ value: " first\t", label: "Result", description: "First result" },
|
|
{ value: "second", label: "Result", description: "Second result" },
|
|
],
|
|
allowCustomAnswer: false,
|
|
multiSelect: false,
|
|
} as const;
|
|
|
|
describe("resolvePendingUserInputAnswer", () => {
|
|
it("prefers a custom answer over selected options", () => {
|
|
expect(
|
|
resolvePendingUserInputAnswer(singleSelectQuestion, {
|
|
selectedOptionValues: ["Orchestration-first"],
|
|
customAnswer: "Keep the existing envelope for one release",
|
|
}),
|
|
).toBe("Keep the existing envelope for one release");
|
|
});
|
|
|
|
it("falls back to the selected option for single-select questions", () => {
|
|
expect(
|
|
resolvePendingUserInputAnswer(singleSelectQuestion, {
|
|
selectedOptionValues: ["Orchestration-first"],
|
|
}),
|
|
).toBe("Orchestration-first");
|
|
});
|
|
|
|
it("returns all selected labels for multi-select questions", () => {
|
|
expect(
|
|
resolvePendingUserInputAnswer(multiSelectQuestion, {
|
|
selectedOptionValues: ["Server", "Web"],
|
|
}),
|
|
).toEqual(["Server", "Web"]);
|
|
});
|
|
|
|
it("clears the preset selection when a custom answer is entered", () => {
|
|
expect(
|
|
setPendingUserInputCustomAnswer(
|
|
{
|
|
selectedOptionValues: ["Server", "Web"],
|
|
},
|
|
"doesn't matter",
|
|
),
|
|
).toEqual({
|
|
customAnswer: "doesn't matter",
|
|
});
|
|
});
|
|
|
|
it("does not replace a required choice with a custom answer", () => {
|
|
expect(
|
|
resolvePendingUserInputAnswer(nativeChoiceQuestion, {
|
|
selectedOptionValues: ["second"],
|
|
customAnswer: "Use another result",
|
|
}),
|
|
).toBe("second");
|
|
});
|
|
|
|
it("does not submit labels or unknown values when an option has a value", () => {
|
|
expect(
|
|
resolvePendingUserInputAnswer(nativeChoiceQuestion, {
|
|
selectedOptionValues: ["Result", "unknown"],
|
|
}),
|
|
).toBeNull();
|
|
});
|
|
});
|
|
|
|
describe("togglePendingUserInputOptionSelection", () => {
|
|
it("toggles options for multi-select questions", () => {
|
|
expect(togglePendingUserInputOptionSelection(multiSelectQuestion, undefined, "Server")).toEqual(
|
|
{
|
|
customAnswer: "",
|
|
selectedOptionValues: ["Server"],
|
|
},
|
|
);
|
|
|
|
expect(
|
|
togglePendingUserInputOptionSelection(
|
|
multiSelectQuestion,
|
|
{
|
|
selectedOptionValues: ["Server", "Web"],
|
|
},
|
|
"Server",
|
|
),
|
|
).toEqual({
|
|
customAnswer: "",
|
|
selectedOptionValues: ["Web"],
|
|
});
|
|
});
|
|
|
|
it("selects and removes options with the same label independently", () => {
|
|
const question = { ...nativeChoiceQuestion, multiSelect: true };
|
|
const firstSelected = togglePendingUserInputOptionSelection(question, undefined, " first\t");
|
|
const bothSelected = togglePendingUserInputOptionSelection(question, firstSelected, "second");
|
|
|
|
expect(buildPendingUserInputAnswers([question], { result: bothSelected })).toEqual({
|
|
result: [" first\t", "second"],
|
|
});
|
|
|
|
const secondSelected = togglePendingUserInputOptionSelection(
|
|
question,
|
|
bothSelected,
|
|
" first\t",
|
|
);
|
|
expect(buildPendingUserInputAnswers([question], { result: secondSelected })).toEqual({
|
|
result: ["second"],
|
|
});
|
|
});
|
|
});
|
|
|
|
describe("buildPendingUserInputAnswers", () => {
|
|
it("returns a canonical answer map for complete prompts", () => {
|
|
expect(
|
|
buildPendingUserInputAnswers(
|
|
[
|
|
singleSelectQuestion,
|
|
{
|
|
id: "compat",
|
|
header: "Compat",
|
|
question: "How strict should compatibility be?",
|
|
options: [
|
|
{
|
|
label: "Keep current envelope",
|
|
description: "Preserve current wire format",
|
|
},
|
|
],
|
|
multiSelect: false,
|
|
},
|
|
],
|
|
{
|
|
scope: {
|
|
selectedOptionValues: ["Orchestration-first"],
|
|
},
|
|
compat: {
|
|
customAnswer: "Keep the current envelope for one release window",
|
|
},
|
|
},
|
|
),
|
|
).toEqual({
|
|
scope: "Orchestration-first",
|
|
compat: "Keep the current envelope for one release window",
|
|
});
|
|
});
|
|
|
|
it("returns arrays for answered multi-select prompts", () => {
|
|
expect(
|
|
buildPendingUserInputAnswers([multiSelectQuestion], {
|
|
areas: {
|
|
selectedOptionValues: ["Server", "Web"],
|
|
},
|
|
}),
|
|
).toEqual({
|
|
areas: ["Server", "Web"],
|
|
});
|
|
});
|
|
|
|
it("returns null when any question is unanswered", () => {
|
|
expect(buildPendingUserInputAnswers([singleSelectQuestion], {})).toBeNull();
|
|
});
|
|
|
|
it.each([" first\t", ""])("preserves the exact selected option value %j", (value) => {
|
|
const question = {
|
|
...nativeChoiceQuestion,
|
|
options: [{ ...nativeChoiceQuestion.options[0], value }, nativeChoiceQuestion.options[1]],
|
|
};
|
|
const draft = togglePendingUserInputOptionSelection(question, undefined, value);
|
|
|
|
expect(buildPendingUserInputAnswers([question], { result: draft })).toEqual({ result: value });
|
|
expect(derivePendingUserInputProgress([question], { result: draft }, 0)).toMatchObject({
|
|
selectedOptionValues: [value],
|
|
answeredQuestionCount: 1,
|
|
canAdvance: true,
|
|
isComplete: true,
|
|
});
|
|
});
|
|
});
|
|
|
|
describe("pending user input question progress", () => {
|
|
const questions = [
|
|
singleSelectQuestion,
|
|
{
|
|
id: "compat",
|
|
header: "Compat",
|
|
question: "How strict should compatibility be?",
|
|
options: [
|
|
{
|
|
label: "Keep current envelope",
|
|
description: "Preserve current wire format",
|
|
},
|
|
],
|
|
multiSelect: false,
|
|
},
|
|
] as const;
|
|
|
|
it("counts only answered questions", () => {
|
|
expect(
|
|
countAnsweredPendingUserInputQuestions(questions, {
|
|
scope: {
|
|
selectedOptionValues: ["Orchestration-first"],
|
|
},
|
|
}),
|
|
).toBe(1);
|
|
});
|
|
|
|
it("finds the first unanswered question", () => {
|
|
expect(
|
|
findFirstUnansweredPendingUserInputQuestionIndex(questions, {
|
|
scope: {
|
|
selectedOptionValues: ["Orchestration-first"],
|
|
},
|
|
}),
|
|
).toBe(1);
|
|
});
|
|
|
|
it("returns the last question index when all answers are complete", () => {
|
|
expect(
|
|
findFirstUnansweredPendingUserInputQuestionIndex(questions, {
|
|
scope: {
|
|
selectedOptionValues: ["Orchestration-first"],
|
|
},
|
|
compat: {
|
|
customAnswer: "Keep it for one release window",
|
|
},
|
|
}),
|
|
).toBe(1);
|
|
});
|
|
|
|
it("derives the active question and advancement state", () => {
|
|
expect(
|
|
derivePendingUserInputProgress(
|
|
questions,
|
|
{
|
|
scope: {
|
|
selectedOptionValues: ["Orchestration-first"],
|
|
},
|
|
},
|
|
0,
|
|
),
|
|
).toMatchObject({
|
|
questionIndex: 0,
|
|
activeQuestion: questions[0],
|
|
selectedOptionValues: ["Orchestration-first"],
|
|
customAnswer: "",
|
|
resolvedAnswer: "Orchestration-first",
|
|
answeredQuestionCount: 1,
|
|
isLastQuestion: false,
|
|
isComplete: false,
|
|
canAdvance: true,
|
|
});
|
|
});
|
|
|
|
it("treats multi-select questions as answered when they have selected options", () => {
|
|
expect(
|
|
derivePendingUserInputProgress(
|
|
[multiSelectQuestion],
|
|
{
|
|
areas: {
|
|
selectedOptionValues: ["Server", "Web"],
|
|
},
|
|
},
|
|
0,
|
|
),
|
|
).toMatchObject({
|
|
selectedOptionValues: ["Server", "Web"],
|
|
resolvedAnswer: ["Server", "Web"],
|
|
canAdvance: true,
|
|
isComplete: true,
|
|
});
|
|
});
|
|
|
|
it("requires an option when custom answers are disabled", () => {
|
|
const drafts = { result: { customAnswer: "Use another result" } };
|
|
|
|
expect(buildPendingUserInputAnswers([nativeChoiceQuestion], drafts)).toBeNull();
|
|
expect(derivePendingUserInputProgress([nativeChoiceQuestion], drafts, 0)).toMatchObject({
|
|
customAnswer: "",
|
|
usingCustomAnswer: false,
|
|
resolvedAnswer: null,
|
|
answeredQuestionCount: 0,
|
|
canAdvance: false,
|
|
isComplete: false,
|
|
});
|
|
});
|
|
});
|
|
|
|
it("accepts attachment-only answers after every upload finishes", () => {
|
|
const questions = [
|
|
{ id: "spec", header: "Spec", question: "Provide a spec", options: [], multiSelect: false },
|
|
];
|
|
expect(buildPendingUserInputAnswers(questions, { spec: { attachmentCount: 1 } })).toEqual({
|
|
spec: "",
|
|
});
|
|
expect(
|
|
buildPendingUserInputAnswers(questions, {
|
|
spec: { attachmentCount: 1, attachmentsBlocked: true },
|
|
}),
|
|
).toBeNull();
|
|
expect(
|
|
buildPendingUserInputAnswers([{ ...questions[0]!, allowCustomAnswer: false }], {
|
|
spec: { attachmentCount: 1 },
|
|
}),
|
|
).toBeNull();
|
|
});
|
|
|
|
describe("carryDisplacedCustomAnswerIntoPrompt", () => {
|
|
it("keeps the thread draft when nothing was typed into the answer", () => {
|
|
expect(carryDisplacedCustomAnswerIntoPrompt("draft", undefined)).toBe("draft");
|
|
expect(carryDisplacedCustomAnswerIntoPrompt("draft", " ")).toBe("draft");
|
|
});
|
|
|
|
it("moves the typed answer into an empty thread draft", () => {
|
|
expect(carryDisplacedCustomAnswerIntoPrompt("", "also rename the flag ")).toBe(
|
|
"also rename the flag",
|
|
);
|
|
});
|
|
|
|
it("appends the typed answer after an existing thread draft", () => {
|
|
expect(carryDisplacedCustomAnswerIntoPrompt("first half\n", "second half")).toBe(
|
|
"first half\n\nsecond half",
|
|
);
|
|
});
|
|
});
|