Files
RuneStone/tests/smoke/plugins/lifecycle.smoke.mjs
T
Knotty Wyvern 9cf82503d0 Show one view control and name the file once
Phase 5-3.

- One radio group shows Write, Source, and Read at all times, with an
  icon and a name. Narrow panes show only the icons. The arrow keys
  move the choice, and the group has one Tab stop. The current choice
  gets the selection fill and an accent bar. Hover gets only a fill.
- A Split toggle shows Read beside Write or Source. Each document pane
  keeps a split flag beside its reading flag. Read ends Split.
- Ctrl+Shift+E switches between Read and the editor. Ctrl+E still
  switches between Write and Source.
- "IDE" becomes "Source" in the Chrome type, the tab menu (a View
  submenu), the status bar, the catalog, the tests, and the docs.
- Settings, General, File name title hides the title in Write and
  Read. It is on by default.
- The breadcrumb shows only the folder of the file. The status bar
  shows the view, not the path.
- ModeSwitcher.svelte and its hover test are gone. The new test
  layout/viewModes covers the control.
- The command palette from 5-2 gets its row in docs/menu-surfaces.json.
- The user guide Format table is whole again. The 5-2 edit had put
  the Paragraph and Insert rows under the shortcut table.
- 8 new catalog rows and 10 removed rows, in French, Japanese, and
  Simplified Chinese.
- Docs: UI-049, the user guide, ui-design.md, document-tools.md,
  development.md, and the README feature list.

Tests: the new layout/viewModes, new cases in documentPanes.spec.ts
and settings.spec.ts, and the chooseView harness helper. 21 smoke
tests use the new control. Tests that read the full path from the
breadcrumb now read its tooltip.
2026-10-28 19:45:08 -07:00

186 lines
11 KiB
JavaScript

