Files
RuneStone/tests/smoke/find/pluginViews.smoke.mjs
T
Knotty Wyvern 0fdc991b2e Give way in narrow windows and use one icon for each action
Phase 5-6.

- Side panes give way when the window becomes narrow: the outline
  below 1100 pixels, the side pane below 800 pixels. They come back
  when the window grows. A pane that the user opens in a narrow window
  stays open, and the saved layout keeps the wide-window choice.
- One function has one icon. The SDK icon set gets duplicate, template,
  and tab. The reveal action has one label for each platform (Show in
  Explorer, Show in Finder, Show in file manager).
- The file menu follows one order: open, clipboard, organize, show and
  copy path, history, then Delete and Delete permanently in the error
  color after a separator. The tree copies paths through a Copy path
  submenu, as the tab menu does.
- The tree uses the shared chevron. Search hits come in groups by file,
  with counts and marked matches. Bookmarks show the name, the folder,
  and a remove button.
- All boolean settings use one switch design (src/lib/ui/switch.css).
  Browser settings apply at once, and the Save button is gone. The
  Settings window opens with the focus on its search.
- Targets of at least 24 pixels: the tab close button, outline rows,
  switches, and the settings search.
- Catalog rows in French, Japanese, and Simplified Chinese.
- Docs: UI-052, ui-design.md, and the user guide.

Tests: the new layout/panesAndSettings. Tests that closed or opened
panes by hand around narrow windows now rely on the new behavior, or
wait for the panes to give way before they reopen one. Tests that read
the old menu labels or the browser Save button use the new ones.
2026-10-28 21:31:36 -07:00

163 lines
11 KiB
JavaScript

