@@ -1520,7 +1520,7 @@ it.each([
15201520} ) ;
15211521
15221522it . each ( [ false , true ] ) (
1523- "bounds shared-string text including CDATA %s per cell and across sheets in the worker and viewer " ,
1523+ "bounds shared-string text including CDATA %s per cell and across sheets in the worker" ,
15241524 async ( cdata ) => {
15251525 const { default : JSZip } = await import ( "jszip" ) ;
15261526 const archive = new JSZip ( ) ;
@@ -1581,34 +1581,6 @@ it.each([false, true])(
15811581 } finally {
15821582 worker . terminate ( ) ;
15831583 }
1584- const src = URL . createObjectURL ( file ) ;
1585- try {
1586- const container = document . createElement ( "div" ) ;
1587- container . style . cssText = "display:flex;flex-direction:column;width:640px;height:480px" ;
1588- await using screen = await render (
1589- < OfficeFilePreview src = { src } name = "shared.xlsx" kind = "xlsx" /> ,
1590- { container } ,
1591- ) ;
1592- await vi . waitFor (
1593- ( ) =>
1594- expect ( screen . container . querySelector ( '[role="gridcell"]' ) ?. textContent ) . toHaveLength (
1595- 4096 ,
1596- ) ,
1597- { timeout : 30_000 } ,
1598- ) ;
1599- expect ( screen . container . textContent ) . toContain ( "Preview limited" ) ;
1600- const canvas = screen . container . querySelector ( "canvas" ) ! ;
1601- await vi . waitFor ( ( ) => expect ( canvas . width ) . toBeGreaterThan ( 0 ) ) ;
1602- const scroll = screen . container . querySelector < HTMLElement > ( '[role="grid"]' ) ! ;
1603- await act ( ( ) => {
1604- scroll . scrollTop = 200 ;
1605- scroll . scrollLeft = 200 ;
1606- } ) ;
1607- await vi . waitFor ( ( ) => expect ( scroll . scrollTop ) . toBe ( 200 ) ) ;
1608- expect ( canvas . getBoundingClientRect ( ) . top ) . toBeCloseTo ( scroll . getBoundingClientRect ( ) . top , 0 ) ;
1609- } finally {
1610- URL . revokeObjectURL ( src ) ;
1611- }
16121584 } ,
16131585) ;
16141586
@@ -2349,112 +2321,6 @@ it("toggles a Mermaid attachment between diagram and source through the lazy pre
23492321 expect ( screen . container . querySelector ( '[role="alert"]' ) ) . toBeNull ( ) ;
23502322} ) ;
23512323
2352- it ( "navigates, searches, zooms, and selects mixed-height PDF pages" , async ( ) => {
2353- const objects = [
2354- "<< /Type /Catalog /Pages 2 0 R >>" ,
2355- "<< /Type /Pages /Count 3 /Kids [3 0 R 5 0 R 7 0 R] >>" ,
2356- ] ;
2357- for ( const [ index , title ] of [
2358- "Quarterly outlook" ,
2359- "Delivery milestones" ,
2360- "Budget and risks" ,
2361- ] . entries ( ) ) {
2362- const text = `/GS1 gs BT /F1 24 Tf 30 ${ index === 0 ? 70 : 700 } Td ${ index === 0 ? "(Quarter) Tj /F2 24 Tf (ly outlook) Tj" : `(${ title } ) Tj` } ET` ;
2363- objects . push (
2364- `<< /Type /Page /Parent 2 0 R /MediaBox [0 0 612 ${ index === 0 ? 140 : 792 } ] /Rotate ${ index === 2 ? 90 : 0 } /Resources << /Font << /F1 9 0 R /F2 10 0 R >> /ExtGState << /GS1 << /TR << /FunctionType 2 /Domain [0 1] /C0 [0] /C1 [1] /N 2 >> >> >> >> /Contents ${ 4 + index * 2 } 0 R >>` ,
2365- `<< /Length ${ text . length } >>\nstream\n${ text } \nendstream` ,
2366- ) ;
2367- }
2368- objects . push ( "<< /Type /Font /Subtype /Type1 /BaseFont /Helvetica >>" ) ;
2369- objects . push ( "<< /Type /Font /Subtype /Type1 /BaseFont /Helvetica-Bold >>" ) ;
2370- let source = "%PDF-1.4\n" ;
2371- const offsets = [ 0 ] ;
2372- for ( const [ index , object ] of objects . entries ( ) ) {
2373- offsets . push ( source . length ) ;
2374- source += `${ index + 1 } 0 obj\n${ object } \nendobj\n` ;
2375- }
2376- const xref = source . length ;
2377- source += `xref\n0 11\n0000000000 65535 f \n${ offsets
2378- . slice ( 1 )
2379- . map ( ( offset ) => `${ String ( offset ) . padStart ( 10 , "0" ) } 00000 n \n` )
2380- . join ( "" ) } trailer\n<< /Size 11 /Root 1 0 R >>\nstartxref\n${ xref } \n%%EOF`;
2381- const file = new Blob ( [ source ] , { type : "application/pdf" } ) ;
2382- const { default : PdfViewer } = await import ( "./PdfViewer" ) ;
2383- const url = URL . createObjectURL ( file ) ;
2384- try {
2385- await using screen = await render (
2386- < div style = { { display : "flex" , height : 600 , width : 320 } } >
2387- < PdfViewer src = { url } title = "Planning PDF" />
2388- </ div > ,
2389- ) ;
2390- await vi . waitFor ( ( ) => expect ( screen . container . textContent ) . toContain ( "1 / 3 pages" ) , {
2391- timeout : 15_000 ,
2392- } ) ;
2393- const region = screen . container . querySelector < HTMLElement > ( '[role="region"]' ) ! ;
2394- await vi . waitFor ( ( ) => {
2395- expect ( region . scrollWidth ) . toBe ( region . clientWidth ) ;
2396- expect ( region . querySelector ( "canvas" ) ! . getBoundingClientRect ( ) . width ) . toBeLessThan (
2397- region . clientWidth ,
2398- ) ;
2399- expect ( screen . container . textContent ) . toContain ( "Fit width" ) ;
2400- } ) ;
2401- await act ( ( ) => {
2402- ( screen . container . firstElementChild as HTMLElement ) . style . width = "500px" ;
2403- } ) ;
2404- await vi . waitFor ( ( ) =>
2405- expect ( region . querySelector ( "canvas" ) ! . getBoundingClientRect ( ) . width ) . toBe ( 468 ) ,
2406- ) ;
2407- await screen . getByRole ( "button" , { name : "Next page" , exact : true } ) . click ( ) ;
2408- await vi . waitFor ( ( ) => expect ( screen . container . textContent ) . toContain ( "2 / 3 pages" ) ) ;
2409- await screen . getByRole ( "button" , { name : "Previous page" , exact : true } ) . click ( ) ;
2410- await vi . waitFor ( ( ) => expect ( screen . container . textContent ) . toContain ( "1 / 3 pages" ) ) ;
2411- await screen . getByRole ( "button" , { name : "Zoom in" , exact : true } ) . click ( ) ;
2412- await vi . waitFor ( ( ) => expect ( region . scrollWidth ) . toBeGreaterThan ( region . clientWidth ) ) ;
2413- await screen . getByRole ( "button" , { name : "Fit width" , exact : true } ) . click ( ) ;
2414- await vi . waitFor ( ( ) => expect ( region . scrollWidth ) . toBe ( region . clientWidth ) ) ;
2415- await screen . getByRole ( "searchbox" , { name : "Find in PDF" } ) . fill ( "Quarterly outlook" ) ;
2416- await vi . waitFor ( ( ) => {
2417- expect ( screen . container . querySelector ( '[role="status"]' ) ?. textContent ) . toBe ( "1/1" ) ;
2418- expect (
2419- Array . from ( region . querySelectorAll ( ".pdf-find-match" ) ) . map ( ( span ) => span . textContent ) ,
2420- ) . toEqual ( [ "Quarter" , "ly outlook" ] ) ;
2421- } ) ;
2422- await screen . getByRole ( "searchbox" , { name : "Find in PDF" } ) . fill ( "Budget" ) ;
2423- await vi . waitFor ( ( ) => expect ( screen . container . textContent ) . toContain ( "3 / 3 pages" ) ) ;
2424- await screen . getByRole ( "button" , { name : "Zoom in" , exact : true } ) . click ( ) ;
2425- await vi . waitFor ( ( ) => expect ( screen . container . textContent ) . toContain ( "3 / 3 pages" ) ) ;
2426- await vi . waitFor ( ( ) => {
2427- const span = Array . from ( screen . container . querySelectorAll ( "[data-pdf-text-layer] span" ) ) . find (
2428- ( node ) => node . textContent === "Budget and risks" ,
2429- ) ;
2430- expect ( span ) . toBeDefined ( ) ;
2431- const textBounds = span ! . getBoundingClientRect ( ) ;
2432- const pageBounds = span ! . parentElement ! . getBoundingClientRect ( ) ;
2433- expect ( textBounds . width ) . toBeGreaterThan ( 0 ) ;
2434- expect ( textBounds . height ) . toBeGreaterThan ( 0 ) ;
2435- expect ( textBounds . left ) . toBeGreaterThanOrEqual ( pageBounds . left - 1 ) ;
2436- expect ( textBounds . top ) . toBeGreaterThanOrEqual ( pageBounds . top - 1 ) ;
2437- expect ( textBounds . right ) . toBeLessThanOrEqual ( pageBounds . right + 1 ) ;
2438- expect ( textBounds . bottom ) . toBeLessThanOrEqual ( pageBounds . bottom + 1 ) ;
2439- const range = document . createRange ( ) ;
2440- range . selectNodeContents ( span ! ) ;
2441- const selection = window . getSelection ( ) ! ;
2442- selection . removeAllRanges ( ) ;
2443- selection . addRange ( range ) ;
2444- expect ( selection . toString ( ) ) . toBe ( "Budget and risks" ) ;
2445- expect ( getComputedStyle ( span ! ) . userSelect ) . toBe ( "text" ) ;
2446- selection . removeAllRanges ( ) ;
2447- } ) ;
2448- await screen . getByRole ( "button" , { name : "Fit width" , exact : true } ) . click ( ) ;
2449- await vi . waitFor ( ( ) => expect ( screen . container . textContent ) . toContain ( "3 / 3 pages" ) ) ;
2450- await screen . getByRole ( "searchbox" , { name : "Find in PDF" } ) . fill ( " " ) ;
2451- await vi . waitFor ( ( ) =>
2452- expect ( screen . container . querySelector ( '[role="status"]' ) ?. textContent ) . toBe ( "0/0" ) ,
2453- ) ;
2454- } finally {
2455- URL . revokeObjectURL ( url ) ;
2456- }
2457- } ) ;
24582324it ( "mounts a bounded set of saved notebook outputs as the reader scrolls" , async ( ) => {
24592325 const notebook = {
24602326 nbformat : 4 ,
@@ -2480,8 +2346,10 @@ it("mounts a bounded set of saved notebook outputs as the reader scrolls", async
24802346 />
24812347 </ div > ,
24822348 ) ;
2483- await vi . waitFor ( ( ) =>
2484- expect ( screen . container . querySelectorAll ( "iframe" ) . length ) . toBeGreaterThan ( 0 ) ,
2349+ // The first outputs wait on the lazy notebook viewer and the conversion worker, not on a frame.
2350+ await vi . waitFor (
2351+ ( ) => expect ( screen . container . querySelectorAll ( "iframe" ) . length ) . toBeGreaterThan ( 0 ) ,
2352+ { timeout : 10_000 } ,
24852353 ) ;
24862354 expect ( screen . container . querySelectorAll ( "iframe" ) . length ) . toBeLessThanOrEqual ( 16 ) ;
24872355 const first = screen . container . querySelector ( "iframe" ) ! ;
@@ -2635,18 +2503,22 @@ it.each(["rtf", "epub", "ods"] as const)(
26352503 />
26362504 </ div > ,
26372505 ) ;
2638- await vi . waitFor ( ( ) => {
2639- if ( kind === "ods" ) {
2640- expect ( screen . container . textContent ) . toContain ( "North" ) ;
2641- expect ( screen . container . textContent ) . toContain ( "150" ) ;
2642- expect ( screen . container . textContent ) . not . toContain ( "private note" ) ;
2643- expect ( screen . container . textContent ) . toContain ( "1 rows · 2 columns" ) ;
2644- expect ( screen . container . textContent ) . not . toContain ( "Limited to 500" ) ;
2645- } else {
2646- const frame = screen . container . querySelector ( "iframe" ) ;
2647- expect ( frame ?. srcdoc ) . toContain ( kind === "rtf" ? "10–20" : "first<br>second<br>third" ) ;
2648- }
2649- } ) ;
2506+ await vi . waitFor (
2507+ ( ) => {
2508+ if ( kind === "ods" ) {
2509+ expect ( screen . container . textContent ) . toContain ( "North" ) ;
2510+ expect ( screen . container . textContent ) . toContain ( "150" ) ;
2511+ expect ( screen . container . textContent ) . not . toContain ( "private note" ) ;
2512+ expect ( screen . container . textContent ) . toContain ( "1 rows · 2 columns" ) ;
2513+ expect ( screen . container . textContent ) . not . toContain ( "Limited to 500" ) ;
2514+ } else {
2515+ const frame = screen . container . querySelector ( "iframe" ) ;
2516+ expect ( frame ?. srcdoc ) . toContain ( kind === "rtf" ? "10–20" : "first<br>second<br>third" ) ;
2517+ }
2518+ // The viewer runs its own conversion worker behind lazy chunks.
2519+ } ,
2520+ { timeout : 10_000 } ,
2521+ ) ;
26502522 expect ( screen . container . querySelector ( '[role="alert"]' ) ) . toBeNull ( ) ;
26512523 } ,
26522524) ;
0 commit comments