// Feature lifecycle: the built-in Table formulas setting and the Terminal plug-in turn off, persist, reopen across windows, and uninstall without restoration.
// An old Table Formulas package stays inactive and shows that the feature is built in.
// @requires plugin:terminal
import assert from 'node:assert/strict';
import path from 'node:path';
import { mockTauri, openPage, outputDir, runSmoke, smokeUrl } from '../_harness/index.mjs';
import { mockFeaturePlugins, oldTableFormulasRow } from '../_harness/pluginMocks.mjs';
await runSmoke('plugins/lifecycle', async ({ browser }) => {
const context = await browser.newContext({ viewport: { width: 1440, height: 1000 } });
await context.route('**/__settings-closed', route => route.fulfill({ contentType: 'text/html', body: '<!doctype html><title>Closed settings</title>' }));
const page = await openPage(context);
const settingsPage = await openPage(context);
page.on('console', message => { if (message.type() === 'error' || message.type() === 'warning') console.log(message.type(), message.text()); });
await mockTauri(context, {
commands: test => {
const ws = 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 files = ws.files;
test.files = files;
return {
...ws,
workspace_write: ({ rel, contents, expected }) => {
if (expected !== undefined && files.get(rel) !== expected) throw new Error('Save blocked: file changed on disk');
files.set(rel, contents);
test.emit('workspace-event', { root: ws.root, kind: 'modify', paths: [rel] });
},
settings_open_window: () => null,
pty_profiles: () => [{ id: 'powershell', title: 'PowerShell', kind: 'powershell' }],
pty_open: async ({ id, channel }) => {
const data = new TextEncoder().encode('READY 🪨\r\n\x1b[6n');
// A Terminal plugin that uses api.pty passes a channel and gets raw bytes. Released versions listen for events.
if (channel) setTimeout(() => { channel.onmessage(data.slice(0, 8).buffer); channel.onmessage(data.slice(8).buffer); }, 0);
else {
test.emit('pty-data', { id, data: [...data.slice(0, 8)] });
test.emit('pty-data', { id, data: [...data.slice(8)] });
}
await new Promise(resolve => setTimeout(resolve, 50));
},
pty_write: () => null,
pty_resize: () => null,
pty_close: () => null,
};
},
});
await mockFeaturePlugins(context, [oldTableFormulasRow]);
const output = await outputDir('plugins/lifecycle');
const source = '# Formulas\n\n| A | B |\n| --- | --- |\n| 2 | =A2*3 |\n\nAfter.\n';
const table = page.locator('.live-writer table');
const dialog = settingsPage.getByRole('dialog', { name: 'Settings', exact: true });
const switchFor = name => dialog.getByRole('switch', { name, exact: true });
const ptyCalled = command => window.__TEST__.calls.some(call => call.command === command);
const count = command => page.evaluate(command => window.__TEST__.calls.filter(call => call.command === command).length, command);
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();
}
async function settings(category = 'Plug-ins') {
await page.getByRole('button', { name: 'Settings (Ctrl+,)', exact: true }).click();
await settingsPage.goto(smokeUrl + '/?settingsWindow=true');
await dialog.getByRole('button', { name: category, exact: true }).click();
}
// The switch of an old package of a built-in feature stays disabled.
const idle = () => settingsPage.waitForFunction(() => [...document.querySelectorAll('input[role="switch"]')].every(input => !input.disabled || input.id === 'external-runestone.table-formulas'));
async function closeSettings() {
await idle();
await settingsPage.goto(smokeUrl + '/__settings-closed');
await page.bringToFront();
}
try {
await page.goto(smokeUrl);
await page.getByText('smoke-workspace', { exact: true }).waitFor();
await page.evaluate(text => window.__TEST__.files.set('formulas.md', text), source);
await quickOpen('formulas.md');
await table.waitFor();
assert.equal(await table.locator('.md-table-formula').innerText(), '6');
assert(!await page.evaluate(() => window.__TEST__.calls.some(call => call.command === 'plugins_load' && call.args.id === 'runestone.table-formulas')), 'The old Table Formulas package does not load');
await settings('General');
await switchFor('Table formulas').uncheck();
await closeSettings();
await page.waitForFunction(() => !document.querySelector('.md-table-formula'));
assert.equal(await page.evaluate(() => window.__TEST__.settings('general').tableFormulas), false, 'The settings file stores the choice');
assert.match(await table.innerText(), /=A2\*3/);
assert.equal(await page.locator('.table-formula-tools').count(), 0);
await table.locator('td').last().click();
await page.locator('.writer-cell-editor').fill('=A2*4');
await page.keyboard.press('Enter');
await settings('General');
await switchFor('Table formulas').check();
await closeSettings();
await page.waitForFunction(() => document.querySelector('.md-table-formula')?.textContent === '8');
await page.getByRole('radiogroup', { name: 'View', exact: true }).getByRole('radio', { checked: true }).press('End');
const preview = page.locator('.md-page table').first();
await preview.locator('.md-table-formula').waitFor();
await settings('General');
await switchFor('Table formulas').uncheck();
await closeSettings();
await page.waitForFunction(() => !document.querySelector('.md-page .md-table-formula'));
assert.match(await preview.innerText(), /=A2\*4/);
await settings('General');
await switchFor('Table formulas').check();
await closeSettings();
await preview.locator('.md-table-formula').waitFor();
assert.equal(await preview.locator('.md-table-formula').innerText(), '8');
await page.keyboard.press('Control+s');
await page.waitForFunction(() => window.__TEST__.files.get('formulas.md').includes('=A2*4'));
assert(!await page.evaluate(() => window.__TEST__.files.get('formulas.md').includes('>8<')));
await page.getByRole('button', { name: 'Terminal', exact: true }).click();
await page.waitForFunction(ptyCalled, 'pty_open');
await settings();
const oldPackage = dialog.locator('.card').filter({ has: settingsPage.getByRole('switch', { name: 'Table Formulas', exact: true }) });
await oldPackage.getByText('Included with RuneStone', { exact: true }).waitFor();
await oldPackage.getByText(/Table Formulas is now built in\. You can remove this old package\./).waitFor();
assert(await oldPackage.getByRole('switch').isDisabled(), 'The old package cannot be enabled');
await switchFor('Terminal').uncheck();
await page.waitForFunction(ptyCalled, 'pty_close');
await settingsPage.screenshot({ path: path.join(output, 'plugins-settings.png') });
await closeSettings();
assert.equal(await page.getByRole('button', { name: 'Terminal', exact: true }).count(), 0);
const opened = await count('pty_open');
await page.keyboard.press('Control+j');
assert.equal(await count('pty_open'), opened);
await page.reload();
await page.getByText('smoke-workspace', { exact: true }).waitFor();
assert.equal(await page.getByRole('button', { name: 'Terminal', exact: true }).count(), 0);
await settings();
assert(!await switchFor('Terminal').isChecked());
const standalone = await openPage(context);
await standalone.goto(smokeUrl + '?terminalWindow=C%3A%5Csmoke-workspace');
await standalone.getByText(/Install and enable the Terminal plugin/).waitFor();
await switchFor('Terminal').check();
await standalone.locator('.xterm').waitFor();
await standalone.waitForFunction(ptyCalled, 'pty_open');
await switchFor('Terminal').uncheck();
await standalone.getByText(/Install and enable the Terminal plugin/).waitFor();
await standalone.waitForFunction(ptyCalled, 'pty_close');
page.errors.push(...standalone.errors);
await standalone.close();
await switchFor('Terminal').check();
await closeSettings();
await page.getByRole('button', { name: 'Terminal', exact: true }).click();
await page.locator('.xterm').waitFor();
await page.evaluate(text => window.__TEST__.files.set('formulas.md', text.replace('=A2*3', '=A2*4')), source);
await page.getByRole('button', { name: 'Terminal', exact: true }).focus();
await quickOpen('formulas.md');
await settings();
assert.equal(await dialog.getByRole('heading', { name: 'Bundled plugins' }).count(), 0);
for (const name of ['Terminal', 'Table Formulas']) {
await idle();
await dialog.locator('.card').filter({ has: settingsPage.getByRole('switch', { name, exact: true }) }).getByRole('button', { name: 'Uninstall', exact: true }).click();
const confirmation = settingsPage.getByRole('dialog', { name: `Uninstall ${name}?`, exact: true });
await confirmation.getByRole('button', { name: 'Uninstall and delete files', exact: true }).click();
await confirmation.waitFor({ state: 'hidden' });
await switchFor(name).waitFor({ state: 'detached' });
}
await closeSettings();
await page.waitForFunction(() => !document.querySelector('.xterm'));
assert.equal(await page.getByRole('button', { name: 'Terminal', exact: true }).count(), 0);
assert.equal(await table.locator('.md-table-formula').innerText(), '8', 'Removing the old package keeps the built-in formulas');
await page.reload();
await page.getByText('smoke-workspace', { exact: true }).waitFor();
await settings();
await dialog.getByText('No plugins installed.', { exact: true }).waitFor();
assert.deepEqual([...page.errors, ...settingsPage.errors], []);
} catch (error) {
await settingsPage.screenshot({ path: path.join(output, 'plugins-settings-failure.png') });
console.log('Settings page:', settingsPage.url(), await settingsPage.locator('body').innerText());
await page.screenshot({ path: path.join(output, 'plugins-failure.png') });
console.log(await page.locator('.md-page').allTextContents());
console.log([...page.errors, ...settingsPage.errors]);
throw error;
}
console.log('Plugin smoke passed: formula setting, source preservation, inactive old package, terminal shutdown, persistence, shortcuts, cross-window enable controls, removal, and no automatic restoration.');
});