// @ts-check // Lightweight constrained-device regression: the browser's 4 GB profile must // reduce shared batch concurrency before multiple audio/image operations run. const { test, expect } = require('@playwright/test'); test('4 GB browser profile caps shared batch concurrency at two', async ({ page }) => { await page.goto('/', { waitUntil: 'domcontentloaded' }); await page.waitForFunction(() => typeof window.runPool === 'function', null, { timeout: 15_000 }); const maxActive = await page.evaluate(async () => { Object.defineProperty(navigator, 'deviceMemory', { configurable: true, value: 4 }); let active = 0; let max = 0; await window.runPool(Array.from({ length: 8 }, (_, i) => i), async () => { active += 1; max = Math.max(max, active); await new Promise(resolve => setTimeout(resolve, 15)); active -= 1; }, 4); return max; }); expect(maxActive).toBeLessThanOrEqual(2); }); test('large character productions keep the rendered DOM paginated', async ({ page }) => { const characters = Array.from({ length: 250 }, (_, index) => ({ id: 'large-' + index, book: 'Large Smoke Book', name: 'Character ' + index, tags: '', voice: null, sheet: { gender: index % 2 ? 'F' : 'M' }, })); await page.route('**/api/characters*', route => route.fulfill({ json: { characters } })); await page.route('**/api/voices*', route => route.fulfill({ json: [] })); await page.route('**/api/settings*', route => route.fulfill({ json: {} })); await page.goto('/', { waitUntil: 'domcontentloaded' }); await page.waitForFunction(() => typeof window.libraryRenderCharacters === 'function', null, { timeout: 15_000 }); await page.waitForSelector('#lib-chars-list', { state: 'attached', timeout: 15_000 }); await page.waitForSelector('#app-skeleton', { state: 'detached', timeout: 15_000 }); await page.evaluate(() => window.navTo('s-library')); await page.locator('.lib-tab[data-library-view="characters"]').click(); await expect.poll(() => page.locator('#lib-chars-list .lib-char-card').count()).toBeLessThanOrEqual(50); await page.locator('#lib-chars-list .lib-chars-load-more').click(); await expect.poll(() => page.locator('#lib-chars-list .lib-char-card').count()).toBeLessThanOrEqual(100); });