import { test, expect } from '@playwright/test'; import path from 'node:path'; import { scrollThrough } from '../lib/scroll'; const fx = (n: string) => 'file://' + path.resolve(__dirname, '../fixtures', n); test('scrollThrough: длинный список y проходится до конца', async ({ page }) => { await page.goto(fx('long-list.html')); const r = await scrollThrough(page, '#box', 'y'); expect(r.complete).toBe(true); expect(r.steps).toBeGreaterThanOrEqual(100); // вернулись к началу expect(await page.evaluate(() => document.querySelector('#box')!.scrollTop)).toBeLessThanOrEqual(2); }); test('scrollThrough: ось x', async ({ page }) => { await page.goto(fx('long-list.html')); const r = await scrollThrough(page, '#box', 'x'); expect(r.complete).toBe(true); }); test('scrollThrough: при исчерпании maxSteps complete === false', async ({ page }) => { await page.goto(fx('clipped-list.html')); const r = await scrollThrough(page, '#box', 'y', 200, 10); expect(r.complete).toBe(false); expect(r.steps).toBeLessThanOrEqual(10); });