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); }); test('scrollThrough: контейнер без переполнения - complete === false, reason no_overflow, 0 шагов', async ({ page }) => { await page.goto(fx('no-overflow.html')); for (const axis of ['y', 'x'] as const) { const r = await scrollThrough(page, '#box', axis); expect(r.complete).toBe(false); expect(r.steps).toBe(0); expect(r.reason).toBe('no_overflow'); } }); test('scrollThrough: ось x на длинном по высоте, но не по ширине контейнере - no_overflow', async ({ page }) => { await page.goto(fx('clipped-list.html')); const r = await scrollThrough(page, '#box', 'x'); expect(r.complete).toBe(false); expect(r.reason).toBe('no_overflow'); });