import { render, screen } from "@testing-library/react"; import userEvent from "@testing-library/user-event"; import { describe, expect, it, vi } from "vitest"; import { UploadWorkbench } from "../../src/components/UploadWorkbench"; vi.mock("../../src/components/OoxmlViewer", () => ({ OoxmlViewer: () =>
, })); describe("UploadWorkbench", () => { it("exposes the initial local format families", () => { render(); expect( screen.getByRole("heading", { name: "Open an office file" }), ).toBeInTheDocument(); for (const format of ["DOCX", "XLSX", "PPTX", "ODT", "ODS", "ODP"]) expect(screen.getByText(format)).toBeInTheDocument(); expect(screen.getByText("No upload")).toBeInTheDocument(); }); it("shows the identity of a locally selected file", async () => { const user = userEvent.setup(); render(); const input = screen.getByLabelText("Open office file"); const bytes = new Uint8Array(13); bytes.set([0x50, 0x4b, 0x03, 0x04]); const file = new File([bytes], "report.docx", { type: "application/vnd.openxmlformats-officedocument.wordprocessingml.document", }); await user.upload(input, file); const heading = await screen.findByRole("region", { name: "report.docx" }); expect(heading).toHaveTextContent("report.docx"); expect(heading).toHaveTextContent("13 B"); expect(screen.getByLabelText("Test OOXML viewer")).toBeInTheDocument(); expect( screen.getByRole("button", { name: "Save exact copy" }), ).toBeVisible(); }); it("explains a renamed legacy compound-binary file", async () => { const user = userEvent.setup(); render(); const file = new File( [Uint8Array.from([0xd0, 0xcf, 0x11, 0xe0, 0xa1, 0xb1, 0x1a, 0xe1])], "renamed.docx", ); await user.upload(screen.getByLabelText("Open office file"), file); expect(await screen.findByRole("alert")).toHaveTextContent( "legacy OLE Compound File", ); }); });