Skip to content

Commit 13d6c8e

Browse files
committed
test for scroll stuff
1 parent eb5d0a7 commit 13d6c8e

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed

special-pages/pages/new-tab/integration-tests/new-tab.page.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,39 @@ export class NewtabPage {
189189
await this.mocks.simulateSubscriptionMessage(sub('tabs_onDataUpdate'), tabs({ tabId, tabIds }));
190190
});
191191
}
192+
193+
/**
194+
* @return {Promise<{y: number}>}
195+
*/
196+
async didScrollToEnd() {
197+
const { page } = this;
198+
return await test.step(`manually setting scroll position to end of element`, async () => {
199+
const y = await page.evaluate(() => {
200+
const scroller = document.querySelector('[data-main-scroller]');
201+
if (!scroller) throw new Error('missing element');
202+
scroller.scrollTop = scroller.scrollHeight - scroller.clientHeight;
203+
return scroller.scrollTop;
204+
});
205+
expect(y).toBeGreaterThan(0);
206+
return { y };
207+
});
208+
}
209+
210+
/**
211+
* @param {object} props
212+
* @param {number} props.y
213+
* @returns {Promise<void>}
214+
*/
215+
async scrollIs({ y }) {
216+
const { page } = this;
217+
await test.step(`fetching the scroll position and comparing to ${y}`, async () => {
218+
await page.waitForFunction(
219+
({ y }) => (document.querySelector('[data-main-scroller]')?.scrollTop ?? 0) === y,
220+
{ y },
221+
{ timeout: 1000 },
222+
);
223+
});
224+
}
192225
}
193226

194227
/**

special-pages/pages/new-tab/integration-tests/new-tab.spec.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,4 +149,27 @@ test.describe('newtab widgets', () => {
149149
await ntp.hasBackgroundColor({ hex: '#000000' });
150150
});
151151
});
152+
153+
test.describe('scroll restoration', () => {
154+
test.use({ viewport: { height: 400, width: 800 } });
155+
test('restores to previous position', async ({ page }, workerInfo) => {
156+
const ntp = NewtabPage.create(page, workerInfo);
157+
await ntp.reducedMotion();
158+
await ntp.openPage({ additional: { tabs: true, 'tabs.debug': true } });
159+
160+
// initial
161+
await ntp.scrollIs({ y: 0 });
162+
163+
// scroll to end
164+
const tab1 = await ntp.didScrollToEnd();
165+
166+
// new tab = should be back to 0 for scroll
167+
await ntp.didSwitchToTab('02', ['01', '02']);
168+
await ntp.scrollIs({ y: 0 });
169+
170+
// now back to original
171+
await ntp.didSwitchToTab('01', ['01', '02']);
172+
await ntp.scrollIs({ y: tab1.y });
173+
});
174+
});
152175
});

0 commit comments

Comments
 (0)