Files
RuneStone/tests/smoke/browser/settingsMenus.smoke.mjs
2026-11-16 04:21:21 -07:00

99 lines
5.7 KiB
JavaScript

// Browser settings choice menus: keyboard selection and dismissal, saving, long profile lists, both themes, narrow layout, and cleanup.
import assert from 'node:assert/strict';
import path from 'node:path';
import { mockTauri, outputDir, runSmoke, smokeUrl } from '../_harness/index.mjs';
await runSmoke('browser/settingsMenus', async ({ page }) => {
await mockTauri(page, {
label: 'settings-main',
commands: test => {
const snapshot = {
profiles: [{ id: 'user', name: 'Personal' }, { id: 'work', name: 'Work' }], tabs: [], bookmarks: [],
settings: { search: 'duckduckgo', adblock: true, linkDestination: 'internal', personalRules: '', homepage: '', filterLists: [] },
};
// `requests` records browser requests; `calls` records every IPC command.
Object.assign(test, { snapshot, requests: [] });
return {
browser_connect: () => 'menu-session',
plugins_snapshot: () => ({ root: 'test', plugins: [] }),
'plugin:window|is_maximized': () => false,
browser_request: ({ command, args = {} }) => {
test.requests.push({ command, ...args });
if (command === 'webData') return { profileId: args.profileId, cookies: [], history: [] };
if (command === 'settings') Object.assign(snapshot.settings, args);
return structuredClone(snapshot);
},
};
},
});
const output = await outputDir('browser/settingsMenus');
const shot = name => page.screenshot({ path: path.join(output, name) });
const menu = name => page.getByRole('menu', { name, exact: true });
const trigger = name => page.getByRole('button', { name, exact: true });
await page.goto(smokeUrl + '/?settingsWindow=true');
await trigger('Browser').click();
await trigger('Search engine').waitFor();
for (const mode of ['dark', 'light']) {
await page.evaluate(async mode => { const { saveAppearance } = await import('/src/lib/theme/appearance.ts'); saveAppearance({ theme: 'default', mode }); }, mode);
await trigger('Search engine').focus();
await page.keyboard.press('Enter');
const engines = menu('Search engine');
await engines.waitFor();
assert.equal(await engines.getByRole('menuitemradio', { name: 'DuckDuckGo' }).getAttribute('aria-checked'), 'true');
assert.equal(await engines.evaluate(node => getComputedStyle(node).borderColor), 'rgba(0, 0, 0, 0)');
await shot(`search-${mode}.png`);
await page.keyboard.press('End');
await page.keyboard.press('Space');
assert.equal(await trigger('Search engine').innerText(), 'Bing');
assert.equal(await trigger('Search engine').evaluate(node => node === document.activeElement), true);
await trigger('Search engine').click();
await page.keyboard.press('Home');
await page.keyboard.press('Enter');
await trigger('Profile').focus();
await page.keyboard.press('Space');
await menu('Profile').waitFor();
await shot(`profile-${mode}.png`);
await page.keyboard.press('ArrowDown');
await page.keyboard.press('Enter');
await page.waitForFunction(() => document.querySelector('button[aria-label="Profile"]')?.textContent === 'Work');
await page.waitForFunction(() => window.__TEST__.requests.some(request => request.command === 'webData' && request.profileId === 'work'));
await trigger('Profile').click();
await page.keyboard.press('Home');
await page.keyboard.press('Enter');
await page.setViewportSize({ width: 520, height: 700 });
await trigger('Search engine').click();
const bounds = await engines.boundingBox();
assert.ok(bounds.x >= 8 && bounds.x + bounds.width <= 512);
await shot(`narrow-${mode}.png`);
await page.keyboard.press('Escape');
assert.equal(await trigger('Search engine').evaluate(node => node === document.activeElement), true);
await page.setViewportSize({ width: 1100, height: 850 });
}
await trigger('Search engine').click();
await menu('Search engine').getByRole('menuitemradio', { name: 'Google', exact: true }).click();
// A choice applies at once (src/lib/browser/Settings.svelte).
await page.waitForFunction(() => window.__TEST__.snapshot.settings.search === 'google');
await page.evaluate(async () => { const { state } = await import('/src/lib/browser/client.ts'); const snapshot = window.__TEST__.snapshot; snapshot.profiles.push(...Array.from({ length: 60 }, (_, i) => ({ id: 'p' + i, name: 'Profile ' + i }))); state.set(structuredClone(snapshot)); });
await page.setViewportSize({ width: 520, height: 700 });
await trigger('Profile').click();
const profiles = menu('Profile');
assert.equal(await profiles.evaluate(node => node.scrollHeight > node.clientHeight), true, 'Long profile lists scroll');
await page.keyboard.press('End');
assert.equal(await profiles.getByRole('menuitemradio', { name: 'Profile 59', exact: true }).evaluate(node => node === document.activeElement), true);
await shot('profile-long-narrow.png');
await page.keyboard.press('Escape');
assert.equal(await trigger('Profile').evaluate(node => node === document.activeElement), true);
await trigger('Profile').click();
await trigger('Profile').evaluate(node => {
let parent = node.parentElement;
while (parent && parent.scrollHeight <= parent.clientHeight) parent = parent.parentElement;
if (!parent) throw Error('Settings need a scroll area');
parent.scrollTop -= 40;
});
await profiles.waitFor({ state: 'detached' });
await trigger('Search engine').click();
await trigger('General').click();
assert.equal(await page.locator('.rs-menu').count(), 0, 'Leaving Browser closes the menu');
console.log('PASS: browser choices, persistence, keyboard selection and dismissal, long profiles, both themes, narrow layout, and cleanup.');
}, { viewport: { width: 1100, height: 850 }, timeout: 30000 });