Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

userInput.test.ts

70 lines2.4 KB

1import { describe, expect, it } from "vite-plus/test";
2​
3import { getQuestionAnswerPreview, getQuestionAnswerText } from "./userInput.js";
4​
5// Shape the web client submits for an answer holding a review-comment chip.
6const answerWithReviewComment = [
7 "See my note: [Review comment: notes.md L2; ref=review-comment_c1]",
8 "",
9 '<t3_context version="1">',
10 '<context kind="review-comment" id="review-comment_c1">',
11 "file: notes.md",
12 "range: L2 (2-2)",
13 "comment:",
14 " Rename this",
15 "diff:",
16 " +line changed",
17 "</context>",
18 "</t3_context>",
19].join("\n");
20​
21describe("question answer display", () => {
22 it("keeps the provider context envelope out of answer history and preview", () => {
23 const history = getQuestionAnswerText(answerWithReviewComment);
24 const preview = getQuestionAnswerPreview({
25 requestId: "request-1",
26 answers: { q1: answerWithReviewComment },
27 attachmentsByQuestionId: {},
28 questionTextById: { q1: "What should change?" },
29 });
30​
31 expect(history).toBe("See my note: [Review comment: notes.md L2]");
32 expect(preview).toContain("See my note:");
33 expect(preview).not.toContain("<t3_context");
34​
35 const typedXml =
36 'Use this XML literally: <t3_context version="1"><context kind="review-comment" id="example">keep me</context></t3_context>';
37 expect(getQuestionAnswerText(typedXml)).toBe(typedXml);
38 });
39});
40​
41// agy's ask_question submits 1-based option values that differ from the labels shown.
42const numberedQuestion = {
43 id: "q1",
44 header: "Question 1",
45 question: "What should happen next?",
46 options: [
47 { label: "Add focused tests", description: "Add focused tests", value: "1" },
48 { label: "Refactor the module", description: "Refactor the module", value: "2" },
49 ],
50};
51​
52describe("answers to questions whose option values differ from their labels", () => {
53 it("shows the picked option labels, not the submitted values", () => {
54 expect(getQuestionAnswerText("1", numberedQuestion)).toBe("Add focused tests");
55 expect(getQuestionAnswerText(["1", "2"], numberedQuestion)).toBe(
56 "Add focused tests, Refactor the module",
57 );
58 expect(
59 getQuestionAnswerPreview(
60 {
61 requestId: "request-1",
62 answers: { q1: "1" },
63 attachmentsByQuestionId: {},
64 questionTextById: { q1: "What should happen next?" },
65 },
66 [numberedQuestion],
67 ),
68 ).toBe("Add focused tests");
69 });
70});