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.
92 lines
6.7 KiB
JavaScript
92 lines
6.7 KiB
JavaScript
// Writer previews: ordered-list spacing around fenced code, and local, wiki, and table-source links that open document tabs, in both themes at wide and narrow widths.
|
|
import assert from "node:assert/strict";
|
|
import { mockTauri, outputDir, runSmoke, smokeUrl } from "../_harness/index.mjs";
|
|
|
|
await runSmoke("links/previewLinks", async ({ browser, page }) => {
|
|
const output = await outputDir("links/previewLinks");
|
|
// Every load starts without saved tabs or settings.
|
|
await page.addInitScript(() => localStorage.clear());
|
|
// Unknown commands return null, as the original mock did.
|
|
await mockTauri(page, {
|
|
strict: false,
|
|
commands: test => {
|
|
const workspace = test.workspace({ root: "C:\\tab-menu-workspace", folders: ["notes"], files: { "a.md": "# Links\n\nOriginal text.\n" } });
|
|
test.files = workspace.files;
|
|
return {
|
|
...workspace,
|
|
"plugin:window|is_maximized": () => false,
|
|
plugins_snapshot: () => ({ root: "C:/plugins", plugins: [] }),
|
|
spelling_suggestions: () => ({ language: "en-US", words: [], misspelled: false }),
|
|
"plugin:dialog|message": () => "Cancel",
|
|
};
|
|
},
|
|
});
|
|
// The app stays at its own root URL; compare with the normalized form.
|
|
const appUrl = new URL(smokeUrl).href;
|
|
|
|
const installation = '# Installation\n\nOutside the list.\n\n1. Get `RuneStone_<version>_amd64.deb` and its `SHA256SUMS`.\n2. Save both files to Downloads and open Terminal in that folder.\n3. Verify the download, then install the package:\n\n ```bash\n sha256sum --check SHA256SUMS\n sudo apt install ./RuneStone_0.1.42_amd64.deb\n ```\n\n Stop if verification fails.\n4. Open RuneStone from your applications menu.\n5. Open a workspace outside the application folder.\n\nAfter the list.\n';
|
|
async function resetFile(text) {
|
|
await page.locator('.cm-content').evaluate(async (node, text) => {
|
|
const { EditorView } = await import('/node_modules/@codemirror/view/dist/index.js');
|
|
const view = EditorView.findFromDOM(node);
|
|
view.dispatch({ changes: { from: 0, to: view.state.doc.length, insert: text }, selection: { anchor: 0 } });
|
|
}, text);
|
|
}
|
|
for (const theme of ['dark', 'light']) for (const width of [1440, 620]) {
|
|
await page.setViewportSize({ width, height: 1000 });
|
|
await page.goto(smokeUrl);
|
|
await page.locator('[data-tree-rel="a.md"]').click();
|
|
await page.locator('.cm-content').waitFor();
|
|
await page.evaluate(async mode => (await import('/src/lib/theme/appearance.ts')).saveAppearance({ theme:'default', mode }), theme);
|
|
if (width < 1000) {
|
|
await page.getByRole('button', { name:'Files', exact:true }).click();
|
|
await page.getByRole('button', { name:'Hide outline', exact:true }).click();
|
|
}
|
|
await resetFile(installation);
|
|
const preview = page.locator('.writer-preview').filter({ has: page.locator('ol') });
|
|
await preview.waitFor();
|
|
if (theme === 'dark' && width === 1440) {
|
|
await preview.evaluate(element => { element.style.whiteSpace = 'pre-wrap'; });
|
|
const gap = await preview.locator('li').first().evaluate(item => item.querySelector('p').getBoundingClientRect().top - item.getBoundingClientRect().top);
|
|
assert.ok(gap > 15, 'Inherited editor whitespace reproduces the reported blank line');
|
|
await page.screenshot({ path:`${output}/ordered-list-before-dark-1440.png` });
|
|
await preview.evaluate(element => { element.style.removeProperty('white-space'); });
|
|
}
|
|
const metrics = await preview.evaluate(element => {
|
|
const item = element.querySelector('li'), paragraph = item.querySelector('p');
|
|
return { whiteSpace: getComputedStyle(element).whiteSpace, itemTop: item.getBoundingClientRect().top, paragraphTop: paragraph.getBoundingClientRect().top, firstHeight: item.getBoundingClientRect().height, lineHeight: parseFloat(getComputedStyle(paragraph).lineHeight) };
|
|
});
|
|
assert.equal(metrics.whiteSpace, 'normal');
|
|
assert.ok(Math.abs(metrics.paragraphTop - metrics.itemTop) < 2, 'Number and first paragraph share one line');
|
|
assert.ok(metrics.firstHeight < metrics.lineHeight * 3, 'Short list item has no blank formatting lines');
|
|
assert.equal(await preview.locator('li').count(), 5);
|
|
assert.match(await preview.locator('code').last().innerText(), /sha256sum --check SHA256SUMS\n/);
|
|
await page.screenshot({ path:`${output}/ordered-list-${theme}-${width}.png` });
|
|
const fixture = '# Links\n\nOutside.\n\n| Task | Link |\n| --- | --- |\n| Plugin setup | [Plugin installation](<docs/plugins.md#install-a-plugin>) |\n| Wiki | [[docs/plugins.md\\|Plugin guide]] |\n';
|
|
await resetFile(fixture);
|
|
await page.evaluate(() => window.__TEST__.files.set('docs/plugins.md', '# Plugins\n\n## Install a plugin\n\nLocal plugin instructions.\n'));
|
|
const localLink = page.locator('.writer-table a').filter({ hasText:'Plugin installation' });
|
|
await localLink.click({ modifiers:[width === 620 ? 'Meta' : 'Control'] });
|
|
await page.getByRole('tab', { name:'plugins.md', exact:true }).waitFor();
|
|
assert.match(await page.locator('.cm-content').innerText(), /Local plugin instructions/);
|
|
assert.equal(page.url(), appUrl);
|
|
assert.equal(browser.contexts().flatMap(context => context.pages()).length, 1, 'Local link cannot open a browser tab');
|
|
assert.equal(await page.evaluate(() => window.__TEST__.calls.filter(call => /open_url|open_path/.test(call.command)).length), 0);
|
|
await page.screenshot({ path:`${output}/local-link-tab-${theme}-${width}.png` });
|
|
await page.getByRole('tab', { name:'a.md', exact:true }).click();
|
|
const wiki = page.locator('.writer-table a').filter({ hasText:'Plugin guide' });
|
|
await wiki.click({ modifiers:['Control'] });
|
|
await page.getByRole('tab', { name:'plugins.md', exact:true }).waitFor();
|
|
assert.equal(await page.getByRole('tab', { name:'plugins.md', exact:true }).count(), 1, 'Duplicate link focuses its existing document');
|
|
await page.getByRole('tab', { name:'a.md', exact:true }).click();
|
|
await page.locator('.writer-table a').filter({ hasText:'Plugin installation' }).click();
|
|
const source = page.locator('.is-source-editing .writer-cell-editor');
|
|
await source.waitFor();
|
|
await page.screenshot({ path:`${output}/source-link-${theme}-${width}.png` });
|
|
await source.locator('.writer-link-target').click({ modifiers:['Control'] });
|
|
await page.getByRole('tab', { name:'plugins.md', exact:true }).waitFor();
|
|
assert.match(await page.locator('.cm-content').innerText(), /Local plugin instructions/);
|
|
}
|
|
console.log('PASS: nested fenced-code list spacing, preserved code newlines, rendered/table-source/wiki local links open document tabs, duplicate target focus, both themes, narrow and wide windows. Native WebView acceptance remains open.');
|
|
}, { timeout: 15000 });
|