@@ -16,6 +16,7 @@ class TestClock {
1616 private nextHandle = 1 ;
1717 private animationFrames = new Map < number , FrameRequestCallback > ( ) ;
1818 private timeouts = new Map < number , { at : number ; callback : ( ) => void } > ( ) ;
19+
1920 reducedMotion = false ;
2021
2122 readonly env = {
@@ -203,68 +204,43 @@ describe("createPageScrollController", () => {
203204 ) ;
204205 } ) ;
205206
206- test ( "moves a full page without animation frames when motion is reduced" , ( ) => {
207- const clock = new TestClock ( ) ;
208- clock . reducedMotion = true ;
209- const container = {
210- clientHeight : 600 ,
211- scrollHeight : 1_800 ,
212- scrollTop : 0 ,
213- getBoundingClientRect : ( ) => ( { height : 600 } ) ,
214- } ;
215- const controller = createPageScrollController ( {
216- getContainer : ( ) => container ,
217- getScrollPaddingBottomPx : ( ) => 24 ,
218- env : clock . env ,
219- } ) ;
220- const pageDistance = getPageScrollDistancePx ( {
221- containerHeightPx : 600 ,
222- scrollPaddingBottomPx : 24 ,
223- } ) ;
224-
225- controller . handleKeyDown ( "PageDown" ) ;
226-
227- expect ( container . scrollTop ) . toBe ( pageDistance ) ;
228-
229- controller . handleKeyUp ( "PageDown" ) ;
230- clock . advanceBy ( PAGE_SCROLL_ANIMATION_MS ) ;
231-
232- expect ( container . scrollTop ) . toBe ( pageDistance ) ;
233- } ) ;
234-
235- test ( "reads the motion preference on each press" , ( ) => {
207+ test ( "uses the current motion preference for page taps in both directions" , ( ) => {
236208 const clock = new TestClock ( ) ;
237209 const container = {
238210 clientHeight : 600 ,
239211 scrollHeight : 4_000 ,
240- scrollTop : 0 ,
212+ scrollTop : 1_200 ,
241213 getBoundingClientRect : ( ) => ( { height : 600 } ) ,
242214 } ;
243215 const controller = createPageScrollController ( {
244216 getContainer : ( ) => container ,
245217 getScrollPaddingBottomPx : ( ) => 24 ,
246218 env : clock . env ,
247219 } ) ;
248- const pageDistance = getPageScrollDistancePx ( {
249- containerHeightPx : 600 ,
250- scrollPaddingBottomPx : 24 ,
251- } ) ;
252-
253- controller . handleKeyDown ( "PageDown" ) ;
254- controller . handleKeyUp ( "PageDown" ) ;
255- clock . advanceBy ( 16 ) ;
256-
257- expect ( container . scrollTop ) . toBeGreaterThan ( 0 ) ;
258- expect ( container . scrollTop ) . toBeLessThan ( pageDistance ) ;
259-
260- clock . advanceBy ( PAGE_SCROLL_ANIMATION_MS ) ;
261- clock . reducedMotion = true ;
262- controller . handleKeyDown ( "PageDown" ) ;
263220
264- expect ( container . scrollTop ) . toBeCloseTo ( pageDistance * 2 , 5 ) ;
221+ for ( const reducedMotion of [ false , true , false ] ) {
222+ clock . reducedMotion = reducedMotion ;
223+ for ( const [ key , destination ] of [
224+ [ "PageDown" , 1_740 ] ,
225+ [ "PageUp" , 1_200 ] ,
226+ ] as const ) {
227+ const start = container . scrollTop ;
228+ controller . handleKeyDown ( key ) ;
229+ controller . handleKeyUp ( key ) ;
230+
231+ if ( ! reducedMotion ) {
232+ clock . advanceBy ( 16 ) ;
233+ expect ( container . scrollTop ) . toBeGreaterThan ( Math . min ( start , destination ) ) ;
234+ expect ( container . scrollTop ) . toBeLessThan ( Math . max ( start , destination ) ) ;
235+ clock . advanceBy ( PAGE_SCROLL_ANIMATION_MS ) ;
236+ }
237+ expect ( container . scrollTop ) . toBeCloseTo ( destination , 5 ) ;
238+ clock . advanceBy ( PAGE_SCROLL_ANIMATION_MS * 2 ) ;
239+ expect ( container . scrollTop ) . toBeCloseTo ( destination , 5 ) ;
240+ }
241+ }
265242 } ) ;
266243
267- // Holding the key is the user moving the page, so it stays continuous under reduced motion.
268244 test . each ( [ false , true ] ) (
269245 "continues scrolling on hold without repeated keydown events and stops on keyup (reduced motion: %s)" ,
270246 ( reducedMotion ) => {
0 commit comments