@@ -33,13 +33,19 @@ async function epubFixture(): Promise<Buffer> {
|
||||
await writer.add(
|
||||
"EPUB/package.opf",
|
||||
new TextReader(
|
||||
`<?xml version="1.0"?><package xmlns="http://www.idpf.org/2007/opf" version="3.0" unique-identifier="id"><metadata xmlns:dc="http://purl.org/dc/elements/1.1/"><dc:identifier id="id">urn:browser:test</dc:identifier><dc:title>Browser Fixture</dc:title><dc:language>en</dc:language><dc:creator>Local Author</dc:creator></metadata><manifest><item id="nav" href="nav.xhtml" media-type="application/xhtml+xml" properties="nav"/><item id="chapter" href="chapter.xhtml" media-type="application/xhtml+xml"/><item id="cover" href="cover.png" media-type="image/png" properties="cover-image"/></manifest><spine><itemref idref="chapter"/></spine></package>`,
|
||||
`<?xml version="1.0"?><package xmlns="http://www.idpf.org/2007/opf" version="3.0" unique-identifier="id"><metadata xmlns:dc="http://purl.org/dc/elements/1.1/"><dc:identifier id="id">urn:browser:test</dc:identifier><dc:title>Browser Fixture</dc:title><dc:language>en</dc:language><dc:creator>Local Author</dc:creator></metadata><manifest><item id="nav" href="nav.xhtml" media-type="application/xhtml+xml" properties="nav"/><item id="title-page" href="title.xhtml" media-type="application/xhtml+xml"/><item id="chapter" href="chapter.xhtml" media-type="application/xhtml+xml"/><item id="cover" href="cover.png" media-type="image/png" properties="cover-image"/></manifest><spine><itemref idref="title-page"/><itemref idref="chapter"/></spine></package>`,
|
||||
),
|
||||
);
|
||||
await writer.add(
|
||||
"EPUB/nav.xhtml",
|
||||
new TextReader(
|
||||
`<?xml version="1.0"?><html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops"><body><nav epub:type="toc"><ol><li><a href="chapter.xhtml">A safe chapter</a></li></ol></nav></body></html>`,
|
||||
`<?xml version="1.0"?><html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops"><body><nav epub:type="toc"><ol><li><a href="title.xhtml">Cover</a></li><li><a href="chapter.xhtml">A safe chapter</a></li></ol></nav></body></html>`,
|
||||
),
|
||||
);
|
||||
await writer.add(
|
||||
"EPUB/title.xhtml",
|
||||
new TextReader(
|
||||
`<?xml version="1.0"?><html xmlns="http://www.w3.org/1999/xhtml"><head><title>Cover</title></head><body><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" width="100%" height="100%" viewBox="0 0 1283 1920" preserveAspectRatio="none"><image width="1283" height="1920" xlink:href="cover.png"></image></svg></body></html>`,
|
||||
),
|
||||
);
|
||||
await writer.add(
|
||||
@@ -85,17 +91,45 @@ test("serves the release identity and hardened headers", async ({
|
||||
const manifest = await request.get("/deep/nested/epub/toolbox-app.json");
|
||||
await expect(manifest.json()).resolves.toMatchObject({
|
||||
id: "de.add-ideas.epub-tools",
|
||||
version: "0.1.0",
|
||||
version: "0.2.0",
|
||||
entry: "./",
|
||||
});
|
||||
});
|
||||
|
||||
test("adapts Markdown locally and reports the resulting EPUB workspace", async ({
|
||||
page,
|
||||
}) => {
|
||||
const external = await localOnly(page);
|
||||
await page.goto("/deep/nested/epub/");
|
||||
await page.getByLabel("Choose publication").setInputFiles({
|
||||
name: "local-notes.md",
|
||||
mimeType: "text/markdown",
|
||||
buffer: Buffer.from("# Local notes\n\nA **private** chapter."),
|
||||
});
|
||||
await expect(
|
||||
page.getByText("Local notes", { exact: true }).first(),
|
||||
).toBeVisible({
|
||||
timeout: 30_000,
|
||||
});
|
||||
await expect(page.getByText("MARKDOWN → EPUB workspace")).toBeVisible();
|
||||
await expect(
|
||||
page
|
||||
.frameLocator("iframe[title^='Safe EPUB preview']")
|
||||
.getByRole("heading", { name: "Local notes" }),
|
||||
).toBeVisible();
|
||||
await page.getByRole("button", { name: "Validation" }).click();
|
||||
await expect(page.getByText(/was converted locally into/iu)).toBeVisible();
|
||||
expect(external).toEqual([]);
|
||||
});
|
||||
|
||||
test("opens, sanitizes, edits, rebuilds, and reopens a real EPUB", async ({
|
||||
page,
|
||||
}) => {
|
||||
const external = await localOnly(page);
|
||||
await page.goto("/deep/nested/epub/");
|
||||
await page.getByLabel("Choose EPUB").setInputFiles({
|
||||
await page.getByRole("button", { name: "Personalize" }).click();
|
||||
await page.getByRole("button", { name: "Dark" }).click();
|
||||
await page.getByLabel("Choose publication").setInputFiles({
|
||||
name: "fixture.epub",
|
||||
mimeType: "application/epub+zip",
|
||||
buffer: await epubFixture(),
|
||||
@@ -104,13 +138,33 @@ test("opens, sanitizes, edits, rebuilds, and reopens a real EPUB", async ({
|
||||
page.getByText("Browser Fixture", { exact: true }).first(),
|
||||
).toBeVisible({ timeout: 30_000 });
|
||||
const reader = page.frameLocator("iframe[title^='Safe EPUB preview']");
|
||||
const titleImage = reader.locator("svg image");
|
||||
await expect(titleImage).toBeVisible();
|
||||
expect(
|
||||
await titleImage.evaluate((element) =>
|
||||
element.getAttributeNS("http://www.w3.org/1999/xlink", "href"),
|
||||
),
|
||||
).toMatch(/^blob:/u);
|
||||
await expect(reader.locator("html")).toHaveAttribute(
|
||||
"data-epub-reader-theme",
|
||||
"dark",
|
||||
);
|
||||
await expect
|
||||
.poll(() =>
|
||||
reader.locator("body").evaluate((element) => {
|
||||
const style = getComputedStyle(element);
|
||||
return [style.backgroundColor, style.color];
|
||||
}),
|
||||
)
|
||||
.toEqual(["rgb(23, 29, 45)", "rgb(237, 241, 251)"]);
|
||||
await page.getByRole("button", { name: /A safe chapter/u }).click();
|
||||
await expect(
|
||||
reader.getByRole("heading", { name: "Hello from EPUB" }),
|
||||
).toBeVisible();
|
||||
await expect(reader.locator("script")).toHaveCount(0);
|
||||
await page.getByRole("tab", { name: "Metadata" }).click();
|
||||
await page.getByRole("button", { name: "Metadata" }).click();
|
||||
await page.getByLabel("Title").fill("Updated in browser");
|
||||
await page.getByRole("tab", { name: "Export & rebuild" }).click();
|
||||
await page.getByRole("button", { name: "Export & rebuild" }).click();
|
||||
const downloadPromise = page.waitForEvent("download");
|
||||
await page.getByRole("button", { name: "Create updated EPUB" }).click();
|
||||
const download = await downloadPromise;
|
||||
|
||||
Reference in New Issue
Block a user