// Find in plug-in views: privacy attributes, Project Management views, plug-in documents, custom find handlers, focus, both themes, and narrow layouts.
// @requires repo:RuneStone_Project_Management/dist/plugin
import assert from 'node:assert/strict';
import { readFile } from 'node:fs/promises';
import path from 'node:path';
import { mockTauri, outputDir, pluginRepo, runSmoke, smokeUrl } from '../_harness/index.mjs';
await runSmoke('find/pluginViews', async ({ page }) => {
const output = await outputDir('find/pluginViews');
const pmDist = pluginRepo('RuneStone_Project_Management/dist/plugin');
const pm = {
manifest: JSON.parse(await readFile(path.join(pmDist, 'plugin.json'), 'utf8')),
code: await readFile(path.join(pmDist, 'main.js'), 'utf8'),
};
// Unknown commands return null, as the original mock did.
await mockTauri(page, {
strict: false,
state: { pm },
commands: test => {
const workspace = test.workspace({
root: 'C:/find-test',
files: {
'untitled.md': '# Existing note\n',
'sample.finddoc': 'Alpha alpha alphabet',
'Board.md': '---\nrunestone_pm:\n schema: 1\n kind: board\n id: host-find-board\n lists:\n - {id: todo, name: To do, status: todo, collapsed: false}\n - {id: doing, name: In progress, status: doing, collapsed: false}\n - {id: done, name: Done, status: done, collapsed: false}\n defaults: {todo: todo, doing: doing, done: done}\n---\n',
},
});
test.files = workspace.files;
const { pm } = test.state;
const manifest = { schemaVersion: 1, id: 'test.find', name: 'Find test', author: 'Test', description: 'Search checks', version: '1.0.0', apiVersion: 1, entry: 'main.js', access: 'full-app' };
const code = `export function activate(api) {
api.registerDocumentType({ id: 'document', title: 'Test document', extensions: ['finddoc'], identify: path => ({ id: path }), mount(root) {
root.innerHTML = '<section><h2>Test document</h2><p>Alpha alpha alphabet</p><button>Alpha card</button><p hidden>Hidden Alpha</p><button class="focus-return">Details</button></section>';
}});
for (const name of ['Board', 'Changes']) api.registerView({ id: name.toLowerCase(), title: name, placement: 'editor', navigation: true, icon: 'list', mount(root) {
root.innerHTML = '<section><h2>' + name + '</h2><p>Alpha alpha alphabet</p><button>Alpha card</button><p hidden>Hidden Alpha</p><button class="focus-return">Details</button></section>';
}});
api.registerView({ id: 'native', title: 'Custom find', placement: 'editor', navigation: true, find() { window.customFindCalls = (window.customFindCalls || 0) + 1; }, mount(root) { root.innerHTML = '<p>Native content</p>'; } });
}`;
return {
...workspace,
workspace_read: args => {
if (!workspace.files.has(args.rel) && args.missingOk) return null;
return workspace.workspace_read(args);
},
plugins_snapshot: () => ({ root: 'C:/test/plugins', plugins: [manifest, pm.manifest].map(item => ({ manifest: item, hash: item.id, enabled: true, path: 'C:/test/plugins/' + item.id, error: null, removal: false })) }),
plugins_load: args => args.id === pm.manifest.id ? pm.code : code,
plugins_data: () => 'null',
browser_connect: () => 'test',
};
},
});
await page.goto(smokeUrl);
await page.locator('.ws').getByText('find-test', { exact: true }).waitFor();
await page.getByRole('button', { name: 'Plug-in views', exact: true }).waitFor();
const note = page.locator('.tree-tools').getByRole('button', { name: 'New note', exact: true });
assert.equal(await page.locator('.tree-tools').getByRole('button', { name: 'New file', exact: true }).count(), 0);
await note.click();
await page.waitForFunction(() => window.__TEST__.files.has('untitled 2.md'));
await page.getByRole('textbox', { name: 'Writing editor', exact: true }).waitFor();
await page.getByRole('textbox', { name: 'Writing editor', exact: true }).click();
await page.keyboard.press('Control+f');
for (const label of ['Find in document', 'Replace with']) {
assert.equal(await page.getByRole('textbox', { name: label, exact: true }).getAttribute('autocomplete'), 'off');
}
await page.keyboard.press('Escape');
await page.screenshot({ path: `${output}/new-note-dark.png` });
assert.equal(await page.getByRole('dialog').count(), 0, 'The note opens without a filename dialog');
await note.click();
await page.waitForFunction(() => window.__TEST__.files.has('untitled 3.md'));
for (const theme of ['dark', 'light']) {
await page.evaluate(async mode => { const { saveAppearance } = await import('/src/lib/theme/appearance.ts'); saveAppearance({ theme: 'default', mode }); }, theme);
await page.getByRole('tab', { name: 'untitled 3.md', exact: true }).click();
await page.getByRole('textbox', { name: 'Writing editor', exact: true }).click();
await page.keyboard.press('Control+f');
const writerFind = page.getByRole('textbox', { name: 'Find in document', exact: true });
await writerFind.fill('fift');
assert.equal(await writerFind.getAttribute('autocomplete'), 'off');
assert.equal(await page.getByRole('textbox', { name: 'Replace with', exact: true }).getAttribute('autocomplete'), 'off');
await page.screenshot({ path: `${output}/find-privacy-${theme}.png` });
await page.setViewportSize({ width: 650, height: 800 });
await page.screenshot({ path: `${output}/find-privacy-${theme}-narrow.png` });
await page.keyboard.press('Escape');
await page.setViewportSize({ width: 1440, height: 1000 });
await page.mouse.move(900, 400);
await note.hover();
await page.getByRole('tooltip').filter({ hasText: /^New note$/ }).waitFor();
await page.screenshot({ path: `${output}/new-note-tooltip-${theme}.png` });
for (const name of ['Board', 'Changes']) {
await page.getByRole('navigation', { name: 'Plugin shortcuts' }).getByRole('button', { name, exact: true }).click();
const pane = page.getByRole('tabpanel', { name, exact: true });
await pane.getByRole('button', { name: 'Details', exact: true }).focus();
await page.keyboard.press('Control+f');
assert.equal(await pane.locator('.rs-find-bar').count(), 0, 'Non-document plugin views do not show document Find');
await page.screenshot({ path: `${output}/${name}-${theme}.png` });
await page.setViewportSize({ width: 650, height: 800 });
await page.keyboard.press('Control+f');
assert.equal(await pane.locator('.rs-find-bar').count(), 0);
await page.screenshot({ path: `${output}/${name}-${theme}-narrow.png` });
await page.setViewportSize({ width: 1440, height: 1000 });
}
for (const surface of ['all-tasks', 'board-document']) {
if (surface === 'all-tasks') {
await page.getByRole('button', { name: 'Plug-in views', exact: true }).click();
await page.getByRole('menuitem', { name: /^Project Management/ }).click();
} else await page.getByRole('tree', { name: 'Workspace files' }).getByText('Board', { exact: true }).dblclick();
const pane = page.locator('.plugin-editor-pane:visible');
await pane.locator('.pm-board').waitFor();
await pane.focus();
await page.keyboard.press('Control+f');
assert.equal(await pane.locator('.rs-find-bar').count(), 0, 'Actual PM views do not show host Find');
await page.screenshot({ path: `${output}/pm-${surface}-${theme}.png` });
await page.setViewportSize({ width: 650, height: 800 });
await page.keyboard.press('Control+f');
assert.equal(await pane.locator('.rs-find-bar').count(), 0);
await page.screenshot({ path: `${output}/pm-${surface}-${theme}-narrow.png` });
await page.setViewportSize({ width: 1440, height: 1000 });
}
await page.getByRole('tree', { name: 'Workspace files' }).getByText('sample', { exact: true }).dblclick();
for (const name of ['sample']) {
const pane = page.getByRole('tabpanel', { name, exact: true });
const returnButton = pane.getByRole('button', { name: 'Details', exact: true });
await returnButton.focus();
await page.keyboard.press('Control+f');
const find = pane.getByRole('textbox', { name: 'Find in document', exact: true });
assert.equal(await find.getAttribute('autocomplete'), 'off');
await find.fill('Alpha');
assert.equal(await page.locator('.rs-find-bar:visible').count(), 1);
assert.equal(await pane.getByRole('textbox', { name: 'Replace with' }).count(), 0);
await page.keyboard.press('Enter');
assert.equal(await page.evaluate(() => getSelection().toString()), 'Alpha');
await page.keyboard.press('F3');
assert.equal(await page.evaluate(() => getSelection().toString()), 'alpha');
await pane.getByText('Whole word', { exact: true }).click();
await find.focus();
const matches = [];
for (let i = 0; i < 4; i++) {
await page.keyboard.press('Enter');
matches.push(await page.evaluate(() => ({ text: getSelection().toString(), button: !!getSelection().anchorNode?.parentElement?.closest('button') })));
}
assert.equal(matches.filter(match => match.button).length, 1, 'Rendered card buttons participate in search');
assert.ok(matches.every(match => /^alpha$/i.test(match.text)));
await page.screenshot({ path: `${output}/${name}-${theme}.png` });
await page.setViewportSize({ width: 650, height: 800 });
await page.screenshot({ path: `${output}/${name}-${theme}-narrow.png` });
const bar = await pane.locator('.rs-find-bar').boundingBox(), bounds = await pane.boundingBox();
assert.ok(bar.x >= bounds.x && bar.x + bar.width <= bounds.x + bounds.width + 1);
// The side panes give way in a narrow window and come back in a wide one (src/lib/layout/Workbench.svelte).
await page.screenshot({ path: `${output}/${name}-${theme}-narrow-focused.png` });
await find.focus();
await page.keyboard.press('Escape');
assert.equal(await returnButton.evaluate(node => node === document.activeElement), true);
await page.setViewportSize({ width: 1440, height: 1000 });
}
}
await page.getByRole('navigation', { name: 'Plugin shortcuts' }).getByRole('button', { name: 'Custom find', exact: true }).click();
await page.getByRole('tabpanel', { name: 'Custom find' }).focus();
await page.keyboard.press('Control+f');
assert.equal(await page.evaluate(() => window.customFindCalls), 1, 'Plugin find handlers retain ownership');
assert.equal(await page.locator('.rs-find-bar:visible').count(), 0);
console.log('PASS: Find privacy attributes, actual PM All Tasks and board scope, plugin document Find, custom handlers, focus, both themes, and narrow layouts');
});