@@ -1,4 +1,4 @@
|
||||
import { expect, test, type Page } from "@playwright/test";
|
||||
import { expect, test, type Download, type Page } from "@playwright/test";
|
||||
import {
|
||||
createMinimalOdp,
|
||||
createMinimalOds,
|
||||
@@ -25,9 +25,31 @@ async function find(page: Page, value: string) {
|
||||
await expect(search.getByText("1 of 1", { exact: true })).toBeVisible();
|
||||
}
|
||||
|
||||
async function downloadedBytes(download: Download): Promise<Uint8Array> {
|
||||
const stream = await download.createReadStream();
|
||||
const chunks: Uint8Array[] = [];
|
||||
let total = 0;
|
||||
for await (const chunk of stream) {
|
||||
const bytes =
|
||||
typeof chunk === "string"
|
||||
? new TextEncoder().encode(chunk)
|
||||
: new Uint8Array(chunk as ArrayBufferLike);
|
||||
chunks.push(bytes);
|
||||
total += bytes.byteLength;
|
||||
}
|
||||
const result = new Uint8Array(total);
|
||||
let offset = 0;
|
||||
for (const chunk of chunks) {
|
||||
result.set(chunk, offset);
|
||||
offset += chunk.byteLength;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
test("renders and searches a project-authored ODT in an isolated worker", async ({
|
||||
page,
|
||||
}) => {
|
||||
const fixture = createMinimalOdt();
|
||||
const externalHosts = new Set<string>();
|
||||
const errors: string[] = [];
|
||||
const workerScripts: URL[] = [];
|
||||
@@ -45,7 +67,7 @@ test("renders and searches a project-authored ODT in an isolated worker", async
|
||||
});
|
||||
page.on("pageerror", (error) => errors.push(error.message));
|
||||
|
||||
await openFixture(page, createMinimalOdt());
|
||||
await openFixture(page, fixture);
|
||||
await expect(
|
||||
page.getByRole("heading", { name: "OpenDocument Text Fixture" }),
|
||||
).toBeVisible();
|
||||
@@ -59,6 +81,11 @@ test("renders and searches a project-authored ODT in an isolated worker", async
|
||||
await page.getByRole("button", { name: "Zoom in" }).click();
|
||||
await expect(page.getByText("110%", { exact: true })).toBeVisible();
|
||||
|
||||
const exactCopy = page.waitForEvent("download");
|
||||
await page.getByRole("button", { name: "Save exact copy" }).click();
|
||||
const exactBytes = await downloadedBytes(await exactCopy);
|
||||
expect([...exactBytes]).toEqual([...fixture.buffer]);
|
||||
|
||||
expect(externalHosts).toEqual(new Set());
|
||||
expect(errors).toEqual([]);
|
||||
expect(workerScripts.length).toBeGreaterThan(0);
|
||||
@@ -81,6 +108,12 @@ test("renders, searches and switches sheets in a project-authored ODS", async ({
|
||||
await page.getByRole("button", { name: "Next sheet" }).click();
|
||||
await expect(page.getByText("sheet 2 of 2", { exact: true })).toBeVisible();
|
||||
await expect(page.getByRole("grid")).toContainText("Second sheet content");
|
||||
const csvDownload = page.waitForEvent("download");
|
||||
await page.getByRole("button", { name: "Export sheet CSV" }).click();
|
||||
const csv = new TextDecoder().decode(
|
||||
await downloadedBytes(await csvDownload),
|
||||
);
|
||||
expect(csv).toContain("Second sheet content");
|
||||
});
|
||||
|
||||
test("renders, searches and navigates a project-authored ODP", async ({
|
||||
|
||||
Reference in New Issue
Block a user