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

composerContextPresentation.test.ts

81 lines2.3 KB

1import { ThreadId } from "@t3tools/contracts";
2import { describe, expect, it } from "vite-plus/test";
3​
4import { buildMessageContext } from "~/lib/composerContextRecords";
5import {
6 composerContextRecordsFromDraft,
7 uploadedContextRecordFromDraft,
8} from "./composerContextPresentation";
9​
10describe("composerContextRecordsFromDraft", () => {
11 it("recovers the uploaded record when clipboard data points at an attachment already in the draft", () => {
12 const file = {
13 type: "file" as const,
14 id: "file-1",
15 name: "file.txt",
16 mimeType: "text/plain",
17 sizeBytes: 4,
18 file: new File(["test"], "file.txt"),
19 uploadedAttachmentId: "attachment-1",
20 };
21 const draftRecord = composerContextRecordsFromDraft({
22 terminalContexts: [],
23 files: [file],
24 }).get("file_file-1");
25​
26 expect(draftRecord && uploadedContextRecordFromDraft(draftRecord)).toMatchObject({
27 kind: "file",
28 contextId: "file_file-1",
29 attachmentId: "attachment-1",
30 });
31 });
32​
33 it("resolves each wire reference to its own backing draft even when producer ids collide", () => {
34 const id = "same.id:1";
35 const terminal = {
36 id,
37 threadId: ThreadId.make("t1"),
38 terminalId: "default",
39 terminalLabel: "Terminal",
40 lineStart: 1,
41 lineEnd: 1,
42 text: "output",
43 createdAt: "2026-01-01T00:00:00.000Z",
44 };
45 const image = {
46 type: "image" as const,
47 id,
48 name: "shot.png",
49 mimeType: "image/png",
50 sizeBytes: 1,
51 file: new File(["x"], "shot.png"),
52 previewUrl: "blob:shot",
53 };
54 const file = {
55 type: "file" as const,
56 id,
57 name: "file.txt",
58 mimeType: "text/plain",
59 sizeBytes: 1,
60 file: null,
61 };
62 const draftRecords = composerContextRecordsFromDraft({
63 terminalContexts: [terminal],
64 images: [image],
65 files: [file],
66 });
67 const message = buildMessageContext({
68 terminalContexts: [terminal],
69 reviewComments: [],
70 previewAnnotations: [],
71 attachments: [
72 { attachment: image, attachmentId: "uploaded-image" },
73 { attachment: file, attachmentId: "uploaded-file" },
74 ],
75 })!;
76 expect(draftRecords.size).toBe(3);
77 for (const record of message.records) {
78 expect(draftRecords.get(record.contextId)?.kind).toBe(record.kind);
79 }
80 });
81});