|
| 1 | +beforeAll(async () => { |
| 2 | + await page.goto('http://localhost:3000/integration/viewport-100-percent') |
| 3 | +}) |
| 4 | + |
| 5 | +describe('scrollMode: if-needed (outside the scrollingElement bounding box)', () => { |
| 6 | + describe('vertical', () => { |
| 7 | + test('completely below the fold', async () => { |
| 8 | + const actual = await page.evaluate(() => { |
| 9 | + window.scrollTo(0, 0) |
| 10 | + return window |
| 11 | + .computeScrollIntoView(document.querySelector('.vertical-scroll .target'), { |
| 12 | + scrollMode: 'if-needed', |
| 13 | + }) |
| 14 | + .map(window.mapActions) |
| 15 | + }) |
| 16 | + expect(actual).toHaveLength(1) |
| 17 | + expect(actual).toMatchSnapshot() |
| 18 | + }) |
| 19 | + |
| 20 | + test('partially below the fold', async () => { |
| 21 | + const actual = await page.evaluate(() => { |
| 22 | + window.scrollTo(0, 50) |
| 23 | + return window |
| 24 | + .computeScrollIntoView(document.querySelector('.vertical-scroll .target'), { |
| 25 | + scrollMode: 'if-needed', |
| 26 | + }) |
| 27 | + .map(window.mapActions) |
| 28 | + }) |
| 29 | + expect(actual).toHaveLength(1) |
| 30 | + expect(actual).toMatchSnapshot() |
| 31 | + }) |
| 32 | + |
| 33 | + test('completely in view', async () => { |
| 34 | + const actual = await page.evaluate(() => { |
| 35 | + window.scrollTo(0, window.innerHeight / 2); |
| 36 | + return window |
| 37 | + .computeScrollIntoView(document.querySelector('.vertical-scroll .target'), { |
| 38 | + scrollMode: 'if-needed', |
| 39 | + }) |
| 40 | + .map(window.mapActions) |
| 41 | + }) |
| 42 | + expect(actual).toHaveLength(0) |
| 43 | + expect(actual).toMatchSnapshot() |
| 44 | + }) |
| 45 | + |
| 46 | + test('partially above the fold', async () => { |
| 47 | + const actual = await page.evaluate(() => { |
| 48 | + window.scrollTo(0, window.innerHeight + 50) |
| 49 | + return window |
| 50 | + .computeScrollIntoView(document.querySelector('.vertical-scroll .target'), { |
| 51 | + scrollMode: 'if-needed', |
| 52 | + }) |
| 53 | + .map(window.mapActions) |
| 54 | + }) |
| 55 | + expect(actual).toHaveLength(1) |
| 56 | + expect(actual).toMatchSnapshot() |
| 57 | + }) |
| 58 | + |
| 59 | + test('completely above the fold', async () => { |
| 60 | + const actual = await page.evaluate(() => { |
| 61 | + window.scrollTo(0, window.innerHeight + 100) |
| 62 | + return window |
| 63 | + .computeScrollIntoView(document.querySelector('.vertical-scroll .target'), { |
| 64 | + scrollMode: 'if-needed', |
| 65 | + }) |
| 66 | + .map(window.mapActions) |
| 67 | + }) |
| 68 | + expect(actual).toHaveLength(1) |
| 69 | + expect(actual).toMatchSnapshot() |
| 70 | + }) |
| 71 | + }) |
| 72 | + |
| 73 | + describe('horizontal', () => { |
| 74 | + test('completely overflowing', async () => { |
| 75 | + const actual = await page.evaluate(() => { |
| 76 | + window.scrollTo(0, 0) |
| 77 | + return window |
| 78 | + .computeScrollIntoView(document.querySelector('.horizontal-scroll .target'), { |
| 79 | + scrollMode: 'if-needed', |
| 80 | + }) |
| 81 | + .map(window.mapActions) |
| 82 | + }) |
| 83 | + expect(actual).toHaveLength(1) |
| 84 | + expect(actual).toMatchSnapshot() |
| 85 | + }) |
| 86 | + |
| 87 | + test('partially overflowing', async () => { |
| 88 | + const actual = await page.evaluate(() => { |
| 89 | + window.scrollTo(50, 0) |
| 90 | + return window |
| 91 | + .computeScrollIntoView(document.querySelector('.horizontal-scroll .target'), { |
| 92 | + scrollMode: 'if-needed', |
| 93 | + }) |
| 94 | + .map(window.mapActions) |
| 95 | + }) |
| 96 | + expect(actual).toHaveLength(1) |
| 97 | + expect(actual).toMatchSnapshot() |
| 98 | + }) |
| 99 | + |
| 100 | + test('completely in view', async () => { |
| 101 | + const actual = await page.evaluate(() => { |
| 102 | + window.scrollTo(window.innerWidth / 2, 0); |
| 103 | + return window |
| 104 | + .computeScrollIntoView(document.querySelector('.horizontal-scroll .target'), { |
| 105 | + scrollMode: 'if-needed', |
| 106 | + }) |
| 107 | + .map(window.mapActions) |
| 108 | + }) |
| 109 | + expect(actual).toHaveLength(0) |
| 110 | + expect(actual).toMatchSnapshot() |
| 111 | + }) |
| 112 | + |
| 113 | + test('partially negative overflowing', async () => { |
| 114 | + const actual = await page.evaluate(() => { |
| 115 | + window.scrollTo(window.innerWidth + 50, 0) |
| 116 | + return window |
| 117 | + .computeScrollIntoView(document.querySelector('.horizontal-scroll .target'), { |
| 118 | + scrollMode: 'if-needed', |
| 119 | + }) |
| 120 | + .map(window.mapActions) |
| 121 | + }) |
| 122 | + expect(actual).toHaveLength(1) |
| 123 | + expect(actual).toMatchSnapshot() |
| 124 | + }) |
| 125 | + |
| 126 | + test('fully negative overflowing', async () => { |
| 127 | + const actual = await page.evaluate(() => { |
| 128 | + window.scrollTo(window.innerWidth + 100, 0) |
| 129 | + return window |
| 130 | + .computeScrollIntoView(document.querySelector('.horizontal-scroll .target'), { |
| 131 | + scrollMode: 'if-needed', |
| 132 | + }) |
| 133 | + .map(window.mapActions) |
| 134 | + }) |
| 135 | + expect(actual).toHaveLength(1) |
| 136 | + expect(actual).toMatchSnapshot() |
| 137 | + }) |
| 138 | + }) |
| 139 | +}) |
0 commit comments