Files
RuneStone/tests/smoke/editor/properties.smoke.mjs
2026-11-16 04:21:21 -07:00

57 lines
3.2 KiB
JavaScript

// Front matter properties: first open, editing, undo, the saved selection, and both themes.
import assert from "node:assert/strict";
import { chooseView, mockTauri, outputDir, runSmoke, smokeUrl } from "../_harness/index.mjs";
await runSmoke("editor/properties", async ({ page }) => {
await mockTauri(page, {
commands: test => 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",
},
}),
});
const output = await outputDir("editor/properties");
await page.goto(smokeUrl);
await page.getByText("smoke-workspace", { exact: true }).waitFor();
await page.keyboard.press("Control+p");
await page.getByRole("textbox", { name: "Find a file" }).fill("welcome.md");
await page.getByRole("dialog").getByRole("button").filter({ hasText: "welcome.md" }).first().click();
await page.getByRole('textbox', { name: 'Writing editor', exact: true }).waitFor();
await page.locator('.md-properties').waitFor();
await page.evaluate(async () => {
const { EditorView } = await import('/node_modules/@codemirror/view/dist/index.js');
window.__CM__ = EditorView.findFromDOM(document.querySelector('.cm-content'));
});
const original = await page.evaluate(() => window.__CM__.state.sliceDoc());
assert.equal(await page.evaluate(() => window.__CM__.state.selection.main.head), original.indexOf('\n\n') + 1);
await page.locator('.md-properties summary').click();
assert.equal(await page.locator('.md-properties').getAttribute('open'), '');
assert.match(await page.locator('.md-properties pre').textContent(), /title: Welcome/);
for (const mode of ['light', 'dark']) {
await page.evaluate(async mode => {
const { applyAppearance } = await import('/src/lib/theme/appearance.ts');
applyAppearance({ theme: 'default', mode });
}, mode);
await page.setViewportSize({ width: 760, height: 900 });
await page.screenshot({ path: `${output}/properties-${mode}-narrow.png` });
}
await page.evaluate(() => { window.__CM__.dispatch({ selection: { anchor: 11 } }); window.__CM__.focus(); });
assert.equal(await page.locator('.md-properties').count(), 0);
await page.keyboard.type('New ');
assert.match(await page.evaluate(() => window.__CM__.state.sliceDoc()), /title: New Welcome/);
await page.keyboard.press('Control+z');
assert.equal(await page.evaluate(() => window.__CM__.state.sliceDoc()), original);
await page.evaluate(() => window.__CM__.dispatch({ selection: { anchor: window.__CM__.state.doc.length } }));
await page.locator('.md-properties').waitFor();
await page.evaluate(() => { window.__CM__.dispatch({ selection: { anchor: 11 } }); window.__CM__.focus(); });
await chooseView(page, 'Read');
await page.locator('.reading .md-properties').waitFor();
await chooseView(page, 'Write');
await page.getByRole('textbox', { name: 'Writing editor', exact: true }).waitFor();
assert.equal(await page.locator('.writer-preview .md-properties').count(), 0);
console.log('Properties first-open, editing, undo, saved selection, and both themes passed.');
});