Move the tests from scripts/ to tests/ by feature
Unit tests go to tests/unit/<area>/, browser smoke tests to tests/smoke/<area>/, and tests against a running desktop app to tests/native/. Files named after dates, work passes, or Kanban cards get feature names, for example editorOctober12 -> editor/footnotes. scripts/ keeps the build, release, and package tools. Plugin repositories import scripts/packagePlugin.mjs, and the Terminal smoke test imports scripts/pluginMocks.mjs, which now re-exports the harness copy. The unit tests get their own type check (tests/tsconfig.json) with Node types. pnpm check runs it after the app check. Add @types/node and fix the three test mocks that it reported.
This commit is contained in:
@@ -0,0 +1,165 @@
|
||||
import { createRequire } from 'node:module';
|
||||
import assert from 'node:assert/strict';
|
||||
import { mkdir } from 'node:fs/promises';
|
||||
const require = createRequire(import.meta.url);
|
||||
const { chromium } = require(process.env.PLAYWRIGHT_MODULE || 'playwright');
|
||||
const browser = await chromium.launch({ headless: true, ...(process.env.CHROME_PATH ? { executablePath: process.env.CHROME_PATH } : {}) });
|
||||
const context = await browser.newContext({ viewport: { width: 1200, height: 850 } });
|
||||
const page = await context.newPage();
|
||||
const errors = [];
|
||||
page.on('pageerror', error => errors.push(error.message));
|
||||
await context.addInitScript(() => {
|
||||
window.isTauri = true;
|
||||
const root = 'C:\\host-todo-test';
|
||||
const files = new Map([['a.md', '# Note\n\nOriginal text.'], ['.runestone/templates/Daily.md', '# Daily\n\n## Tasks'], ['.runestone/marks.json', JSON.stringify({ pins: ['a.md'], bookmarks: ['a.md'], order: { '': ['a.md'] } })]]);
|
||||
const state = { files, calls: [], exportResult: 'C:\\exports\\my-theme.json', exportError: '' };
|
||||
window.__HOST_TEST__ = state;
|
||||
let sequence = 0;
|
||||
window.__TAURI_INTERNALS__ = {
|
||||
metadata: { currentWindow: { label: 'main' }, currentWebview: { label: 'main' } },
|
||||
transformCallback: () => ++sequence, unregisterCallback: () => {},
|
||||
invoke: async (command, args = {}) => {
|
||||
state.calls.push({ command, args });
|
||||
if (command === 'plugins_snapshot') return { root: 'C:/plugins', plugins: [] };
|
||||
if (command === 'workspace_last_path') return root;
|
||||
if (command === 'workspace_open') return { root, name: 'host-todo-test', watch_mode: 'native' };
|
||||
if (command === 'workspace_read') { if (!files.has(args.rel)) throw new Error('Missing file'); return files.get(args.rel); }
|
||||
if (command === 'workspace_list') {
|
||||
const prefix = args.rel ? args.rel + '/' : '';
|
||||
const entries = new Map();
|
||||
for (const path of files.keys()) {
|
||||
if (!path.startsWith(prefix) || (!args.rel && path.startsWith('.runestone/'))) continue;
|
||||
const tail = path.slice(prefix.length), name = tail.split('/')[0];
|
||||
entries.set(name, { name, rel_path: prefix + name, kind: tail.includes('/') ? 'folder' : 'file' });
|
||||
}
|
||||
return [...entries.values()];
|
||||
}
|
||||
if (command === 'workspace_create') { if (files.has(args.rel)) throw new Error('Destination exists'); files.set(args.rel, ''); return; }
|
||||
if (command === 'workspace_write') {
|
||||
if (args.expected !== undefined && files.get(args.rel) !== args.expected) throw new Error('Changed on disk');
|
||||
files.set(args.rel, args.contents); return;
|
||||
}
|
||||
if (command === 'workspace_rename') {
|
||||
if (files.has(args.to)) throw new Error('Destination exists');
|
||||
if (!files.has(args.from)) throw new Error('Missing file');
|
||||
files.set(args.to, files.get(args.from)); files.delete(args.from); return;
|
||||
}
|
||||
if (command === 'workspace_delete') { files.delete(args.rel); return; }
|
||||
if (command === 'workspace_search') return [];
|
||||
if (command === 'plugin:event|listen') return ++sequence;
|
||||
if (command === 'plugin:window|is_maximized') return false;
|
||||
if (command === 'plugin:dialog|message') return 'Ok';
|
||||
if (command === 'theme_export') { if (state.exportError) throw new Error(state.exportError); return state.exportResult; }
|
||||
return null;
|
||||
},
|
||||
};
|
||||
window.__TAURI_EVENT_PLUGIN_INTERNALS__ = { unregisterListener: () => {} };
|
||||
});
|
||||
const origin = process.env.SMOKE_URL || 'http://127.0.0.1:5173';
|
||||
const row = path => page.locator(`[data-tree-rel="${path}"]`);
|
||||
const item = name => page.getByRole('menuitem', { name, exact: true });
|
||||
async function paneMenu() { await page.getByRole('navigation', { name: 'Workspace files' }).click({ button: 'right', position: { x: 90, y: 360 } }); }
|
||||
await mkdir('output/host-todo', { recursive: true });
|
||||
try {
|
||||
await page.goto(origin);
|
||||
await row('a.md').waitFor();
|
||||
await page.getByRole('button', { name: 'New file Ctrl N' }).click();
|
||||
await page.getByRole('textbox', { name: 'New file path relative to the workspace' }).waitFor();
|
||||
await page.mouse.click(5, 700);
|
||||
assert.equal(await page.locator('dialog').count(), 0, 'Outside click dismisses new-file dialog');
|
||||
await page.getByRole('button', { name: 'Find a file Ctrl P' }).click();
|
||||
await page.getByRole('textbox', { name: 'Find a file' }).click();
|
||||
assert.equal(await page.locator('dialog').count(), 1, 'Inside click keeps file search open');
|
||||
await page.mouse.click(5, 700);
|
||||
assert.equal(await page.locator('dialog').count(), 0, 'Outside click dismisses file search');
|
||||
await row('a.md').click({ button: 'right' });
|
||||
assert.equal(await item('Copy path').count(), 0);
|
||||
assert.equal(await item('Copy system path').count(), 1);
|
||||
await item('Rename').click();
|
||||
await page.locator('.tree input').fill('renamed.md');
|
||||
await page.locator('.tree input').press('Enter');
|
||||
await row('renamed.md').waitFor();
|
||||
await row('renamed.md').click({ button: 'right' });
|
||||
assert.equal(await item('Undo rename').count(), 1);
|
||||
await page.keyboard.press('Escape');
|
||||
await row('renamed.md').focus(); await page.keyboard.press('Control+z');
|
||||
await row('a.md').waitFor();
|
||||
assert.deepEqual(await page.evaluate(() => JSON.parse(window.__HOST_TEST__.files.get('.runestone/marks.json')).pins), ['a.md']);
|
||||
await row('a.md').focus(); await page.keyboard.press('Control+y');
|
||||
await row('renamed.md').waitFor();
|
||||
await paneMenu(); await item('New note').hover();
|
||||
await item('Daily').click();
|
||||
await row('Daily.md').waitFor();
|
||||
assert.equal(await page.evaluate(() => window.__HOST_TEST__.files.get('Daily.md')), '# Daily\n\n## Tasks');
|
||||
await paneMenu(); await item('New note').hover(); await item('Manage templates…').click();
|
||||
await page.getByRole('button', { name: 'Rename Daily', exact: true }).click();
|
||||
await page.getByRole('textbox', { name: 'Template name', exact: true }).fill('Weekly');
|
||||
await page.getByRole('button', { name: 'Continue', exact: true }).click();
|
||||
await page.getByRole('button', { name: 'Edit Weekly', exact: true }).waitFor();
|
||||
await page.evaluate(() => window.__HOST_TEST__.files.set('.runestone/templates/Existing.md', '# Keep this template'));
|
||||
await page.getByRole('button', { name: 'Rename Weekly', exact: true }).click();
|
||||
await page.getByRole('textbox', { name: 'Template name', exact: true }).fill('Existing');
|
||||
await page.getByRole('button', { name: 'Continue', exact: true }).click();
|
||||
await page.getByRole('alert').filter({ hasText: 'Destination exists' }).waitFor();
|
||||
assert.equal(await page.evaluate(() => window.__HOST_TEST__.files.get('.runestone/templates/Existing.md')), '# Keep this template');
|
||||
for (const mode of ['light', 'dark']) {
|
||||
await page.evaluate(async mode => { const { saveAppearance } = await import('/src/lib/theme/appearance.ts'); saveAppearance({ theme: 'default', mode }); }, mode);
|
||||
await page.screenshot({ path: `output/host-todo/templates-${mode}.png` });
|
||||
}
|
||||
await page.getByRole('button', { name: 'Edit Weekly', exact: true }).click();
|
||||
await page.getByRole('tab', { name: 'Weekly.md', exact: true }).waitFor();
|
||||
await paneMenu(); await item('New note').hover(); await item('Manage templates…').click();
|
||||
await page.getByRole('button', { name: 'New template', exact: true }).click();
|
||||
await page.getByRole('textbox', { name: 'Template name', exact: true }).fill('Meeting');
|
||||
await page.getByRole('button', { name: 'Continue', exact: true }).click();
|
||||
await page.getByRole('tab', { name: 'Meeting.md', exact: true }).waitFor();
|
||||
assert.equal(await page.evaluate(() => window.__HOST_TEST__.files.get('.runestone/templates/Meeting.md')), '');
|
||||
await paneMenu(); await item('New note').hover(); await item('Manage templates…').click();
|
||||
await page.getByRole('button', { name: 'Delete Weekly', exact: true }).click();
|
||||
await page.getByRole('button', { name: 'Edit Weekly', exact: true }).waitFor({ state: 'detached' });
|
||||
assert.equal(await page.evaluate(() => window.__HOST_TEST__.files.get('Daily.md')), '# Daily\n\n## Tasks', 'Deleting template preserves notes');
|
||||
await page.getByRole('button', { name: 'Close templates', exact: true }).click();
|
||||
await page.evaluate(() => { for (let i = 0; i < 40; i++) window.__HOST_TEST__.files.set(`.runestone/templates/Long template name ${i}.md`, '# Template'); });
|
||||
await page.setViewportSize({ width: 600, height: 600 });
|
||||
await paneMenu(); await item('New note').hover(); await item('Manage templates…').click();
|
||||
assert.ok(await page.locator('dialog .list').evaluate(node => node.scrollHeight > node.clientHeight), 'Long template list scrolls');
|
||||
await page.screenshot({ path: 'output/host-todo/templates-narrow-long.png' });
|
||||
await page.getByRole('button', { name: 'Close templates', exact: true }).click();
|
||||
await page.setViewportSize({ width: 1200, height: 850 });
|
||||
const settings = await context.newPage(); settings.on('pageerror', error => errors.push(error.message));
|
||||
await settings.goto(origin + '/?settingsWindow=true');
|
||||
await settings.getByRole('button', { name: 'Appearance', exact: true }).click();
|
||||
await settings.getByRole('button', { name: 'Export theme template' }).click();
|
||||
await settings.getByRole('status').filter({ hasText: 'Theme saved to' }).waitFor();
|
||||
assert.equal(await settings.evaluate(() => JSON.parse(window.__HOST_TEST__.calls.find(call => call.command === 'theme_export').args.contents).schema), 1);
|
||||
await settings.evaluate(() => window.__HOST_TEST__.exportResult = null);
|
||||
await settings.getByRole('button', { name: 'Export theme template' }).click();
|
||||
await settings.getByText('Export canceled.', { exact: true }).waitFor();
|
||||
await settings.evaluate(() => window.__HOST_TEST__.exportError = 'Disk is full');
|
||||
await settings.getByRole('button', { name: 'Export theme template' }).click();
|
||||
await settings.getByRole('alert').filter({ hasText: 'Disk is full' }).waitFor();
|
||||
await settings.getByRole('button', { name: 'Color theme', exact: true }).click();
|
||||
await settings.getByRole('menuitemradio', { name: 'RuneStone', exact: true }).focus();
|
||||
await settings.keyboard.press('ArrowDown'); await settings.keyboard.press('Enter');
|
||||
assert.equal(await settings.evaluate(() => document.documentElement.dataset.palette), 'claude');
|
||||
assert.equal(await settings.locator('input[type=color]').count(), 0);
|
||||
await page.getByRole('button', { name: 'New tab (Ctrl T)', exact: true }).click();
|
||||
await page.locator('.empty').waitFor();
|
||||
await page.waitForFunction(() => document.documentElement.dataset.palette === 'claude');
|
||||
assert.equal(await page.locator('.empty').evaluate(node => { const reference = document.createElement('span'); reference.style.color = 'var(--rs-bg)'; node.append(reference); const matches = getComputedStyle(node).backgroundColor === getComputedStyle(reference).color; reference.remove(); return matches; }), true);
|
||||
await settings.getByLabel('Background image file', { exact: true }).setInputFiles({ name: 'test.png', mimeType: 'image/png', buffer: Buffer.from('iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8/x8AAwMCAO+jM1sAAAAASUVORK5CYII=', 'base64') });
|
||||
await page.waitForFunction(() => getComputedStyle(document.querySelector('.empty')).backgroundImage.includes('blob:'));
|
||||
await page.reload(); await page.locator('.empty').waitFor();
|
||||
assert.ok(await page.locator('.empty').evaluate(node => getComputedStyle(node).backgroundImage.includes('blob:')), 'Background survives restart');
|
||||
await settings.getByRole('button', { name: 'Remove image', exact: true }).click();
|
||||
await page.waitForFunction(() => getComputedStyle(document.querySelector('.empty')).backgroundImage === 'none');
|
||||
for (const mode of ['light', 'dark']) {
|
||||
await settings.evaluate(async mode => { const { saveAppearance, parseAppearance, APPEARANCE_KEY } = await import('/src/lib/theme/appearance.ts'); saveAppearance({ ...parseAppearance(localStorage.getItem(APPEARANCE_KEY)), theme: 'default', mode }); window.dispatchEvent(new Event('focus')); }, mode);
|
||||
await settings.setViewportSize({ width: 650, height: 760 });
|
||||
await settings.screenshot({ path: `output/host-todo/appearance-${mode}-narrow.png` });
|
||||
}
|
||||
assert.equal(await settings.getByRole('button', { name: 'Reset background', exact: true }).isDisabled(), true);
|
||||
await page.waitForFunction(() => !JSON.parse(localStorage.getItem('runestone.appearance')).newTabBackground);
|
||||
assert.deepEqual(errors, []);
|
||||
console.log('Host To Do: dialog dismissal, rename undo/redo with marks, template creation/rename/edit/delete, theme export success/cancel/error, shared theme menu, background persistence/reset passed.');
|
||||
} finally { await browser.close(); }
|
||||
@@ -0,0 +1,115 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import { createRequire } from 'node:module';
|
||||
import { mkdir } from 'node:fs/promises';
|
||||
const { chromium } = createRequire(import.meta.url)(process.env.PLAYWRIGHT_MODULE || '../browser-runtime/node_modules/playwright');
|
||||
const browser = await chromium.launch({ headless: true, executablePath: process.env.CHROME_PATH || 'C:/Program Files/Google/Chrome/Application/chrome.exe' });
|
||||
const output = '.audit/todo-ui';
|
||||
await mkdir(output, { recursive: true });
|
||||
try {
|
||||
for (const theme of ['light', 'dark']) {
|
||||
const page = await browser.newPage({ viewport: { width: 1100, height: 780 } });
|
||||
const errors = [];
|
||||
page.on('pageerror', error => errors.push(error.message));
|
||||
await page.addInitScript(() => {
|
||||
window.isTauri = true;
|
||||
window.__TAURI_INTERNALS__ = {
|
||||
metadata: { currentWindow: { label: 'main' }, currentWebview: { label: 'main' } }, transformCallback: () => 1, unregisterCallback() {},
|
||||
invoke: async (command, args = {}) => {
|
||||
if (command === 'workspace_last_path') return 'C:/todo-ui';
|
||||
if (command === 'workspace_open') return { root: 'C:/todo-ui', name: 'todo-ui', watch_mode: 'native' };
|
||||
if (command === 'workspace_list') return [{ name: 'sample.md', rel_path: 'sample.md', kind: 'file' }];
|
||||
if (command === 'workspace_read') return '# Selection sample\n\nThe same text color applies to each editor.\n';
|
||||
if (command === 'plugins_snapshot') return { root: 'C:/plugins', plugins: [] };
|
||||
if (command === 'workspace_search') return [];
|
||||
if (command === 'browser_request') {
|
||||
if (args.command === 'frameAck') window.blankAcks = (window.blankAcks || 0) + 1;
|
||||
return window.browserSnapshot;
|
||||
}
|
||||
return null;
|
||||
},
|
||||
};
|
||||
window.__TAURI_EVENT_PLUGIN_INTERNALS__ = { unregisterListener() {} };
|
||||
});
|
||||
await page.goto(process.env.SMOKE_URL || 'http://127.0.0.1:1420');
|
||||
await page.getByText('todo-ui', { exact: true }).waitFor();
|
||||
await page.evaluate(async theme => {
|
||||
const { saveAppearance } = await import('/src/lib/theme/appearance.ts');
|
||||
saveAppearance({ theme: 'default', mode: theme });
|
||||
const { attachTooltip } = await import('/src/lib/ui/tooltip.ts');
|
||||
const cell = document.createElement('button');
|
||||
cell.id = 'tooltip-test'; cell.textContent = 'Formula cell';
|
||||
Object.assign(cell.style, { position: 'fixed', left: '20px', top: '100px', zIndex: '2000' });
|
||||
document.body.append(cell);
|
||||
window.disposeTip = attachTooltip(cell, () => 'B6 · Click to edit · Type = for a formula');
|
||||
}, theme);
|
||||
const target = page.locator('#tooltip-test');
|
||||
await target.hover();
|
||||
const tooltip = page.locator('.rs-tooltip:popover-open');
|
||||
await tooltip.waitFor();
|
||||
assert.equal(await target.getAttribute('title'), null);
|
||||
assert.equal(await tooltip.evaluate(node => getComputedStyle(node).borderRadius), '5px');
|
||||
await page.screenshot({ path: `${output}/${theme}-tooltip.png` });
|
||||
await page.keyboard.press('Escape');
|
||||
assert.equal(await page.locator('.rs-tooltip:popover-open').count(), 0);
|
||||
await target.focus();
|
||||
await tooltip.waitFor();
|
||||
await page.setViewportSize({ width: 390, height: 620 });
|
||||
await page.locator('header').first().hover();
|
||||
await target.hover();
|
||||
await tooltip.waitFor();
|
||||
const bounds = await tooltip.boundingBox();
|
||||
assert(bounds.x >= 8 && bounds.x + bounds.width <= 382);
|
||||
await page.screenshot({ path: `${output}/${theme}-narrow-tooltip.png` });
|
||||
await page.evaluate(() => { window.disposeTip(); document.getElementById('tooltip-test').remove(); });
|
||||
await page.setViewportSize({ width: 1100, height: 780 });
|
||||
await page.keyboard.press('Control+p');
|
||||
await page.getByRole('textbox', { name: 'Find a file' }).fill('sample.md');
|
||||
await page.getByRole('textbox', { name: 'Find a file' }).press('Enter');
|
||||
const writer = page.getByRole('textbox', { name: 'Writing editor', exact: true });
|
||||
await writer.waitFor(); await writer.click(); await page.keyboard.press('Control+a');
|
||||
const colors = await writer.evaluate(node => {
|
||||
const probe = document.createElement('span'); probe.style.backgroundColor = 'var(--rs-selection)'; node.append(probe);
|
||||
const expected = getComputedStyle(probe).backgroundColor; probe.remove();
|
||||
return { expected, native: getComputedStyle(node, '::selection').backgroundColor,
|
||||
layer: getComputedStyle(document.querySelector('.cm-selectionBackground')).backgroundColor };
|
||||
});
|
||||
assert.equal(colors.native, colors.expected); assert.equal(colors.layer, colors.expected);
|
||||
await page.screenshot({ path: `${output}/${theme}-writer-selection.png` });
|
||||
await page.getByRole('group', { name: 'Document view', exact: true }).hover();
|
||||
await page.getByRole('button', { name: 'Read', exact: true }).click();
|
||||
const reader = page.locator('.reading');
|
||||
await reader.waitFor();
|
||||
assert.equal(await reader.evaluate(node => getComputedStyle(node, '::selection').backgroundColor), colors.expected);
|
||||
await page.evaluate(async () => {
|
||||
const { mount } = await import('/node_modules/svelte/src/index-client.js');
|
||||
const { default: Browser } = await import('/src/lib/browser/Browser.svelte');
|
||||
const client = await import('/src/lib/browser/client.ts');
|
||||
const container = document.createElement('div'); container.id = 'browser-test';
|
||||
Object.assign(container.style, { position: 'fixed', inset: '50px 10px 20px', zIndex: '2000', background: 'linear-gradient(120deg,#945975,#395c72)' });
|
||||
document.body.append(container);
|
||||
window.browserSnapshot = { profiles: [{ id: 'user', name: 'User' }], tabs: [{ id: 'blank', profileId: 'user', url: 'about:blank', title: '', loading: false }], bookmarks: [], settings: {} };
|
||||
client.state.set(window.browserSnapshot);
|
||||
mount(Browser, { target: container, props: { initial: { tabId: 'blank' }, onSessionChange() {}, async newTab() {} } });
|
||||
window.browserClient = client;
|
||||
});
|
||||
const surface = page.locator('#browser-test .surface');
|
||||
await page.locator('#browser-test [data-browser-state="ready"]').waitFor();
|
||||
await page.evaluate(() => window.browserClient.frames.get('blank')({ tabId: 'blank', frameId: 1, width: 10, height: 10, mime: 'image/png', data: 'AA==' }));
|
||||
assert.equal(await surface.evaluate(node => getComputedStyle(node).backgroundColor), 'rgba(0, 0, 0, 0)');
|
||||
assert.equal(await surface.locator('img').count(), 0);
|
||||
assert.equal(await page.evaluate(() => window.blankAcks), 1);
|
||||
await page.screenshot({ path: `${output}/${theme}-blank-browser.png` });
|
||||
await page.evaluate(() => {
|
||||
window.browserSnapshot.tabs[0].url = 'https://example.com/minimal';
|
||||
window.browserClient.state.set({ ...window.browserSnapshot });
|
||||
const canvas = document.createElement('canvas'); canvas.width = 10; canvas.height = 10;
|
||||
const ctx = canvas.getContext('2d'); ctx.fillStyle = 'white'; ctx.fillRect(0, 0, 10, 10);
|
||||
window.browserClient.frames.get('blank')({ tabId: 'blank', frameId: 2, width: 10, height: 10, mime: 'image/png', data: canvas.toDataURL().split(',')[1] });
|
||||
});
|
||||
await surface.locator('img').waitFor();
|
||||
assert.notEqual(await surface.evaluate(node => getComputedStyle(node).backgroundColor), 'rgba(0, 0, 0, 0)');
|
||||
assert.deepEqual(errors, []);
|
||||
await page.close();
|
||||
}
|
||||
console.log('To do UI smoke passed: tooltips, selection, blank browser, light/dark/narrow.');
|
||||
} finally { await browser.close(); }
|
||||
@@ -0,0 +1,162 @@
|
||||
// Run against the host dev server with PLAYWRIGHT_MODULE and CHROME_PATH when needed.
|
||||
import { createRequire } from "node:module";
|
||||
import { readFile, mkdir } from "node:fs/promises";
|
||||
import { resolve } from "node:path";
|
||||
import assert from "node:assert/strict";
|
||||
const { chromium } = createRequire(import.meta.url)(process.env.PLAYWRIGHT_MODULE || "playwright");
|
||||
const browser = await chromium.launch({ headless: true, ...(process.env.CHROME_PATH ? { executablePath: process.env.CHROME_PATH } : {}) });
|
||||
const context = await browser.newContext({ viewport: { width: 1440, height: 1000 } });
|
||||
const page = await context.newPage();
|
||||
page.setDefaultTimeout(15000);
|
||||
const errors = [];
|
||||
page.on("pageerror", error => errors.push(error.message));
|
||||
await page.addInitScript(() => {
|
||||
window.isTauri = true;
|
||||
localStorage.setItem("runestone.settings", JSON.stringify({ autosaveEnabled: false }));
|
||||
const root = "C:\\kanban-root-smoke";
|
||||
const svg = '<svg xmlns="http://www.w3.org/2000/svg" width="100" height="80"><rect width="100" height="80" fill="#639"/></svg>';
|
||||
const files = new Map([
|
||||
["notes/draft.md", "Before.\n\nAfter.\n"],
|
||||
["files/report [Q1] (#1).pdf", "PDF fixture"],
|
||||
["images/diagram (#1).svg", btoa(svg)],
|
||||
]);
|
||||
const calls = [], callbacks = new Map(), listeners = new Map(); let sequence = 0;
|
||||
window.kanbanRootSmoke = { files, calls };
|
||||
window.__TAURI_INTERNALS__ = {
|
||||
metadata: { currentWindow: { label: "main" }, currentWebview: { label: "main" } },
|
||||
transformCallback(callback) { callbacks.set(++sequence, callback); return sequence; },
|
||||
unregisterCallback(id) { callbacks.delete(id); },
|
||||
async invoke(command, args = {}) {
|
||||
calls.push({ command, args });
|
||||
if (command === "plugin:event|listen") { const values = listeners.get(args.event) || []; values.push(args.handler); listeners.set(args.event, values); return args.handler; }
|
||||
if (command === "plugin:event|unlisten" || command === "spelling_menu_install" || command === "spelling_menu_uninstall") return;
|
||||
if (command === "workspace_last_path") return root;
|
||||
if (command === "workspace_open") return { root, name: "kanban-root-smoke", watch_mode: "native" };
|
||||
if (command === "workspace_read") { if (!files.has(args.rel)) throw Error("File missing"); return files.get(args.rel); }
|
||||
if (command === "workspace_read_data_url") return "data:image/svg+xml;base64," + files.get(args.rel);
|
||||
if (command === "workspace_write") {
|
||||
if (args.expected !== undefined && files.get(args.rel) !== args.expected) throw Error("Save conflict");
|
||||
files.set(args.rel, args.contents); return;
|
||||
}
|
||||
if (command === "workspace_list") {
|
||||
const prefix = args.rel ? args.rel + "/" : "", entries = new Map();
|
||||
for (const path of files.keys()) {
|
||||
if (!path.startsWith(prefix) || path.startsWith(".runestone/")) continue;
|
||||
const tail = path.slice(prefix.length), name = tail.split("/")[0];
|
||||
entries.set(name, { name, rel_path: prefix + name, kind: tail.includes("/") ? "folder" : "file" });
|
||||
}
|
||||
return [...entries.values()];
|
||||
}
|
||||
if (command === "workspace_search") return [];
|
||||
if (command === "workspace_recent") return [root];
|
||||
if (command === "plugins_snapshot") return { plugins: [], issues: [] };
|
||||
if (command === "plugin:dialog|message") return "Cancel";
|
||||
if (command.startsWith("plugin:window|") || command === "browser_stop") return;
|
||||
throw Error("Unhandled IPC: " + command);
|
||||
},
|
||||
};
|
||||
window.__TAURI_EVENT_PLUGIN_INTERNALS__ = { unregisterListener() {} };
|
||||
});
|
||||
const row = path => page.locator(`[data-tree-rel="${path}"]`);
|
||||
async function drag(path, target) {
|
||||
const from = await row(path).boundingBox(), to = await page.locator(target).boundingBox();
|
||||
assert.ok(from && to, "The file and editor must be visible");
|
||||
await page.mouse.move(from.x + Math.min(80, from.width / 2), from.y + from.height / 2);
|
||||
await page.mouse.down();
|
||||
await page.mouse.move(to.x + 45, to.y + 12, { steps: 15 });
|
||||
await page.locator(".image-drop-target").waitFor();
|
||||
await page.mouse.up();
|
||||
}
|
||||
async function writerSource() { return page.evaluate(() => window.kanbanWriter.state.doc.toString()); }
|
||||
async function ideSource() {
|
||||
return page.evaluate(async () => {
|
||||
const { monaco } = await import("/src/lib/editor/monacoEnv.ts");
|
||||
return monaco.editor.getEditors().find(editor => editor.getDomNode()?.isConnected)?.getValue();
|
||||
});
|
||||
}
|
||||
try {
|
||||
await page.goto(process.env.SMOKE_URL || "http://127.0.0.1:5173");
|
||||
await row("notes").click(); await row("notes/draft.md").dblclick();
|
||||
await page.locator(".cm-content").waitFor();
|
||||
await page.evaluate(async () => {
|
||||
const { EditorView } = await import("/node_modules/@codemirror/view/dist/index.js");
|
||||
window.kanbanWriter = EditorView.findFromDOM(document.querySelector(".cm-content"));
|
||||
});
|
||||
await row("files").click();
|
||||
const original = await writerSource();
|
||||
await drag("files/report [Q1] (#1).pdf", ".cm-content");
|
||||
await page.waitForFunction(() => window.kanbanWriter.state.doc.toString().includes(".pdf)"));
|
||||
const linked = await writerSource();
|
||||
assert.ok(linked.includes("[report \\[Q1\\] (#1).pdf](../files/report%20%5BQ1%5D%20%28%231%29.pdf)"), linked);
|
||||
assert.ok(!linked.includes(""));
|
||||
await page.evaluate(() => window.kanbanWriter.focus()); await page.keyboard.press("Control+z");
|
||||
assert.equal(await writerSource(), original);
|
||||
await page.keyboard.press("Control+e");
|
||||
await page.locator(".monaco-editor textarea").waitFor();
|
||||
const originalIde = await ideSource();
|
||||
await page.evaluate(async () => {
|
||||
const { monaco } = await import("/src/lib/editor/monacoEnv.ts");
|
||||
const editor = monaco.editor.getEditors().find(editor => editor.getDomNode()?.isConnected);
|
||||
window.kanbanMonaco = editor;
|
||||
});
|
||||
await drag("files/report [Q1] (#1).pdf", ".monaco-editor .view-lines");
|
||||
await page.waitForFunction(() => window.kanbanMonaco.getValue().includes(".pdf)"));
|
||||
assert.ok((await ideSource()).includes("[report \\[Q1\\] (#1).pdf](../files/report%20%5BQ1%5D%20%28%231%29.pdf)"));
|
||||
await page.evaluate(() => window.kanbanMonaco.focus());
|
||||
assert.equal(await page.evaluate(() => window.kanbanMonaco.hasTextFocus()), true);
|
||||
await page.keyboard.press("Control+z");
|
||||
await page.waitForFunction(expected => window.kanbanMonaco.getValue() === expected, originalIde, { timeout: 3000 });
|
||||
assert.equal(await ideSource(), originalIde, "IDE undo restores the exact source");
|
||||
await drag("images/diagram (#1).svg", ".monaco-editor .view-lines");
|
||||
assert.ok((await ideSource()).includes(""));
|
||||
assert.equal(await page.evaluate(() => window.kanbanRootSmoke.calls.filter(call => ["workspace_rename", "workspace_write_bytes"].includes(call.command)).length), 0);
|
||||
console.log("PASS: real FileTree pointer drags insert escaped document links in Writer and IDE, undo restores both, and image drags still embed.");
|
||||
|
||||
// Load current Git source through the host origin without creating a distributable.
|
||||
const gitRoot = process.env.RUNESTONE_GIT_ROOT || resolve("../RuneStone_Git");
|
||||
const sources = new Map(await Promise.all(["view.js", "model.js"].map(async file => [file, await readFile(resolve(gitRoot, "src", file), "utf8")])));
|
||||
await page.route("**/__kanban_git/*", route => route.fulfill({ contentType: "text/javascript", body: sources.get(new URL(route.request().url()).pathname.split("/").pop()) || "" }));
|
||||
const css = await readFile(resolve(gitRoot, "src/style.css"), "utf8");
|
||||
await page.evaluate(async css => {
|
||||
const { mountSidebar } = await import("/__kanban_git/view.js");
|
||||
const container = document.createElement("div"); container.id = "git-smoke"; container.style.cssText = "position:fixed;inset:45px 0 0 0;z-index:1000;background:var(--rs-bg)";
|
||||
document.body.append(container);
|
||||
window.gitGraphOpens = 0;
|
||||
window.disposeGitSmoke = mountSidebar(container, {
|
||||
workspace: {},
|
||||
git: { status: async () => ({ available: true, repository: true, branch: "main", changes: [] }), pull: async () => {}, push: async () => {} },
|
||||
openView: () => window.gitGraphOpens++,
|
||||
}, css, () => {});
|
||||
}, css);
|
||||
const graph = page.locator("#git-smoke").getByRole("button", { name: "Graph", exact: true });
|
||||
for (const theme of ["dark", "light"]) {
|
||||
await page.evaluate(async mode => { const { saveAppearance } = await import("/src/lib/theme/appearance.ts"); saveAppearance({ theme: "default", mode }); }, theme);
|
||||
await graph.waitFor();
|
||||
assert.equal(await graph.locator("svg").count(), 1);
|
||||
assert.equal(await graph.getAttribute("title"), "Graph");
|
||||
assert.equal(await graph.evaluate(node => [...node.childNodes].filter(child => child.nodeType === Node.TEXT_NODE && child.textContent.trim()).length), 0);
|
||||
assert.equal(await graph.locator(":scope > :not(.rs-git-icon):not(.rs-git-tooltip)").count(), 0, "Graph has no visible text label");
|
||||
await page.mouse.move(800, 800); await graph.evaluate(node => node.blur());
|
||||
assert.equal(await graph.locator(".rs-git-tooltip").isVisible(), false);
|
||||
await graph.hover(); await graph.locator(".rs-git-tooltip").waitFor({ state: "visible" });
|
||||
await page.mouse.move(800, 800); await page.keyboard.press("Tab"); await graph.focus();
|
||||
assert.equal(await graph.evaluate(node => node.matches(":focus-visible")), true);
|
||||
await graph.locator(".rs-git-tooltip").waitFor({ state: "visible" });
|
||||
await mkdir(".audit", { recursive: true });
|
||||
await page.screenshot({ path: `.audit/kanban-git-toolbar-${theme}.png` });
|
||||
}
|
||||
await graph.click(); assert.equal(await page.evaluate(() => window.gitGraphOpens), 1);
|
||||
await page.evaluate(() => window.disposeGitSmoke());
|
||||
assert.deepEqual(errors, []);
|
||||
console.log("PASS: current Git Graph toolbar control is icon-only, keeps its accessible name, shows hover and focus tooltips in both themes, and opens Graph.");
|
||||
} catch (error) {
|
||||
await mkdir(".audit", { recursive: true });
|
||||
await page.screenshot({ path: ".audit/kanban-root-failure.png" });
|
||||
console.error(errors); throw error;
|
||||
} finally { await browser.close(); }
|
||||
@@ -0,0 +1,152 @@
|
||||
import { createRequire } from 'node:module';
|
||||
import assert from 'node:assert/strict';
|
||||
import { mkdir } from 'node:fs/promises';
|
||||
const { chromium } = createRequire(import.meta.url)(process.env.PLAYWRIGHT_MODULE || '../node_modules/playwright');
|
||||
const browser = await chromium.launch({ headless: true, ...(process.env.CHROME_PATH ? { executablePath: process.env.CHROME_PATH } : {}) });
|
||||
const context = await browser.newContext({ viewport: { width: 1440, height: 1000 } });
|
||||
await context.addInitScript(() => {
|
||||
window.isTauri = true;
|
||||
const root = 'C:\\kanban-smoke';
|
||||
const files = new Map([['a.md', '# Alpha\n\nTemplate body.\n'], ['b.md', '# Beta\n'], ['folder/keep.md', '# Keep\n'], ['.runestone/config.json', '{}']]);
|
||||
const calls = [], callbacks = new Map(); let id = 0;
|
||||
window.workspaceSmoke = { files, calls, transfer: null };
|
||||
window.__TAURI_INTERNALS__ = {
|
||||
metadata: { currentWindow: { label: 'main' }, currentWebview: { label: 'main' } },
|
||||
transformCallback: callback => { callbacks.set(++id, callback); return id; }, unregisterCallback: id => callbacks.delete(id),
|
||||
invoke: async (command, args = {}) => {
|
||||
calls.push({ command, args });
|
||||
if (command === 'plugin:event|listen') return ++id;
|
||||
if (command === 'plugin:event|unlisten' || command === 'spelling_menu_install' || command === 'spelling_menu_uninstall') return;
|
||||
if (command === 'workspace_last_path') return root;
|
||||
if (command === 'workspace_open') return { root, name: 'kanban-smoke', watch_mode: 'native' };
|
||||
if (command === 'workspace_read') { if (!files.has(args.rel)) throw Error('File missing'); return files.get(args.rel); }
|
||||
if (command === 'workspace_write') {
|
||||
if (args.expected !== undefined && files.get(args.rel) !== args.expected) throw Error('Save conflict');
|
||||
files.set(args.rel, args.contents); return;
|
||||
}
|
||||
if (command === 'workspace_create') { if (files.has(args.rel)) throw Error('Exists'); files.set(args.rel, ''); return; }
|
||||
if (command === 'workspace_list') {
|
||||
const prefix = args.rel ? args.rel + '/' : ''; const entries = new Map();
|
||||
for (const path of files.keys()) {
|
||||
if (!path.startsWith(prefix) || (!args.rel && path.startsWith('.runestone/') && !args.showInternal)) continue;
|
||||
const tail = path.slice(prefix.length), name = tail.split('/')[0];
|
||||
entries.set(name, { name, rel_path: prefix + name, kind: tail.includes('/') ? 'folder' : 'file' });
|
||||
}
|
||||
return [...entries.values()];
|
||||
}
|
||||
if (command === 'workspace_rename') {
|
||||
if (files.has(args.to)) throw Error('Destination exists');
|
||||
const matches = [...files].filter(([path]) => path === args.from || path.startsWith(args.from + '/'));
|
||||
if (!matches.length) throw Error('Source missing');
|
||||
for (const [path, contents] of matches) { files.delete(path); files.set(args.to + path.slice(args.from.length), contents); }
|
||||
return;
|
||||
}
|
||||
if (command === 'workspace_copy') {
|
||||
const path = (args.parent ? args.parent + '/' : '') + args.rel.split('/').pop();
|
||||
if (files.has(path)) throw Error('Destination exists');
|
||||
files.set(path, files.get(args.rel)); return { rel_path: path, name: path.split('/').pop(), kind: 'file' };
|
||||
}
|
||||
if (command === 'workspace_open_window') { window.workspaceSmoke.transfer = args.transfer; return; }
|
||||
if (command === 'workspace_abs_path') return root + '\\' + args.rel;
|
||||
if (command === 'workspace_recent') return [root];
|
||||
if (command === 'workspace_search') return [];
|
||||
if (command === 'plugin:dialog|message') return 'Cancel';
|
||||
if (command === 'plugins_snapshot') return { plugins: [], issues: [] };
|
||||
if (command.startsWith('plugin:window|') || command === 'workspace_open_terminal' || command === 'workspace_open_default') return;
|
||||
if (command === 'browser_stop') return;
|
||||
throw Error('Unhandled IPC: ' + command);
|
||||
},
|
||||
};
|
||||
window.__TAURI_EVENT_PLUGIN_INTERNALS__ = { unregisterListener() {} };
|
||||
});
|
||||
const page = await context.newPage();
|
||||
const errors = [];
|
||||
page.on('pageerror', error => errors.push(error.message));
|
||||
page.setDefaultTimeout(15000);
|
||||
const url = process.env.SMOKE_URL || 'http://127.0.0.1:1420';
|
||||
const row = path => page.locator(`[data-tree-rel="${path}"]`);
|
||||
const menu = label => page.getByRole('menuitem', { name: label, exact: true });
|
||||
try {
|
||||
await page.goto(url);
|
||||
await row('a.md').click();
|
||||
await page.locator('.cm-content').waitFor();
|
||||
await page.locator('.mode-switcher').first().hover();
|
||||
await page.waitForFunction(() => document.querySelector('.mode-switcher')?.classList.contains('expanded'), null, { timeout: 500 });
|
||||
await page.mouse.move(500, 400);
|
||||
await row('a.md').click({ button: 'right' });
|
||||
await menu('Save as template').click();
|
||||
await page.getByRole('textbox', { name: 'Template name' }).fill('Meeting');
|
||||
await page.getByRole('button', { name: 'Continue', exact: true }).click();
|
||||
await page.waitForFunction(() => window.workspaceSmoke.files.has('.runestone/templates/Meeting.md'));
|
||||
await page.getByRole('button', { name: 'New tab (Ctrl T)', exact: true }).click();
|
||||
await page.getByRole('button', { name: 'New note', exact: true }).click();
|
||||
await menu('Meeting').click();
|
||||
await page.getByRole('tab', { name: /Meeting/ }).waitFor();
|
||||
assert.equal(await page.evaluate(() => window.workspaceSmoke.files.get('Meeting.md')), '# Alpha\n\nTemplate body.\n');
|
||||
const before = await page.getByRole('tab', { selected: true }).getAttribute('data-path');
|
||||
await page.keyboard.press('Control+Tab');
|
||||
assert.notEqual(await page.getByRole('tab', { selected: true }).getAttribute('data-path'), before);
|
||||
await page.keyboard.press('Control+Shift+Tab');
|
||||
assert.equal(await page.getByRole('tab', { selected: true }).getAttribute('data-path'), before);
|
||||
await row('b.md').click({ button: 'right' }); await menu('Cut').click();
|
||||
await row('folder').click({ button: 'right' }); await menu('Paste').click();
|
||||
await page.waitForFunction(() => window.workspaceSmoke.files.has('folder/b.md'));
|
||||
await row('folder').click({ button: 'right' }); await menu('Undo file move').click();
|
||||
await page.waitForFunction(() => window.workspaceSmoke.files.has('b.md'));
|
||||
await row('folder').click({ button: 'right' }); await menu('Redo file move').click();
|
||||
await page.waitForFunction(() => window.workspaceSmoke.files.has('folder/b.md'));
|
||||
await row('folder').focus();
|
||||
await page.keyboard.press('Control+z');
|
||||
await page.waitForFunction(() => window.workspaceSmoke.files.has('b.md'));
|
||||
const sourceBox = await row('b.md').boundingBox(), folderBox = await row('folder').boundingBox();
|
||||
await page.mouse.move(sourceBox.x + 50, sourceBox.y + sourceBox.height / 2);
|
||||
await page.mouse.down();
|
||||
await page.mouse.move(folderBox.x + 70, folderBox.y + folderBox.height / 2, { steps: 12 });
|
||||
await page.mouse.up();
|
||||
await page.waitForFunction(() => window.workspaceSmoke.files.has('folder/b.md'));
|
||||
await page.keyboard.press('Control+z');
|
||||
await page.waitForFunction(() => window.workspaceSmoke.files.has('b.md'));
|
||||
await row('folder').click({ button: 'right' }); await menu('Open in terminal').click();
|
||||
assert.ok(await page.evaluate(() => window.workspaceSmoke.calls.some(call => call.command === 'workspace_open_terminal' && call.args.rel === 'folder')));
|
||||
await page.keyboard.press('Control+,');
|
||||
const settingsPage = await context.newPage();
|
||||
await settingsPage.goto(url + '/?settingsWindow=true');
|
||||
await settingsPage.getByRole('switch', { name: 'Show .runestone folder' }).check();
|
||||
await settingsPage.getByRole('button', { name: 'Appearance', exact: true }).click();
|
||||
const theme = { schema: 1, id: 'smoke', name: 'Smoke theme', light: { bg: '#fefefe', text: '#222222', accent: '#334499' }, dark: { bg: '#181820', text: '#eeeeee', accent: '#aabbff' } };
|
||||
await settingsPage.locator('input[type=file][aria-label="Theme JSON file"]').setInputFiles({ name: 'smoke.json', mimeType: 'application/json', buffer: Buffer.from(JSON.stringify(theme)) });
|
||||
await settingsPage.waitForFunction(() => document.documentElement.dataset.palette === 'custom:smoke');
|
||||
assert.equal(await settingsPage.evaluate(() => getComputedStyle(document.documentElement).getPropertyValue('--rs-bg').trim()), '#181820');
|
||||
await settingsPage.getByRole('combobox', { name: 'Appearance', exact: true }).selectOption('light');
|
||||
assert.equal(await settingsPage.evaluate(() => getComputedStyle(document.documentElement).getPropertyValue('--rs-bg').trim()), '#fefefe');
|
||||
await mkdir('.audit', { recursive: true });
|
||||
await settingsPage.screenshot({ path: '.audit/kanban-custom-theme-light.png' });
|
||||
await settingsPage.close();
|
||||
await row('.runestone').waitFor();
|
||||
await page.getByRole('tab', { name: /Meeting/ }).click();
|
||||
const editor = page.locator('.cm-content'); await editor.click(); await page.keyboard.press('Control+End'); await page.keyboard.type('Unsaved transfer');
|
||||
await page.getByRole('tab', { name: /Meeting/ }).click({ button: 'right' });
|
||||
await menu('Open in new window').click();
|
||||
await page.waitForFunction(() => window.workspaceSmoke.transfer);
|
||||
const token = await page.evaluate(() => window.workspaceSmoke.transfer);
|
||||
const target = await context.newPage();
|
||||
target.on('pageerror', error => errors.push(error.message));
|
||||
await target.goto(url + '/?tabTransfer=' + token);
|
||||
await target.getByRole('tab', { name: /Meeting/ }).waitFor();
|
||||
await target.waitForFunction(() => document.querySelector('.cm-content')?.textContent.includes('Unsaved transfer'));
|
||||
await page.getByRole('tab', { name: /Meeting/ }).waitFor({ state: 'detached' });
|
||||
await page.evaluate(() => { window.workspaceSmoke.transfer = null; });
|
||||
const draggedTab = page.getByRole('tab').first();
|
||||
const draggedPath = await draggedTab.getAttribute('data-path');
|
||||
const tabBox = await draggedTab.boundingBox();
|
||||
await page.mouse.move(tabBox.x + tabBox.width / 2, tabBox.y + tabBox.height / 2);
|
||||
await page.mouse.down();
|
||||
await page.mouse.move(1480, 180, { steps: 12 });
|
||||
await page.mouse.up();
|
||||
await page.waitForFunction(() => window.workspaceSmoke.transfer);
|
||||
assert.notEqual(await page.evaluate(() => window.workspaceSmoke.transfer), token);
|
||||
assert.equal(await page.locator(`[role="tab"][data-path="${draggedPath}"]`).count(), 1, 'Keep the source tab until the new window accepts it');
|
||||
assert.equal(errors.length, 0, errors.join('\n'));
|
||||
console.log('PASS: templates, tab shortcuts, move undo/redo, terminal action, internal folder, theme import, and acknowledged unsaved tab transfer');
|
||||
} finally { await browser.close(); }
|
||||
|
||||
Reference in New Issue
Block a user