// @ts-check // Conversation Playground "Thinking" switch (all /api routes mocked). const { test, expect } = require('./_guard'); async function boot(page, settings, lang) { /** @type {any[]} */ const patches = []; await page.route('**/api/**', route => route.request().method() === 'GET' ? route.fulfill({ json: {} }) : route.fulfill({ json: { ok: true } })); await page.route('**/api/settings', route => { if (route.request().method() === 'GET') return route.fulfill({ json: settings }); patches.push(route.request().postDataJSON()); return route.fulfill({ json: { ok: true } }); }); await page.route('**/static/dist/main.min.js*', r => r.abort()); if (lang) await page.addInitScript(l => { try { localStorage.setItem('app-lang', l); } catch (e) {} }, lang); await page.goto('/', { waitUntil: 'domcontentloaded' }); await page.waitForFunction(() => typeof window.navTo === 'function', null, { timeout: 15_000 }); await page.waitForSelector('#app-skeleton', { state: 'detached', timeout: 15_000 }); await page.evaluate(() => window.navTo('s-conversation')); return patches; } test('switch is labelled, keyboard operable, 44px, saves the setting', async ({ page }) => { const patches = await boot(page, { conversation_thinking: false }); const sw = page.getByRole('switch', { name: /Thinking/ }); await expect(sw).not.toBeChecked(); await expect(page.locator('#conv-thinking-state')).toHaveText('off'); const box = await page.locator('label.conv-thinking').boundingBox(); expect(box && box.height).toBeGreaterThanOrEqual(44); await sw.focus(); await page.keyboard.press('Space'); await expect(sw).toBeChecked(); await expect(page.locator('#conv-thinking-state')).toHaveText('on'); await expect.poll(() => patches.some(p => p && p.conversation_thinking === true)).toBe(true); }); test('restores saved state', async ({ page }) => { await boot(page, { conversation_thinking: true }); await expect(page.getByRole('switch', { name: /Thinking/ })).toBeChecked(); }); test('help text is linked to the switch (request body is covered by the unit tests; the server reads the setting)', async ({ page }) => { await boot(page, { conversation_thinking: false }); await expect(page.locator('#conv-thinking-switch')).toHaveAttribute('aria-describedby', 'conv-thinking-help'); await expect(page.locator('#conv-thinking-help')).toContainText('faster answers'); }); test('German labels', async ({ page }) => { await boot(page, { conversation_thinking: false }, 'de'); await expect(page.locator('label.conv-thinking')).toContainText('Denken'); await expect(page.locator('#conv-thinking-state')).toHaveText('aus'); });