Each smoke test now uses tests/smoke/_harness/ for Playwright, the Tauri IPC mock, the in-memory workspace, and output folders, instead of its own copy. The tests keep their interactions and assertions. Mock handlers that the app never calls are gone. - Split the four mixed regression scripts into 18 feature tests. - Update tests that broke when the app changed on purpose. Each update cites the app source that shows the new behavior. - Mark two real app defects with @known-issue: the settings window controls are 1px shorter than the main window controls, and plugin tabs cannot be reordered by dragging without a workspace. - Merge three palette unit tests into one table-driven test. - The native tests load Playwright through the harness and read NATIVE_CDP_URL, with their old variable names as fallbacks. - A failed smoke test saves a screenshot and prints the console errors. - The runner runs failed tests once more, alone, and reports a test that then passes as flaky. Result: 89 passed, 1 flaky, 2 known issues, 0 failed. Before, 45 of 78 passed.
100 lines
5.8 KiB
JavaScript
100 lines
5.8 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();
|
|
assert.equal(await page.evaluate(() => window.__TEST__.requests.filter(request => request.command === 'settings').length), 0, 'A choice does not submit the form');
|
|
await trigger('Save browser settings').click();
|
|
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 });
|