Open History to see the last commit
1import { EnvironmentId, PROVIDER_SEND_TURN_MAX_FILE_BYTES } from "@t3tools/contracts";
2import { describe, expect, it } from "vite-plus/test";
3
4import type { ComposerFileAttachment, ComposerImageAttachment } from "../../composerDraftStore";
5import {
6 attachmentsToReleaseOnUploadCapabilityLoss,
7 fileAttachmentCapabilityBlockReason,
8 fileAttachmentStagingLimit,
9 shouldHandleComposerAttachmentPaste,
10} from "./composerAttachmentFiles";
11
12describe("composer attachment files", () => {
13 it("preserves text paste when an application adds a synthetic generic file", () => {
14 const file = new File(["clipboard"], "clipboard.rtf", { type: "application/rtf" });
15
16 expect(
17 shouldHandleComposerAttachmentPaste({
18 files: [file],
19 plainText: "Copied text",
20 }),
21 ).toBe(false);
22 });
23
24 it("uses the hard local limit while server config is unknown", () => {
25 expect(
26 fileAttachmentStagingLimit({
27 attachmentUploadsCapabilityKnown: false,
28 supportsAttachmentUploads: false,
29 maxFileAttachmentBytes: null,
30 }),
31 ).toBe(PROVIDER_SEND_TURN_MAX_FILE_BYTES);
32 expect(
33 fileAttachmentCapabilityBlockReason({
34 files: [{ name: "pending.zip", sizeBytes: PROVIDER_SEND_TURN_MAX_FILE_BYTES }],
35 attachmentUploadsCapabilityKnown: false,
36 supportsAttachmentUploads: false,
37 maxFileAttachmentBytes: null,
38 }),
39 ).toBe("Waiting for the server before file attachments can send");
40 });
41
42 it("keeps draft-persisted file uploads when the upload capability flips off", () => {
43 const environmentId = EnvironmentId.make("environment-1");
44 const image: ComposerImageAttachment = {
45 type: "image",
46 id: "image-1",
47 name: "photo.png",
48 mimeType: "image/png",
49 sizeBytes: 3,
50 previewUrl: "blob:photo",
51 file: new File([new Uint8Array([1, 2, 3])], "photo.png", { type: "image/png" }),
52 };
53 const uploadingFile: ComposerFileAttachment = {
54 type: "file",
55 id: "file-uploading",
56 name: "fresh.pdf",
57 mimeType: "application/pdf",
58 sizeBytes: 3,
59 file: new File([new Uint8Array([1, 2, 3])], "fresh.pdf", { type: "application/pdf" }),
60 };
61 const hydratedFile: ComposerFileAttachment = {
62 type: "file",
63 id: "file-hydrated",
64 name: "report.pdf",
65 mimeType: "application/pdf",
66 sizeBytes: 3,
67 file: null,
68 uploadedAttachmentId: "pending-report-pdf",
69 uploadEnvironmentId: environmentId,
70 };
71 const uploadedLocalFile: ComposerFileAttachment = {
72 ...uploadingFile,
73 id: "file-uploaded-local",
74 uploadedAttachmentId: "pending-fresh-pdf",
75 uploadEnvironmentId: environmentId,
76 };
77
78 const released = attachmentsToReleaseOnUploadCapabilityLoss([
79 image,
80 uploadingFile,
81 hydratedFile,
82 uploadedLocalFile,
83 ]);
84
85 expect(released.map((attachment) => attachment.id)).toEqual(["image-1", "file-uploading"]);
86 });
87});