@@ -379,28 +379,18 @@ test.describe( 'Fit Text', () => {
379379 await expect ( heading ) . toBeVisible ( ) ;
380380 await expect ( heading ) . toHaveClass ( / h a s - f i t - t e x t / ) ;
381381
382- // Verify data attribute is set (added by frontend script)
383- const fitTextId = await heading . getAttribute ( 'data-fit-text-id' ) ;
384- expect ( fitTextId ) . toBeTruthy ( ) ;
385-
386- // Verify style element exists for this fit text instance.
387- const styleElement = page . locator (
388- `style#fit-text-${ fitTextId } `
389- ) ;
390- await expect ( styleElement ) . toBeAttached ( ) ;
382+ const inlineStyle = await heading . getAttribute ( 'style' ) ;
383+ expect ( inlineStyle ) . toContain ( 'font-size' ) ;
384+ expect ( inlineStyle ) . toMatch ( / f o n t - s i z e : \s * \d + p x / ) ;
391385
392386 const computedFontSize = await heading . evaluate ( ( el ) => {
393387 return window . getComputedStyle ( el ) . fontSize ;
394388 } ) ;
395389
396- const styleContent = await styleElement . textContent ( ) ;
397- const fontSizeMatch = styleContent . match (
398- / f o n t - s i z e : \s * ( \d + (?: \. \d + ) ? ) p x /
399- ) ;
400- expect ( fontSizeMatch ) . toBeTruthy ( ) ;
401- const expectedFontSize = parseFloat ( fontSizeMatch [ 1 ] ) ;
402-
403- expect ( parseFloat ( computedFontSize ) ) . toBe ( expectedFontSize ) ;
390+ // Verify font size is actually applied and is a reasonable value
391+ const fontSize = parseFloat ( computedFontSize ) ;
392+ expect ( fontSize ) . toBeGreaterThan ( 0 ) ;
393+ expect ( fontSize ) . toBeLessThan ( 600 ) ;
404394 } ) ;
405395
406396 test ( 'should resize text on window resize on the frontend' , async ( {
@@ -426,48 +416,41 @@ test.describe( 'Fit Text', () => {
426416
427417 const heading = page . locator ( 'h2.has-fit-text' ) ;
428418
429- // Wait for fit text to initialize (verify frontend script ran)
430- await heading . waitFor ( { state : 'attached' } ) ;
431- const fitTextId = await heading . getAttribute ( 'data-fit-text-id' ) ;
432- expect ( fitTextId ) . toBeTruthy ( ) ;
419+ // Wait for fit text to initialize
420+ await heading . waitFor ( { state : 'visible' } ) ;
421+ await expect ( heading ) . toHaveClass ( / h a s - f i t - t e x t / ) ;
433422
434- // Verify style element exists for this fit text instance
435- const styleElement = page . locator (
436- `style#fit-text-${ fitTextId } `
423+ // Wait for inline style to be applied
424+ await page . waitForFunction (
425+ ( ) => {
426+ const el = document . querySelector ( 'h2.has-fit-text' ) ;
427+ return el && el . style . fontSize && el . style . fontSize !== '' ;
428+ } ,
429+ { timeout : 5000 }
437430 ) ;
438- await styleElement . waitFor ( { state : 'attached' } ) ;
439431
440432 const initialFontSize = await heading . evaluate ( ( el ) => {
441433 return window . getComputedStyle ( el ) . fontSize ;
442434 } ) ;
443435
444- // Capture style content before resize
445- const styleBeforeResize = await styleElement . textContent ( ) ;
436+ const initialInlineStyle = await heading . getAttribute ( 'style' ) ;
446437
447438 await page . setViewportSize ( { width : 440 , height : 720 } ) ;
448439
449- // Wait for fit text to recalculate (style content changes)
440+ // Wait for inline font-size style to change after resize
450441 await page . waitForFunction (
451- ( { styleId , previousContent } ) => {
452- const style = document . getElementById ( styleId ) ;
442+ ( previousStyle ) => {
443+ const el = document . querySelector ( 'h2.has-fit-text' ) ;
453444 return (
454- style &&
455- style . textContent !== previousContent &&
456- style . textContent . trim ( ) . length > 0
445+ el &&
446+ el . style . fontSize &&
447+ el . getAttribute ( 'style' ) !== previousStyle
457448 ) ;
458449 } ,
459- {
460- styleId : `fit-text-${ fitTextId } ` ,
461- previousContent : styleBeforeResize ,
462- } ,
450+ initialInlineStyle ,
463451 { timeout : 5000 }
464452 ) ;
465453
466- // Verify the same element instance is maintained (ID unchanged)
467- const fitTextIdAfterResize =
468- await heading . getAttribute ( 'data-fit-text-id' ) ;
469- expect ( fitTextIdAfterResize ) . toBe ( fitTextId ) ;
470-
471454 const newFontSize = await heading . evaluate ( ( el ) => {
472455 return window . getComputedStyle ( el ) . fontSize ;
473456 } ) ;
@@ -509,17 +492,18 @@ test.describe( 'Fit Text', () => {
509492
510493 const fitTextParagraph = page . locator ( 'p.has-fit-text' ) ;
511494
512- // Wait for fit text to initialize (verify frontend script ran)
495+ // Wait for fit text to initialize
513496 await fitTextParagraph . waitFor ( { state : 'visible' } ) ;
514- const fitTextId =
515- await fitTextParagraph . getAttribute ( 'data-fit-text-id' ) ;
516- expect ( fitTextId ) . toBeTruthy ( ) ;
497+ await expect ( fitTextParagraph ) . toHaveClass ( / h a s - f i t - t e x t / ) ;
517498
518- // Verify style element exists for this fit text instance
519- const styleElement = page . locator (
520- `style#fit-text-${ fitTextId } `
499+ // Wait for inline style to be applied
500+ await page . waitForFunction (
501+ ( ) => {
502+ const el = document . querySelector ( 'p.has-fit-text' ) ;
503+ return el && el . style . fontSize && el . style . fontSize !== '' ;
504+ } ,
505+ { timeout : 5000 }
521506 ) ;
522- await expect ( styleElement ) . toBeAttached ( ) ;
523507
524508 const paragraphs = page . locator ( 'p' ) ;
525509
0 commit comments