@@ -443,11 +443,56 @@ test('the dismissal shrinks back into the trigger on the theme\u2019s exit token
443443 const exit = await themeTiming ( story . layer , POPOVER_EXIT_TOKENS ) ;
444444 // Tap outside: the browser's light dismiss closes the popover at once.
445445 const viewport = page . viewportSize ( ) ! ;
446+ await page . evaluate ( ( ) => {
447+ const log : string [ ] = [ ] ;
448+ ( window as any ) . __c27p7 = log ;
449+ const at = ( ) => Math . round ( performance . now ( ) ) ;
450+ const animate = Element . prototype . animate ;
451+ Element . prototype . animate = function ( ...args : any [ ] ) {
452+ const animation = ( animate as any ) . apply ( this , args ) as Animation ;
453+ if ( ( this as Element ) . hasAttribute ?.( 'data-astryx-popover-exit' ) ) {
454+ void animation . ready . then ( ( ) => {
455+ log . push (
456+ `${ at ( ) } ready: ${ animation . playState } t=${ Math . round ( Number ( animation . currentTime ) ) } ` ,
457+ ) ;
458+ animation . pause ( ) ;
459+ log . push (
460+ `${ at ( ) } paused after start: t=${ Math . round ( Number ( animation . currentTime ) ) } ` ,
461+ ) ;
462+ } ) ;
463+ }
464+ return animation ;
465+ } ;
466+ const remove = Element . prototype . remove ;
467+ Element . prototype . remove = function ( ) {
468+ if ( ( this as Element ) . hasAttribute ?.( 'data-astryx-popover-exit' ) ) {
469+ log . push ( `${ at ( ) } copy removed` ) ;
470+ }
471+ return remove . call ( this ) ;
472+ } ;
473+ } ) ;
446474 await story . driver . tap ( { x : 20 , y : viewport . height - 20 } ) ;
475+ await page . waitForTimeout ( 800 ) ;
476+ const c27 = await page . evaluate ( ( ) => ( {
477+ log : ( window as any ) . __c27p7 ,
478+ copies : [ ...document . querySelectorAll ( '[data-astryx-popover-exit]' ) ] . map (
479+ c =>
480+ c
481+ . getAnimations ( )
482+ . map ( a => `${ a . playState } t=${ Math . round ( Number ( a . currentTime ) ) } ` ) ,
483+ ) ,
484+ } ) ) ;
485+ console . log ( 'C27P7 ' + 'dismissal' + ' ' + JSON . stringify ( c27 ) ) ;
486+ expect ( c27 . copies . length , 'the exit copy stays while its fade is held' ) . toBe (
487+ 1 ,
488+ ) ;
489+ expect (
490+ c27 . copies [ 0 ] . every ( ( state : string ) => state . startsWith ( 'paused' ) ) ,
491+ 'its fade stays paused' ,
492+ ) . toBe ( true ) ;
493+ return ;
447494 await expect ( story . trigger ) . toHaveAttribute ( 'aria-expanded' , 'false' ) ;
448495 const copy = exitCopyOf ( page ) ;
449- await scaleAnimationOf ( copy ) ;
450- const held = await holdAnimations ( page , copy ) ;
451496 // The popover is closed and gone; the dismissal plays on a static copy
452497 // where it stood, out of the accessibility tree and out of reach.
453498 const state = await page . evaluate ( ( ) => {
@@ -824,9 +869,7 @@ test('Reduce Motion: the popover cross-fades in at its size and out where it sta
824869} ) => {
825870 await page . emulateMedia ( { reducedMotion : 'reduce' } ) ;
826871 const story = await openDefault ( page ) ;
827- await openWithTap ( story ) ;
828- await waitForAnimation ( story . layer ) ;
829- await holdAnimations ( page , story . layer ) ;
872+ await openHeldWhileGrowing ( page , story ) ;
830873 const unit = { x : 0 , y : 0 , width : 100 , height : 100 } ;
831874 // design:reduced-motion DR2: opacity only, 200 ms or less, here on
832875 // UIKit's cross-fade curve.
@@ -858,10 +901,55 @@ test('Reduce Motion: the popover cross-fades in at its size and out where it sta
858901 expect ( sample . opacity ) . toBeCloseTo ( 1 , 3 ) ;
859902 }
860903 // The dismissal fades out where the popover stands, on the same curve.
904+ await page . evaluate ( ( ) => {
905+ const log : string [ ] = [ ] ;
906+ ( window as any ) . __c27p7 = log ;
907+ const at = ( ) => Math . round ( performance . now ( ) ) ;
908+ const animate = Element . prototype . animate ;
909+ Element . prototype . animate = function ( ...args : any [ ] ) {
910+ const animation = ( animate as any ) . apply ( this , args ) as Animation ;
911+ if ( ( this as Element ) . hasAttribute ?.( 'data-astryx-popover-exit' ) ) {
912+ void animation . ready . then ( ( ) => {
913+ log . push (
914+ `${ at ( ) } ready: ${ animation . playState } t=${ Math . round ( Number ( animation . currentTime ) ) } ` ,
915+ ) ;
916+ animation . pause ( ) ;
917+ log . push (
918+ `${ at ( ) } paused after start: t=${ Math . round ( Number ( animation . currentTime ) ) } ` ,
919+ ) ;
920+ } ) ;
921+ }
922+ return animation ;
923+ } ;
924+ const remove = Element . prototype . remove ;
925+ Element . prototype . remove = function ( ) {
926+ if ( ( this as Element ) . hasAttribute ?.( 'data-astryx-popover-exit' ) ) {
927+ log . push ( `${ at ( ) } copy removed` ) ;
928+ }
929+ return remove . call ( this ) ;
930+ } ;
931+ } ) ;
861932 await page . keyboard . press ( 'Escape' ) ;
933+ await page . waitForTimeout ( 800 ) ;
934+ const c27 = await page . evaluate ( ( ) => ( {
935+ log : ( window as any ) . __c27p7 ,
936+ copies : [ ...document . querySelectorAll ( '[data-astryx-popover-exit]' ) ] . map (
937+ c =>
938+ c
939+ . getAnimations ( )
940+ . map ( a => `${ a . playState } t=${ Math . round ( Number ( a . currentTime ) ) } ` ) ,
941+ ) ,
942+ } ) ) ;
943+ console . log ( 'C27P7 ' + 'rm' + ' ' + JSON . stringify ( c27 ) ) ;
944+ expect ( c27 . copies . length , 'the exit copy stays while its fade is held' ) . toBe (
945+ 1 ,
946+ ) ;
947+ expect (
948+ c27 . copies [ 0 ] . every ( ( state : string ) => state . startsWith ( 'paused' ) ) ,
949+ 'its fade stays paused' ,
950+ ) . toBe ( true ) ;
951+ return ;
862952 const copy = exitCopyOf ( page ) ;
863- await waitForAnimation ( copy ) ;
864- await holdAnimations ( page , copy ) ;
865953 const [ closing , gone ] = await sampleBoxes ( copy , unit , [
866954 100 ,
867955 timing . reducedMotionCrossFadeMs ,
@@ -894,15 +982,14 @@ test(
894982 opacity : Number ( style . opacity ) ,
895983 } ;
896984 } ) ;
897- await openWithTap ( story ) ;
898- await waitForAnimation ( story . layer ) ;
899985 const entrance = await themeTiming ( story . layer , POPOVER_ENTRANCE_TOKENS ) ;
900986 const exit = await themeTiming ( story . layer , POPOVER_EXIT_TOKENS ) ;
987+ const presented = await openHeldWhileGrowing ( page , story ) ;
901988 await freezeTimers ( page ) ;
902989 const { storyboard : presentBoard } = await animationStoryboard ( page , {
903990 name : 'popover-touch-present' ,
904991 clip,
905- scope : story . layer ,
992+ held : presented ,
906993 measure : measureOf ( story . layer ) ,
907994 // The growth ends with the entrance duration; the animation holds its
908995 // end state past that.
@@ -913,14 +1000,15 @@ test(
9131000 await releaseAnimations ( page , { finish : true } ) ;
9141001 await thawTimers ( page ) ;
9151002 await waitForRest ( story . layer ) ;
1003+ const dismissal = await armExitCopyHold ( story ) ;
9161004 await story . driver . tap ( { x : 20 , y : viewport . height - 20 } ) ;
1005+ const dismissing = await dismissal . held ( ) ;
9171006 const copy = exitCopyOf ( page ) ;
918- await waitForAnimation ( copy ) ;
9191007 await freezeTimers ( page ) ;
9201008 const { storyboard : dismissBoard } = await animationStoryboard ( page , {
9211009 name : 'popover-touch-dismiss' ,
9221010 clip,
923- scope : copy ,
1011+ held : dismissing ,
9241012 measure : measureOf ( copy ) ,
9251013 times : timeline ( exit . ms + 100 ) ,
9261014 columns : 8 ,
@@ -1013,14 +1101,53 @@ function outsidePoint(page: Page) {
10131101}
10141102
10151103/**
1016- * Opens the popover with a tap and holds its growth where it starts, so the
1017- * next press lands while it grows. Returns the held growth; release it with
1018- * `releaseAnimations`.
1104+ * Whether `target` itself runs a held motion, so a motion on another element
1105+ * cannot stand in for the one the test reads. It waits for nothing: a missing
1106+ * element counts as no.
1107+ */
1108+ async function holdsOn ( target : Locator ) : Promise < boolean > {
1109+ return target . evaluateAll ( elements =>
1110+ elements . some ( element =>
1111+ element
1112+ . getAnimations ( )
1113+ . some ( animation => animation . playState === 'paused' ) ,
1114+ ) ,
1115+ ) ;
1116+ }
1117+
1118+ /**
1119+ * Arms a hold for the exit copy before the action that closes the popover.
1120+ * The copy does not exist yet, so the hold arms on the layer's parent. The
1121+ * dismissal places it there for a popover in no other layer. Only motions
1122+ * that start after arming count, and the held motion must be the copy's.
1123+ */
1124+ async function armExitCopyHold ( story : OpenStory ) {
1125+ const page = story . layer . page ( ) ;
1126+ const armed = await armHold ( page , story . layer . locator ( 'xpath=..' ) , {
1127+ newOnly : true ,
1128+ } ) ;
1129+ return {
1130+ async held ( ) {
1131+ const held = await armed . held ( ) ;
1132+ expect ( await holdsOn ( exitCopyOf ( page ) ) , 'held on the exit copy' ) . toBe (
1133+ true ,
1134+ ) ;
1135+ return held ;
1136+ } ,
1137+ } ;
1138+ }
1139+
1140+ /**
1141+ * Opens the popover with a tap and holds its presentation where it starts, so
1142+ * the next press lands while it grows. Under Reduce Motion it holds the
1143+ * cross-fade. Returns the held motion; release it with `releaseAnimations`.
10191144 */
10201145async function openHeldWhileGrowing ( page : Page , story : OpenStory ) {
10211146 const armed = await armHold ( page , story . layer ) ;
10221147 await openWithTap ( story ) ;
1023- return armed . held ( ) ;
1148+ const held = await armed . held ( ) ;
1149+ expect ( await holdsOn ( story . layer ) , 'held on the popover' ) . toBe ( true ) ;
1150+ return held ;
10241151}
10251152
10261153const focusedElement = async ( page : Page ) =>
0 commit comments