Files
office-tools/tests/components/upload-workbench.test.tsx
zemion 08b8f84f7b
Verify / verify (push) Canceled after 0s
Release Office Tools 0.2.0
2026-09-02 07:32:31 +02:00

56 lines
2.0 KiB
TypeScript

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: () => <section aria-label="Test OOXML viewer" />,
}));
describe("UploadWorkbench", () => {
it("exposes the initial local format families", () => {
render(<UploadWorkbench />);
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(<UploadWorkbench />);
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(<UploadWorkbench />);
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",
);
});
});