1import { describe, expect, it } from "vite-plus/test";
2import { ApprovalRequestId, type UserInputAttachmentAnswerPayload } from "@t3tools/contracts";
3import { getQuestionTextPreview } from "./userInput.ts";
4
5function answer(
6 overrides: Partial<UserInputAttachmentAnswerPayload> = {},
7): UserInputAttachmentAnswerPayload {
8 return {
9 requestId: ApprovalRequestId.make("request-1"),
10 questionTextById: { scope: "Which repository?" },
11 answers: { scope: "Use the private repository" },
12 attachmentsByQuestionId: {},
13 ...overrides,
14 };
15}
16
17describe("getQuestionTextPreview", () => {
18 it("joins the question texts", () => {
19 expect(
20 getQuestionTextPreview(
21 answer({ questionTextById: { scope: "Which repository?", name: "What name?" } }),
22 ),
23 ).toBe("Which repository? · What name?");
24 });
25
26 it("normalizes whitespace and skips blank texts", () => {
27 expect(
28 getQuestionTextPreview(
29 answer({ questionTextById: { scope: "Which\nrepository?", x: " " } }),
30 ),
31 ).toBe("Which repository?");
32 });
33
34 it("returns an empty string without question texts", () => {
35 expect(getQuestionTextPreview(answer({ questionTextById: undefined }))).toBe("");
36 });
37});