@@ -479,7 +479,10 @@ describe("large text preview recovery", () => {
479479 await using screen = await render ( preview ( "first" ) ) ;
480480 await vi . waitFor ( ( ) => expect ( workers ) . toHaveLength ( 1 ) ) ;
481481 await vi . waitFor ( ( ) => expect ( screen . container . textContent ) . toContain ( "original" ) ) ;
482- await vi . waitFor ( ( ) => expect ( screen . container . textContent ) . toContain ( "1,000 lines" ) ) ;
482+ // Indexing runs in the worker, so on a loaded runner it can outlast the default wait.
483+ await vi . waitFor ( ( ) => expect ( screen . container . textContent ) . toContain ( "1,000 lines" ) , {
484+ timeout : 10_000 ,
485+ } ) ;
483486 const viewport = screen . container . querySelector < HTMLElement > ( '[tabindex="0"]' ) ! ;
484487 await act ( ( ) =>
485488 viewport . dispatchEvent (
@@ -1388,16 +1391,17 @@ it.each(["footnotes", "footer"] as const)(
13881391 } ,
13891392) ;
13901393
1391- it . each ( [
1394+ const ORDINARY_WORD_SCENARIOS = [
13921395 "ordinary parts" ,
13931396 "unused parts" ,
13941397 "independent styles" ,
13951398 "inherited styles" ,
13961399 "python-docx package" ,
13971400 "default template styles" ,
13981401 "binary package properties" ,
1399- ] ) ( "retains Word %s without a limit warning" , async ( scenario ) => {
1400- const { default : JSZip } = await import ( "jszip" ) ;
1402+ ] as const ;
1403+
1404+ async function ordinaryWordFixture ( scenario : ( typeof ORDINARY_WORD_SCENARIOS ) [ number ] ) {
14011405 const archive = new JSZip ( ) ;
14021406 const ns = "http://schemas.openxmlformats.org/wordprocessingml/2006/main" ;
14031407 const r = "http://schemas.openxmlformats.org/officeDocument/2006/relationships" ;
@@ -1506,33 +1510,61 @@ it.each([
15061510 ) ,
15071511 ) ;
15081512 }
1509- const file = await archive . generateAsync ( { type : "blob" , compression : "DEFLATE" } ) ;
1510- const src = URL . createObjectURL ( file ) ;
1511- try {
1512- const container = document . createElement ( "div" ) ;
1513- container . style . cssText = "display:flex;flex-direction:column;width:640px;height:700px" ;
1514- await using screen = await render (
1515- < OfficeFilePreview src = { src } name = "ordinary.docx" kind = "docx" /> ,
1516- { container } ,
1517- ) ;
1518- await vi . waitFor ( ( ) => expect ( screen . container . textContent ) . toContain ( "ordinary body" ) , {
1519- timeout : 30_000 ,
1520- } ) ;
1521- expect ( screen . container . textContent ) . not . toContain ( "Preview limited" ) ;
1522- await vi . waitFor ( ( ) =>
1523- expect ( screen . container . querySelector ( "canvas" ) ! . width ) . toBeGreaterThan ( 0 ) ,
1524- ) ;
1525- if ( scenario === "default template styles" )
1526- expect ( screen . container . textContent ) . toContain ( "styled cell" ) ;
1527- if ( ordinary ) {
1528- expect ( screen . container . textContent ) . toContain ( "header retained" ) ;
1529- expect ( screen . container . textContent ) . toContain ( "footer retained" ) ;
1530- }
1531- } finally {
1532- URL . revokeObjectURL ( src ) ;
1513+ return archive . generateAsync ( { type : "blob" , compression : "DEFLATE" } ) ;
1514+ }
1515+
1516+ // The limit decision lives in prepareOffice. Rendering compiles the layout engine for each case,
1517+ // so only the cases whose retained parts the engine must accept render in full.
1518+ it . each ( ORDINARY_WORD_SCENARIOS ) ( "prepares Word %s without a limit warning" , async ( scenario ) => {
1519+ const { prepareOffice } = await import ( "./officeArchive" ) ;
1520+ const file = await ordinaryWordFixture ( scenario ) ;
1521+ const prepared = await prepareOffice ( await file . arrayBuffer ( ) , "docx" ) ;
1522+ expect ( prepared . truncated ) . toBe ( false ) ;
1523+ const bounded = await JSZip . loadAsync ( prepared . bytes ) ;
1524+ const markup = await bounded . file ( "word/document.xml" ) ! . async ( "string" ) ;
1525+ expect ( markup ) . toContain ( "ordinary body" ) ;
1526+ expect ( markup ) . toContain ( "styled body" ) ;
1527+ expect ( bounded . file ( "word/styles.xml" ) ) . not . toBeNull ( ) ;
1528+ if ( scenario === "default template styles" ) expect ( markup ) . toContain ( "styled cell" ) ;
1529+ if ( scenario === "ordinary parts" ) {
1530+ expect ( markup ) . toMatch ( / < w : h e a d e r R e f e r e n c e / ) ;
1531+ expect ( markup ) . toMatch ( / < w : f o o t e r R e f e r e n c e / ) ;
1532+ for ( const role of [ "header" , "footer" , "footnotes" , "endnotes" , "comments" ] )
1533+ expect ( await bounded . file ( `word/${ role } .xml` ) ! . async ( "string" ) ) . toContain ( `${ role } retained` ) ;
15331534 }
15341535} ) ;
15351536
1537+ it . each ( [ "ordinary parts" , "default template styles" ] as const ) (
1538+ "retains Word %s without a limit warning" ,
1539+ async ( scenario ) => {
1540+ const file = await ordinaryWordFixture ( scenario ) ;
1541+ const src = URL . createObjectURL ( file ) ;
1542+ try {
1543+ const container = document . createElement ( "div" ) ;
1544+ container . style . cssText = "display:flex;flex-direction:column;width:640px;height:700px" ;
1545+ await using screen = await render (
1546+ < OfficeFilePreview src = { src } name = "ordinary.docx" kind = "docx" /> ,
1547+ { container } ,
1548+ ) ;
1549+ await vi . waitFor ( ( ) => expect ( screen . container . textContent ) . toContain ( "ordinary body" ) , {
1550+ timeout : 30_000 ,
1551+ } ) ;
1552+ expect ( screen . container . textContent ) . not . toContain ( "Preview limited" ) ;
1553+ await vi . waitFor ( ( ) =>
1554+ expect ( screen . container . querySelector ( "canvas" ) ! . width ) . toBeGreaterThan ( 0 ) ,
1555+ ) ;
1556+ if ( scenario === "default template styles" )
1557+ expect ( screen . container . textContent ) . toContain ( "styled cell" ) ;
1558+ if ( scenario === "ordinary parts" ) {
1559+ expect ( screen . container . textContent ) . toContain ( "header retained" ) ;
1560+ expect ( screen . container . textContent ) . toContain ( "footer retained" ) ;
1561+ }
1562+ } finally {
1563+ URL . revokeObjectURL ( src ) ;
1564+ }
1565+ } ,
1566+ ) ;
1567+
15361568it . each ( [ false , true ] ) (
15371569 "bounds shared-string text including CDATA %s per cell and across sheets in the worker and viewer" ,
15381570 async ( cdata ) => {
0 commit comments