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.
141 lines
7.5 KiB
JavaScript
141 lines
7.5 KiB
JavaScript
// Table formulas: live recalculation, raw formula editing, Enter and Tab, undo, cycles, saving, the footer layout, and the Read and Split views.
|
|
// @requires plugin:terminal plugin:table-formulas
|
|
import assert from "node:assert/strict";
|
|
import path from "node:path";
|
|
import { mockTauri, outputDir, runSmoke, smokeUrl } from "../_harness/index.mjs";
|
|
import { mockFeaturePlugins } from "../_harness/pluginMocks.mjs";
|
|
|
|
const source = '# Table formulas\n\n| Name | Appearance | Charisma | Combined |\n| --- | ---: | ---: | ---: |\n| First | 9 | 10 | =AVERAGE(B2:C2) |\n| Second | 7 | 9 | =SUM(B3+C3)/2 |\n| Total | | | =SUM(D2:D3) |\n\nAfter.\n';
|
|
|
|
await runSmoke("tables/formulas", async ({ page }) => {
|
|
const output = await outputDir("tables/formulas");
|
|
await mockTauri(page, {
|
|
state: { files: { 'formulas.md': source } },
|
|
commands: test => {
|
|
const workspace = test.workspace({ root: "C:\\smoke-workspace", files: test.state.files, writeEvents: true });
|
|
test.files = workspace.files;
|
|
return workspace;
|
|
},
|
|
});
|
|
await mockFeaturePlugins(page);
|
|
async function quickOpen(name) {
|
|
await page.keyboard.press("Control+p");
|
|
await page.getByRole("textbox", { name: "Find a file" }).fill(name);
|
|
await page.getByRole("dialog").getByRole("button").filter({ hasText: name }).first().click();
|
|
await page.locator('.live-writer').waitFor();
|
|
await page.keyboard.press('Control+e');
|
|
await page.locator(".monaco-editor textarea").waitFor();
|
|
}
|
|
const table = page.locator('.live-writer table');
|
|
const cell = (r, c) => table.locator('tr').nth(r).locator('th, td').nth(c);
|
|
const edit = page.locator('.writer-cell-editor');
|
|
const result = (r, c) => cell(r, c).locator('.md-table-formula');
|
|
const shot = name => page.screenshot({ path: path.join(output, `${name}.png`) });
|
|
async function save() {
|
|
await page.keyboard.press('Control+s');
|
|
await page.waitForFunction(() => !document.querySelector('[aria-label^="Save changes"]'));
|
|
return page.evaluate(() => window.__TEST__.files.get('formulas.md'));
|
|
}
|
|
// Footer controls share one normal-flow block aligned to the table at any width.
|
|
async function checkFooter() {
|
|
const geometry = await page.evaluate(() => {
|
|
const rect = selector => document.querySelector(selector).getBoundingClientRect().toJSON();
|
|
return { table: rect('.live-writer .md-table-scroll'), footer: rect('.table-footer'), tools: rect('.table-formula-tools'), help: rect('.table-edit-help'), helpHidden: document.querySelector('.table-edit-help').hidden, summary: rect('.table-formula-help summary'), status: rect('.table-formula-status') };
|
|
});
|
|
assert.ok(Math.abs(geometry.table.x - geometry.footer.x) < 2);
|
|
assert.ok(Math.abs(geometry.footer.x - geometry.tools.x) < 2);
|
|
if (!geometry.helpHidden) assert.ok(Math.abs(geometry.help.x - geometry.tools.x) < 2);
|
|
assert.ok(geometry.footer.y >= geometry.table.bottom);
|
|
assert.ok(geometry.footer.y - geometry.table.bottom <= 28, 'Only the add-row control sits between table and footer');
|
|
if (!geometry.helpHidden) {
|
|
assert.ok(geometry.tools.y >= geometry.help.bottom, 'Help must not overlap the controls');
|
|
assert.ok(geometry.help.right <= geometry.footer.right + 1);
|
|
}
|
|
if (geometry.status.x > geometry.summary.right) assert.ok(Math.abs((geometry.status.y + geometry.status.height / 2) - (geometry.summary.y + geometry.summary.height / 2)) < 2);
|
|
}
|
|
|
|
await page.goto(smokeUrl);
|
|
await page.getByText('smoke-workspace', { exact: true }).waitFor();
|
|
await quickOpen('formulas.md');
|
|
await page.keyboard.press('Control+e');
|
|
await table.waitFor();
|
|
assert.equal(await result(1, 3).innerText(), '9.5');
|
|
assert.equal(await result(3, 3).innerText(), '17.5');
|
|
await cell(1, 3).hover();
|
|
await page.locator('.rs-tooltip:popover-open').waitFor();
|
|
assert.equal(await cell(1, 3).getAttribute('title'), null);
|
|
assert.match(await page.locator('.rs-tooltip:popover-open').innerText(), /D2.*AVERAGE/);
|
|
await shot('cell-hint');
|
|
await page.keyboard.press('Escape');
|
|
assert.equal(await page.locator('.rs-tooltip:popover-open').count(), 0);
|
|
await cell(1, 3).click();
|
|
assert.equal(await page.locator('.table-formula-status').innerText(), 'D2 = 9.5');
|
|
await edit.fill('=AVERAGE(B2+C2)');
|
|
assert.equal(await page.locator('.table-formula-status').innerText(), 'D2 = 19');
|
|
assert.equal(await page.locator('.table-formula-hint').isVisible(), false);
|
|
await edit.fill('=AVERAGE(B2,C2)');
|
|
assert.equal(await page.locator('.table-formula-status').innerText(), 'D2 = 9.5');
|
|
assert.equal(await page.locator('.table-formula-hint').isVisible(), false);
|
|
await edit.fill('=AVERAGE(B2:C2)');
|
|
await page.keyboard.press('Enter');
|
|
await cell(1, 1).click();
|
|
await edit.fill('5');
|
|
assert.equal(await result(1, 3).innerText(), '7.5');
|
|
assert.equal(await result(3, 3).innerText(), '15.5');
|
|
await page.keyboard.press('Tab');
|
|
await cell(1, 3).click();
|
|
assert.equal(await edit.innerText(), '=AVERAGE(B2:C2)');
|
|
assert.match(await page.locator('.table-formula-status').innerText(), /D2/);
|
|
await edit.fill('=B2*C2');
|
|
await page.keyboard.press('Enter');
|
|
assert.equal(await result(1, 3).innerText(), '50');
|
|
assert.equal(await result(3, 3).innerText(), '58');
|
|
assert.match(await save(), /\| =B2\*C2 \|/);
|
|
await cell(1, 3).click();
|
|
await page.keyboard.press('Control+z');
|
|
await page.waitForFunction(() => document.querySelector('.writer-cell-editor')?.textContent === '=AVERAGE(B2:C2)');
|
|
assert.equal(await result(3, 3).innerText(), '15.5');
|
|
await page.keyboard.press('Control+y');
|
|
await page.waitForFunction(() => document.querySelector('.writer-cell-editor')?.textContent === '=B2*C2');
|
|
assert.equal(await result(3, 3).innerText(), '58');
|
|
await cell(2, 3).click();
|
|
await edit.fill('=D3');
|
|
// Enter would start editing D4 below (src/lib/editor/tableControls.ts:283), so leave the table to render both results.
|
|
await page.keyboard.press('Control+Enter');
|
|
assert.equal(await result(2, 3).innerText(), '#CYCLE!');
|
|
assert.equal(await result(3, 3).innerText(), '#CYCLE!');
|
|
await cell(2, 3).click();
|
|
await edit.fill('=AVERAGE(B3:C3)');
|
|
await page.keyboard.press('Tab');
|
|
await cell(3, 1).click();
|
|
await edit.fill('=SUM(B2:B3)');
|
|
await page.keyboard.press('Enter');
|
|
assert.equal(await result(3, 1).innerText(), '12');
|
|
const saved = await save();
|
|
assert.match(saved, /=SUM\(B2:B3\)/);
|
|
assert.doesNotMatch(saved, /\\=/);
|
|
await cell(3, 1).click();
|
|
await checkFooter();
|
|
await shot('footer');
|
|
await page.setViewportSize({ width: 850, height: 1000 });
|
|
await checkFooter();
|
|
await shot('footer-narrow');
|
|
await page.locator('.table-formula-help summary').click();
|
|
assert.equal(await page.locator('.table-formula-help').getAttribute('open'), '');
|
|
await checkFooter();
|
|
await page.setViewportSize({ width: 1440, height: 1000 });
|
|
await shot('formulas');
|
|
await page.keyboard.press('Control+e');
|
|
await page.keyboard.press('Control+e');
|
|
assert.equal(await result(3, 1).innerText(), '12');
|
|
assert.equal(await result(3, 3).innerText(), '58');
|
|
for (const mode of ['Read', 'Split']) {
|
|
await page.getByRole('group', { name: 'Document view', exact: true }).getByRole('button', { pressed: true }).press('ArrowRight');
|
|
const preview = page.locator('.md-page table').first();
|
|
await preview.waitFor();
|
|
// Enter in the last row added an empty row below Total (src/lib/editor/tableControls.ts:285).
|
|
const total = preview.locator('tbody tr').filter({ hasText: 'Total' });
|
|
assert.equal(await total.locator('.md-table-formula').last().innerText(), '58', `${mode} view`);
|
|
}
|
|
});
|