Files
RuneStone/tests/smoke/editor/templatesAndTasks.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

102 lines
5.6 KiB
JavaScript

// Note templates and task lines: template creation, filename focus, task entry, checkbox toggles, lone hyphens, and Setext headings.
import assert from "node:assert/strict";
import { mockTauri, outputDir, runSmoke, smokeUrl } from "../_harness/index.mjs";
await runSmoke("editor/templatesAndTasks", async ({ page }) => {
await mockTauri(page, {
commands: test => {
const workspace = test.workspace({
root: "C:\\smoke-workspace",
files: {
"notes/welcome.md": "---\ntitle: Welcome\n---\n\n# Working notes\n\nFirst paragraph.\n\n- [ ] A task\n\n[[second]]\n",
"notes/second.md": "# Second note\n",
"src/hello.py": "print('hello')\n",
},
writeEvents: true,
});
test.files = workspace.files;
return {
...workspace,
// Saves send the last saved text. Reject a save when the file changed, as the backend does.
workspace_write: args => {
if (args.expected !== undefined && workspace.files.get(args.rel) !== args.expected) throw new Error("Save blocked: file changed on disk");
return workspace.workspace_write(args);
},
// The tree hides the root .runestone folder; its templates folder stays listable.
workspace_list: args => workspace.workspace_list(args).filter(entry => args.rel || entry.rel_path !== ".runestone"),
};
},
});
const output = await outputDir("editor/templatesAndTasks");
await page.goto(smokeUrl);
await page.getByText('smoke-workspace', { exact: true }).waitFor();
// Save the empty task lines from the reported template, then create through
// the normal note action so the filename receives the initial focus.
await page.evaluate(async () => {
const { saveNoteTemplate } = await import('/src/lib/workspace/templates.ts');
await saveNoteTemplate('To Do', '- [ ] \n'.repeat(10));
});
await page.getByRole('button', { name: 'New tab (Ctrl+T)', exact: true }).click();
await page.getByRole('button', { name: 'New note', exact: true }).last().click();
await page.getByRole('menuitem', { name: 'To Do', exact: true }).click();
const title = page.getByRole('textbox', { name: 'Note filename', exact: true });
await title.waitFor();
await page.waitForFunction(() => document.activeElement?.getAttribute('aria-label') === 'Note filename');
await page.evaluate(async () => {
const { EditorView } = await import('/node_modules/@codemirror/view/dist/index.js');
window.__CM__ = EditorView.findFromDOM(document.querySelector('.cm-content'));
});
const count = () => page.locator('.writer-checkbox').count();
const expectCount = async expected => {
await page.waitForFunction(expected => document.querySelectorAll('.writer-checkbox').length === expected, expected);
assert.equal(await count(), expected);
};
const setSource = source => page.evaluate(source => {
window.__CM__.dispatch({ changes: { from: 0, to: window.__CM__.state.doc.length, insert: source }, selection: { anchor: source.length } });
window.__CM__.focus();
}, source);
const plain = 'Some generic mobs or factions,\n-';
for (const mode of ['dark', 'light']) {
await page.evaluate(async mode => (await import('/src/lib/theme/appearance.ts')).saveAppearance({ theme: 'default', mode }), mode);
for (const width of [1440, 600]) {
await page.setViewportSize({ width, height: width === 600 ? 760 : 1000 });
// The side panes give way in a narrow window and come back in a wide one (src/lib/layout/Workbench.svelte).
await page.waitForFunction(width => !!document.querySelector('aside.left') === width >= 800, width);
if (!(await title.isVisible())) await page.getByRole('button', { name: 'Rename note', exact: true }).click();
await title.focus();
await expectCount(10);
await page.screenshot({ path: `${output}/${mode}-${width}-template-title.png` });
await page.keyboard.press('Escape');
await page.evaluate(() => {
const view = window.__CM__;
view.dispatch({ selection: { anchor: 0 } }); view.focus();
});
await expectCount(9);
await page.keyboard.press('End');
await page.keyboard.type('First task');
await expectCount(10);
await page.locator('.writer-checkbox').first().click();
assert.match(await page.evaluate(() => window.__CM__.state.sliceDoc()), /^- \[x\] First task/);
await page.screenshot({ path: `${output}/${mode}-${width}-template-edit.png` });
await setSource(plain);
assert.equal(await page.locator('.writer-h2').count(), 0, 'A lone hyphen must not enlarge preceding prose');
await page.screenshot({ path: `${output}/${mode}-${width}-single-hyphen.png` });
await page.keyboard.type(' Item');
assert.equal(await page.locator('.writer-h2').count(), 0, 'The hyphen continues into a list');
assert.equal(await page.evaluate(() => window.__CM__.state.sliceDoc()), plain + ' Item');
await setSource(plain + '-');
assert.equal(await page.locator('.writer-h2').count(), 1, 'Two hyphens retain Setext heading support');
await setSource('A normal heading\n===\n');
assert.equal(await page.locator('.writer-h1').count(), 1);
// Restore the template for the next theme and size without an active body caret.
await setSource('- [ ] \n'.repeat(10));
await page.getByRole('button', { name: 'Rename note', exact: true }).click();
if (width === 600) {
await page.setViewportSize({ width: 1440, height: 1000 });
}
}
}
console.log('PASS: template creation, filename focus, keyboard task entry, checkbox toggle, lone hyphen, list continuation, and Setext headings in both themes and narrow layouts.');
});