diff --git a/ui/src/components/IssueAttachmentsSection.test.tsx b/ui/src/components/IssueAttachmentsSection.test.tsx new file mode 100644 index 00000000..7cec72e6 --- /dev/null +++ b/ui/src/components/IssueAttachmentsSection.test.tsx @@ -0,0 +1,190 @@ +// @vitest-environment jsdom + +import { QueryClient, QueryClientProvider } from "@tanstack/react-query"; +import type { IssueAttachment } from "@paperclipai/shared"; +import { act, type ComponentProps, type ReactNode } from "react"; +import { createRoot, type Root } from "react-dom/client"; +import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; +import { IssueAttachmentsSection } from "./IssueAttachmentsSection"; + +vi.mock("./MarkdownBody", () => ({ + MarkdownBody: ({ children, className }: { children: string; className?: string }) => ( +
+ Attachment · {attachment.contentType} · {formatBytes(attachment.byteSize)} +
+ ); +} + +function MarkdownAttachmentCard({ + attachment, + onDelete, + deletePending, +}: { + attachment: IssueAttachment; + onDelete: (attachmentId: string) => void; + deletePending?: boolean; +}) { + const filename = attachmentFilename(attachment); + const { data, isLoading, error } = useQuery({ + queryKey: queryKeys.issues.attachmentPreview(attachment.id), + queryFn: () => fetchAttachmentText(attachment), + }); + + return ( +Loading preview...
+ ) : error ? ( +Could not load markdown preview.
+ ) : ( +{filename}
++ Attachment · {attachment.contentType} · {formatBytes(attachment.byteSize)} +
+{error}
+ )} + + {imageAttachments.length > 0 && ( +Delete?
+Delete this attachment? This cannot be undone.
+{attachmentError}
- )} - - {imageAttachments.length > 0 && ( -Delete?
-- {attachment.contentType} · {formatBytes(attachment.byteSize)} -
-