Files
RuneStone/tests/smoke/plugins/choiceMenus.smoke.mjs
T
Knotty Wyvern 69f90df571 Move the smoke tests onto the shared harness
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.
2026-10-27 20:58:55 -07:00

51 lines
3.6 KiB
JavaScript

// Local Autocomplete settings choices use the shared action menu in a modal: keyboard choice, saving, focus return, and cleanup.
// @requires repo:RuneStone_Local_Autocomplete/src
import assert from 'node:assert/strict';
import { readFile } from 'node:fs/promises';
import path from 'node:path';
import { outputDir, pluginRepo, runSmoke, smokeUrl } from '../_harness/index.mjs';
const autocompleteSource = path.join(pluginRepo('RuneStone_Local_Autocomplete'), 'src');
await runSmoke('plugins/choiceMenus', async ({ page }) => {
const output = await outputDir('plugins/choiceMenus');
await page.route('**/__choice-audit__', route => route.fulfill({ contentType: 'text/html', body: '<link rel="stylesheet" href="/src/lib/theme/tokens.css"><link rel="stylesheet" href="/src/lib/ui/menu.css"><style>dialog{inset:0;margin:0;max-width:none;max-height:none;width:100%;height:100%;box-sizing:border-box;background:var(--rs-bg);color:var(--rs-text);padding:0;border:0}</style><dialog><main></main></dialog>' }));
await page.route('**/__autocomplete__/*.mjs', async route => {
const name = new URL(route.request().url()).pathname.split('/').pop();
assert.ok(['main.mjs', 'engine.mjs'].includes(name));
await route.fulfill({ contentType: 'application/javascript', body: await readFile(path.join(autocompleteSource, name), 'utf8') });
});
for (const theme of ['light', 'dark']) for (const width of [1100, 390]) {
await page.setViewportSize({ width, height: 850 });
await page.goto(smokeUrl + '/__choice-audit__');
await page.evaluate(async theme => {
document.documentElement.dataset.theme = theme;
const { showActionMenu } = await import('/src/lib/ui/managedActionMenu.ts');
const { activate } = await import('/__autocomplete__/main.mjs');
let view;
window.choiceAudit = { saved: null };
await activate({ ui: { showActionMenu }, completion: { version: 1, transport() {}, invalidate() {}, registerProvider() { return () => {}; }, registerInput() { return { dispose() {}, request() {} }; } },
settings: { read: async () => ({}), write: async value => { window.choiceAudit.saved = value; } },
onDispose() {}, registerCommand() {}, registerView(value) { view = value; } });
document.querySelector('dialog').showModal();
window.choiceAudit.dispose = view.mount(document.querySelector('main'), { surface: 'settings' });
}, theme);
const trigger = page.getByRole('button', { name: 'Server type', exact: true });
await trigger.click();
const menu = page.getByRole('menu', { name: 'Server type', exact: true });
assert.equal(await menu.evaluate(node => !!node.closest('dialog[open]')), true);
await page.keyboard.press('End');
assert.equal(await page.getByRole('menuitemradio', { name: 'Ollama', exact: true }).evaluate(node => node === document.activeElement), true);
await page.screenshot({ path: path.join(output, `autocomplete-${theme}-${width}.png`) });
await page.keyboard.press('Enter');
assert.match(await trigger.innerText(), /Ollama/);
await page.getByRole('button', { name: 'Save settings', exact: true }).click();
await page.waitForFunction(() => window.choiceAudit.saved?.adapter === 'ollama');
await trigger.click(); await page.keyboard.press('Escape');
assert.equal(await trigger.evaluate(node => node === document.activeElement), true);
await trigger.click(); await page.evaluate(() => window.choiceAudit.dispose());
assert.equal(await page.locator('.rs-menu').count(), 0);
}
console.log('PASS: Local Autocomplete shared choices, modal input, saved adapter, focus return, and cleanup in both themes at 1100/390px.');
}, { timeout: 30000 });