|
| 1 | +import { test } from 'vitest'; |
| 2 | +import assert from 'node:assert/strict'; |
| 3 | +import { runScrollEdgePasses } from '../scroll-edge-state.ts'; |
| 4 | +import { capture, scrollNode, subtreeFor, windowRoot } from './scroll-edge-state-fixtures.ts'; |
| 5 | +import { settingsHomeTree } from './scroll-edge-state-android-settings-fixture.ts'; |
| 6 | + |
| 7 | +// --------------------------------------------------------------------------- |
| 8 | +// A scroller nested in a scrollable ancestor with the same rect takes its edge hints from that |
| 9 | +// ancestor (#3737): the inner RecyclerView on Android Settings claims hidden content above even at |
| 10 | +// the top, while the outer ScrollView framing the same pixels reports where the content is. |
| 11 | +// --------------------------------------------------------------------------- |
| 12 | + |
| 13 | +test('scroll top edge: the Android Settings list at the top reports no hidden content above', async () => { |
| 14 | + const state = await capture(settingsHomeTree('at-top'), 'top'); |
| 15 | + assert.equal(state.canScroll, false); |
| 16 | +}); |
| 17 | + |
| 18 | +test('scroll top on Android Settings already at the top costs no pass under scoped recapture', async () => { |
| 19 | + // Scoped captures return only the scope root's subtree, as an Android scoped snapshot does. |
| 20 | + const tree = settingsHomeTree('at-top'); |
| 21 | + const outcome = await runScrollEdgePasses({ |
| 22 | + edge: 'top', |
| 23 | + captureState: async (scope) => await capture(subtreeFor(tree, scope), 'top'), |
| 24 | + scroll: async () => { |
| 25 | + throw new Error('scroll top dispatched a gesture at the top'); |
| 26 | + }, |
| 27 | + }); |
| 28 | + assert.equal(outcome.passes, 0); |
| 29 | +}); |
| 30 | + |
| 31 | +test('scroll top edge: a cyclic chain of same-rect scrollables ends the ancestor walk', async () => { |
| 32 | + const rect = { x: 0, y: 100, width: 400, height: 600 }; |
| 33 | + const nodes = [ |
| 34 | + windowRoot(), |
| 35 | + scrollNode(1, { parentIndex: 2, identifier: 'first', hiddenContentAbove: true, rect }), |
| 36 | + scrollNode(2, { parentIndex: 1, identifier: 'second', rect }), |
| 37 | + ]; |
| 38 | + const state = await capture(nodes, 'top'); |
| 39 | + assert.equal(state.scope, 'first'); |
| 40 | + assert.equal(state.canScroll, true); |
| 41 | +}); |
| 42 | + |
| 43 | +test('scroll top edge: the Android Settings list scrolled down still reports hidden content above', async () => { |
| 44 | + const state = await capture(settingsHomeTree('scrolled-down'), 'top'); |
| 45 | + assert.equal(state.canScroll, true); |
| 46 | +}); |
| 47 | + |
| 48 | +test('scroll bottom edge: the Android Settings list at the top still reports hidden content below', async () => { |
| 49 | + const state = await capture(settingsHomeTree('at-top'), 'bottom'); |
| 50 | + assert.equal(state.canScroll, true); |
| 51 | +}); |
| 52 | + |
| 53 | +test('scroll top on Android Settings stops at the top instead of reporting no progress', async () => { |
| 54 | + const frames = [settingsHomeTree('scrolled-down'), settingsHomeTree('at-top')]; |
| 55 | + let scrolls = 0; |
| 56 | + const outcome = await runScrollEdgePasses({ |
| 57 | + edge: 'top', |
| 58 | + captureState: async () => await capture(frames[Math.min(scrolls, frames.length - 1)]!, 'top'), |
| 59 | + scroll: async () => { |
| 60 | + scrolls += 1; |
| 61 | + }, |
| 62 | + }); |
| 63 | + assert.equal(outcome.passes, 1); |
| 64 | +}); |
| 65 | + |
| 66 | +test('scroll top edge: a nested scroller whose rect differs from its scrollable ancestor keeps its own hint', async () => { |
| 67 | + const nodes = [ |
| 68 | + windowRoot(), |
| 69 | + scrollNode(1, { identifier: 'outer', rect: { x: 0, y: 0, width: 400, height: 800 } }), |
| 70 | + scrollNode(2, { |
| 71 | + parentIndex: 1, |
| 72 | + identifier: 'inner', |
| 73 | + hiddenContentAbove: true, |
| 74 | + rect: { x: 0, y: 100, width: 400, height: 600 }, |
| 75 | + }), |
| 76 | + ]; |
| 77 | + const state = await capture(nodes, 'top'); |
| 78 | + assert.equal(state.scope, 'inner'); |
| 79 | + assert.equal(state.canScroll, true); |
| 80 | +}); |
| 81 | + |
| 82 | +test('scroll top edge: a targeted node in a cyclic chain with no scrollable ancestor ends the walk', async () => { |
| 83 | + const nodes = [ |
| 84 | + windowRoot(), |
| 85 | + scrollNode(1, { identifier: 'list', hiddenContentAbove: true }), |
| 86 | + { ...scrollNode(2, { parentIndex: 3 }), type: 'Button', kind: 'button' }, |
| 87 | + { ...scrollNode(3, { parentIndex: 2 }), type: 'Group', kind: 'group' }, |
| 88 | + ]; |
| 89 | + const state = await capture(nodes, 'top', { nodeIndex: 2 }); |
| 90 | + assert.equal(state.scope, 'list'); |
| 91 | + assert.equal(state.canScroll, true); |
| 92 | +}); |
| 93 | + |
| 94 | +test('scroll bottom edge: a same-rect horizontal pager does not stand in for the vertical list on its page', async () => { |
| 95 | + // A horizontal pager reports no vertical edge hints; its page's vertical list carries them. |
| 96 | + const rect = { x: 0, y: 100, width: 400, height: 600 }; |
| 97 | + const nodes = [ |
| 98 | + windowRoot(), |
| 99 | + scrollNode(1, { identifier: 'pager', rect }), |
| 100 | + scrollNode(2, { parentIndex: 1, identifier: 'feed', hiddenContentBelow: true, rect }), |
| 101 | + ]; |
| 102 | + const state = await capture(nodes, 'bottom'); |
| 103 | + assert.equal(state.scope, 'feed'); |
| 104 | + assert.equal(state.canScroll, true); |
| 105 | +}); |
0 commit comments