@@ -22,6 +22,7 @@ import {
2222 loadAndWait ,
2323 scrollIntoView ,
2424 showViewsManager ,
25+ waitAndClick ,
2526 waitForPageChanging ,
2627 waitForPageRendered ,
2728} from "./test_utils.mjs" ;
@@ -1528,6 +1529,77 @@ describe("PDF viewer", () => {
15281529 } ) ;
15291530 } ) ;
15301531
1532+ describe ( "Find current outline item scrolls into view (PR 20742)" , ( ) => {
1533+ let pages ;
1534+
1535+ beforeEach ( async ( ) => {
1536+ pages = await loadAndWait (
1537+ "freeculture.pdf" ,
1538+ ".textLayer .endOfContent" ,
1539+ null ,
1540+ null ,
1541+ null ,
1542+ { width : 1280 , height : 600 }
1543+ ) ;
1544+ } ) ;
1545+
1546+ afterEach ( async ( ) => {
1547+ await closePages ( pages ) ;
1548+ } ) ;
1549+
1550+ it ( "must scroll the selected outline item into the visible sidebar area" , async ( ) => {
1551+ await Promise . all (
1552+ pages . map ( async ( [ browserName , page ] ) => {
1553+ // Open the sidebar.
1554+ await showViewsManager ( page ) ;
1555+
1556+ // Switch to outline view.
1557+ await page . click ( "#viewsManagerSelectorButton" ) ;
1558+ await waitAndClick ( page , "#outlinesViewMenu" ) ;
1559+
1560+ // Wait for the outline tree to render.
1561+ await page . waitForSelector ( "#outlinesView .treeItem" , {
1562+ visible : true ,
1563+ } ) ;
1564+
1565+ // Navigate to page 310, which maps to a nested outline item inside
1566+ // a collapsed parent; _scrollToCurrentTreeItem will expand the parent
1567+ // and scroll the item into view.
1568+ await page . evaluate ( ( ) => {
1569+ window . PDFViewerApplication . page = 310 ;
1570+ } ) ;
1571+ await page . waitForFunction (
1572+ ( ) => window . PDFViewerApplication . page === 310
1573+ ) ;
1574+ await page . waitForSelector (
1575+ ".page[data-page-number='310'] .textLayer .endOfContent"
1576+ ) ;
1577+
1578+ await waitAndClick (
1579+ page ,
1580+ "#viewsManagerCurrentOutlineButton:not(:disabled)"
1581+ ) ;
1582+
1583+ // Wait for an outline item to receive the "selected" class.
1584+ const item = await page . waitForSelector (
1585+ "#outlinesView .treeItemToggler:not(.treeItemsHidden) + a + .treeItems > .treeItem.selected" ,
1586+ {
1587+ visible : true ,
1588+ }
1589+ ) ;
1590+ const isVisible = await item . isIntersectingViewport ( ) ;
1591+ expect ( isVisible ) . withContext ( `In ${ browserName } ` ) . toBeTrue ( ) ;
1592+ const outlineItemText = await item . evaluate ( el =>
1593+ el . textContent . trim ( )
1594+ ) ;
1595+ expect ( outlineItemText )
1596+ . withContext ( `In ${ browserName } ` )
1597+ . toBe ( "Fire Lots of Lawyers" ) ;
1598+ } )
1599+ ) ;
1600+ } ) ;
1601+ } ) ;
1602+
15311603 describe ( "Scroll into view" , ( ) => {
15321604 let pages ;
15331605
0 commit comments