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

106 lines
5.8 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 });
if (width === 600) {
await page.getByRole('button', { name: 'Files', exact: true }).click();
await page.getByRole('button', { name: 'Hide outline', exact: true }).click();
}
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 });
await page.getByRole('button', { name: 'Files', exact: true }).click();
await page.getByRole('button', { name: 'Show outline', exact: true }).click();
}
}
}
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.');
});