@@ -160,3 +160,80 @@ describe("contrast motion policy with real GSAP", () => {
160160 root . kill ( ) ;
161161 } ) ;
162162} ) ;
163+
164+ describe ( "a layer under the text" , ( ) => {
165+ afterEach ( ( ) => {
166+ Reflect . deleteProperty ( window , "__timelines" ) ;
167+ Reflect . deleteProperty ( window , "__contrastAuditRestores" ) ;
168+ realGsap . ticker . sleep ( ) ;
169+ } ) ;
170+
171+ function layers ( ) {
172+ document . body . innerHTML =
173+ '<div id="stage"><div id="bg"></div><h1 id="label">Hello</h1><div id="aside"></div></div>' ;
174+ const byId = ( id : string ) => document . getElementById ( id ) as HTMLElement ;
175+ const place = ( el : HTMLElement , left : number , right : number ) =>
176+ Object . defineProperty ( el , "getBoundingClientRect" , {
177+ value : ( ) => ( { left, right, top : 0 , bottom : 100 } ) ,
178+ } ) ;
179+ place ( byId ( "bg" ) , 0 , 1000 ) ;
180+ place ( byId ( "label" ) , 100 , 400 ) ;
181+ place ( byId ( "aside" ) , 700 , 900 ) ;
182+ return { bg : byId ( "bg" ) , label : byId ( "label" ) , aside : byId ( "aside" ) } ;
183+ }
184+
185+ const inMotionAt = ( time : number , animate : ( root : RealTimeline ) => void ) => {
186+ const { label } = layers ( ) ;
187+ const root = realGsap . timeline ( { paused : true } ) ;
188+ animate ( root ) ;
189+ root . totalTime ( time , true ) ;
190+ Reflect . set ( window , "__timelines" , { root } ) ;
191+ prepared ( label ) ;
192+ try {
193+ const sample = readContrastMotion ( ) [ 0 ] ;
194+ return sample ? measuredInMotion ( sample ) : false ;
195+ } finally {
196+ root . kill ( ) ;
197+ }
198+ } ;
199+
200+ it ( "counts as motion while it fades in under still text, and not once it has settled" , ( ) => {
201+ const fade = ( root : RealTimeline ) =>
202+ root . to ( document . getElementById ( "bg" ) ! , { opacity : 1 , duration : 1.5 } , 1 ) ;
203+ expect ( inMotionAt ( 1.1 , fade ) ) . toBe ( true ) ;
204+ expect ( inMotionAt ( 2.9 , fade ) ) . toBe ( false ) ;
205+ } ) ;
206+
207+ it ( "does not count a layer that moves beside the text, not under it" , ( ) => {
208+ const aside = ( root : RealTimeline ) =>
209+ root . to ( document . getElementById ( "aside" ) ! , { x : 50 , duration : 1.5 } , 1 ) ;
210+ expect ( inMotionAt ( 1.1 , aside ) ) . toBe ( false ) ;
211+ } ) ;
212+ } ) ;
213+
214+ describe ( "a sub-composition's timeline" , ( ) => {
215+ afterEach ( ( ) => {
216+ Reflect . deleteProperty ( window , "__timelines" ) ;
217+ Reflect . deleteProperty ( window , "__contrastAuditRestores" ) ;
218+ realGsap . ticker . sleep ( ) ;
219+ } ) ;
220+
221+ it ( "is moving when it is registered paused and seeked with the root, and stopped when its clock is elsewhere" , ( ) => {
222+ const { card, label } = stage ( 1 ) ;
223+ const root = realGsap . timeline ( { paused : true } ) ;
224+ const scene = realGsap . timeline ( { paused : true } ) ;
225+ scene . to ( card , { x : 100 , duration : 1.5 } ) ;
226+ root . add ( scene , 1 ) . to ( { } , { duration : 1 } , 3 ) ;
227+ root . totalTime ( 1.1 , true ) ;
228+ scene . totalTime ( 0.1 , true ) ;
229+ Reflect . set ( window , "__timelines" , { root, scene } ) ;
230+ prepared ( label ) ;
231+ try {
232+ expect ( measuredInMotion ( readContrastMotion ( ) [ 0 ] ! ) ) . toBe ( true ) ;
233+ scene . totalTime ( 0 , true ) ;
234+ expect ( measuredInMotion ( readContrastMotion ( ) [ 0 ] ! ) ) . toBe ( false ) ;
235+ } finally {
236+ root . kill ( ) ;
237+ }
238+ } ) ;
239+ } ) ;
0 commit comments