mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-24 09:08:07 +02:00
[Editor] Init the default highlight color before creating the first editor instance
We want to be able to draw an highlight with the default color but without having an instance of the HighlightEditor.
This commit is contained in:
parent
130a0fef3d
commit
17e1519410
10 changed files with 89 additions and 15 deletions
|
@ -132,4 +132,61 @@ describe("Highlight Editor", () => {
|
|||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe("The default color must have the correct value", () => {
|
||||
let pages;
|
||||
|
||||
beforeAll(async () => {
|
||||
pages = await loadAndWait(
|
||||
"tracemonkey.pdf",
|
||||
".annotationEditorLayer",
|
||||
null,
|
||||
null,
|
||||
{ highlightEditorColors: "red=#AB0000" }
|
||||
);
|
||||
});
|
||||
|
||||
afterAll(async () => {
|
||||
await closePages(pages);
|
||||
});
|
||||
|
||||
it("must highlight with red color", async () => {
|
||||
await Promise.all(
|
||||
pages.map(async ([browserName, page]) => {
|
||||
await page.click("#editorHighlight");
|
||||
await page.waitForSelector(".annotationEditorLayer.highlightEditing");
|
||||
|
||||
const rect = await page.evaluate(() => {
|
||||
for (const el of document.querySelectorAll(
|
||||
`.page[data-page-number="1"] > .textLayer > span`
|
||||
)) {
|
||||
if (el.textContent === "Abstract") {
|
||||
const { x, y, width, height } = el.getBoundingClientRect();
|
||||
return { x, y, width, height };
|
||||
}
|
||||
}
|
||||
return null;
|
||||
});
|
||||
|
||||
const x = rect.x + rect.width / 2;
|
||||
const y = rect.y + rect.height / 2;
|
||||
await page.mouse.click(x, y, { count: 2 });
|
||||
|
||||
await page.waitForSelector(`${getEditorSelector(0)}`);
|
||||
await page.waitForSelector(
|
||||
`.page[data-page-number = "1"] svg.highlightOutline.selected`
|
||||
);
|
||||
|
||||
const usedColor = await page.evaluate(() => {
|
||||
const highlight = document.querySelector(
|
||||
`.page[data-page-number = "1"] .canvasWrapper > svg.highlight`
|
||||
);
|
||||
return highlight.getAttribute("fill");
|
||||
});
|
||||
|
||||
expect(usedColor).withContext(`In ${browserName}`).toEqual("#AB0000");
|
||||
})
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
import os from "os";
|
||||
const isMac = os.platform() === "darwin";
|
||||
|
||||
function loadAndWait(filename, selector, zoom, pageSetup) {
|
||||
function loadAndWait(filename, selector, zoom, pageSetup, options) {
|
||||
return Promise.all(
|
||||
global.integrationSessions.map(async session => {
|
||||
const page = await session.browser.newPage();
|
||||
|
@ -36,9 +36,16 @@ function loadAndWait(filename, selector, zoom, pageSetup) {
|
|||
});
|
||||
});
|
||||
|
||||
let app_options = "";
|
||||
if (options) {
|
||||
// Options must be handled in app.js::_parseHashParams.
|
||||
for (const [key, value] of Object.entries(options)) {
|
||||
app_options += `&${key}=${encodeURIComponent(value)}`;
|
||||
}
|
||||
}
|
||||
const url = `${
|
||||
global.integrationBaseUrl
|
||||
}?file=/test/pdfs/${filename}#zoom=${zoom ?? "page-fit"}`;
|
||||
}?file=/test/pdfs/${filename}#zoom=${zoom ?? "page-fit"}${app_options}`;
|
||||
|
||||
await page.goto(url);
|
||||
if (pageSetup) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue