mirror of
https://github.com/mozilla/pdf.js.git
synced 2026-04-15 09:44:03 +02:00
Add an integration test for the issue fixed in #20742
This commit is contained in:
parent
5cbb8413cb
commit
c1fe547a05
@ -22,6 +22,7 @@ import {
|
||||
loadAndWait,
|
||||
scrollIntoView,
|
||||
showViewsManager,
|
||||
waitAndClick,
|
||||
waitForPageChanging,
|
||||
waitForPageRendered,
|
||||
} from "./test_utils.mjs";
|
||||
@ -1528,6 +1529,77 @@ describe("PDF viewer", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("Find current outline item scrolls into view (PR 20742)", () => {
|
||||
let pages;
|
||||
|
||||
beforeEach(async () => {
|
||||
pages = await loadAndWait(
|
||||
"freeculture.pdf",
|
||||
".textLayer .endOfContent",
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
{ width: 1280, height: 600 }
|
||||
);
|
||||
});
|
||||
|
||||
afterEach(async () => {
|
||||
await closePages(pages);
|
||||
});
|
||||
|
||||
it("must scroll the selected outline item into the visible sidebar area", async () => {
|
||||
await Promise.all(
|
||||
pages.map(async ([browserName, page]) => {
|
||||
// Open the sidebar.
|
||||
await showViewsManager(page);
|
||||
|
||||
// Switch to outline view.
|
||||
await page.click("#viewsManagerSelectorButton");
|
||||
await waitAndClick(page, "#outlinesViewMenu");
|
||||
|
||||
// Wait for the outline tree to render.
|
||||
await page.waitForSelector("#outlinesView .treeItem", {
|
||||
visible: true,
|
||||
});
|
||||
|
||||
// Navigate to page 310, which maps to a nested outline item inside
|
||||
// a collapsed parent; _scrollToCurrentTreeItem will expand the parent
|
||||
// and scroll the item into view.
|
||||
await page.evaluate(() => {
|
||||
window.PDFViewerApplication.page = 310;
|
||||
});
|
||||
await page.waitForFunction(
|
||||
() => window.PDFViewerApplication.page === 310
|
||||
);
|
||||
await page.waitForSelector(
|
||||
".page[data-page-number='310'] .textLayer .endOfContent"
|
||||
);
|
||||
|
||||
await waitAndClick(
|
||||
page,
|
||||
"#viewsManagerCurrentOutlineButton:not(:disabled)"
|
||||
);
|
||||
|
||||
// Wait for an outline item to receive the "selected" class.
|
||||
const item = await page.waitForSelector(
|
||||
"#outlinesView .treeItemToggler:not(.treeItemsHidden) + a + .treeItems > .treeItem.selected",
|
||||
{
|
||||
visible: true,
|
||||
}
|
||||
);
|
||||
const isVisible = await item.isIntersectingViewport();
|
||||
expect(isVisible).withContext(`In ${browserName}`).toBeTrue();
|
||||
const outlineItemText = await item.evaluate(el =>
|
||||
el.textContent.trim()
|
||||
);
|
||||
expect(outlineItemText)
|
||||
.withContext(`In ${browserName}`)
|
||||
.toBe("Fire Lots of Lawyers");
|
||||
})
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe("Scroll into view", () => {
|
||||
let pages;
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user