Files
RuneStone/tests/smoke/tree/renameUndo.smoke.mjs
T
Knotty Wyvern c271e2bae1 Put the global actions in a bottom bar and the tools in the ribbon
Decision 3 correction and the owner's ribbon direction of 2026-10-28.

- One bar at the bottom of the side pane holds the workspace switcher,
  Help, and Settings, as in Obsidian. The switcher opens the workspace
  list above it. The header has no workspace button.
- While the side pane is closed, the workspace switcher, Help, and
  Settings move to the bottom of the left ribbon, so they stay
  reachable.
- New browser tab, Terminal, Plug-in views, and Commands moved from the
  header to the top of the left ribbon, so the tabs have more room.
  Their menus open at the right of the ribbon. The header keeps Save,
  the outline toggle, and the window controls. A detached tab window
  has no ribbon and keeps these tools in its header.
- Docs: decision 3 and the ribbon tools in UI-050, ui-design.md, and
  the user guide.

Tests: layout/titleBar checks the bottom bar, the ribbon fallback, and
the header buttons. workspace/openAndCreate uses the ribbon switcher in
a narrow window. tree/renameUndo reads the tools in the ribbon.
2026-10-28 23:57:19 -07:00

180 lines
13 KiB
JavaScript

// Tree rename undo and redo keep folders expanded; New note templates, Git plug-in navigation, and detached tab layout isolation.
// @requires repo:RuneStone_Git/dist
import assert from 'node:assert/strict';
import { readFile } from 'node:fs/promises';
import path from 'node:path';
import { mockTauri, openPage, outputDir, pluginRepo, runSmoke, smokeUrl } from '../_harness/index.mjs';
const gitRoot = path.join(pluginRepo('RuneStone_Git'), 'dist');
const git = {
manifest: JSON.parse(await readFile(path.join(gitRoot, 'plugin.json'), 'utf8')),
code: await readFile(path.join(gitRoot, 'main.js'), 'utf8'),
css: (await readFile(path.join(gitRoot, 'style.css'))).toString('base64'),
};
await runSmoke('tree/renameUndo', async ({ browser }) => {
const context = await browser.newContext({ viewport: { width: 1200, height: 850 } });
await mockTauri(context, {
strict: false,
state: git,
commands: test => {
const git = test.state;
const ws = test.workspace({
root: 'C:\\host-todo-test',
files: {
'a.md': '# Note\n\nOriginal text.', 'folder/nested/note.md': '# Nested', 'other/keep.md': '# Keep', '.runestone/templates/Daily.md': '# Daily\n\n## Tasks',
'.runestone/marks.json': JSON.stringify({ pins: ['a.md'], bookmarks: ['a.md'], order: { '': ['a.md'] } }),
},
});
const files = ws.files;
const within = (from, path) => path === from || path.startsWith(from + '/');
test.files = files;
return {
workspace_last_path: ws.workspace_last_path,
workspace_open: ws.workspace_open,
workspace_read: ws.workspace_read,
workspace_list: args => ws.workspace_list(args).filter(entry => args.rel || !entry.rel_path.startsWith('.runestone')),
workspace_create: ({ rel }) => { if (files.has(rel)) throw new Error('Destination exists'); files.set(rel, ''); },
workspace_write: ({ rel, contents, expected }) => {
if (expected !== undefined && files.get(rel) !== expected) throw new Error('Changed on disk');
files.set(rel, contents);
},
workspace_rename: ({ from, to }) => {
if (files.has(to)) throw new Error('Destination exists');
if (![...files.keys()].some(path => within(from, path))) throw new Error('Missing file');
for (const [path, contents] of [...files]) if (within(from, path)) { files.set(to + path.slice(from.length), contents); files.delete(path); }
},
workspace_delete: ({ rel }) => { files.delete(rel); },
workspace_search: () => [],
plugins_snapshot: () => ({ root: 'C:/plugins', plugins: [{ manifest: git.manifest, hash: 'navigation-git', enabled: true, installedAt: 1, path: 'C:/plugins/runestone.git', error: null, removal: false }] }),
plugins_load: () => git.code,
plugins_asset: () => git.css,
plugins_data: () => 'null',
'plugin:window|is_maximized': () => false,
'plugin:dialog|message': () => 'Ok',
};
},
});
const page = await openPage(context, { timeout: 30000 });
const output = await outputDir('tree/renameUndo');
const shot = (target, name) => target.screenshot({ path: path.join(output, name) });
const row = rel => page.locator(`[data-tree-rel="${rel}"]`);
const item = name => page.getByRole('menuitem', { name, exact: true });
const setMode = (target, mode) => target.evaluate(async mode => { const { saveAppearance } = await import('/src/lib/theme/appearance.ts'); saveAppearance({ theme: 'default', mode }); }, mode);
async function paneMenu() { await page.getByRole('navigation', { name: 'Workspace files' }).click({ button: 'right', position: { x: 90, y: 360 } }); }
async function rename(rel, name) {
await row(rel).click({ button: 'right' }); await item('Rename').click();
await page.locator('.tree input').fill(name); await page.locator('.tree input').press('Enter');
}
async function expanded(rel) { assert.equal(await row(rel).getAttribute('aria-expanded'), 'true', `${rel} stays expanded`); }
await page.goto(smokeUrl);
await row('folder').click(); await row('folder/nested').click(); await row('other').click();
await rename('folder/nested/note.md', 'renamed.md'); await row('folder/nested/renamed.md').waitFor();
await row('folder/nested/renamed.md').focus(); await page.keyboard.press('Control+z');
await row('folder/nested/note.md').waitFor();
for (const rel of ['folder', 'folder/nested', 'other']) await expanded(rel);
await page.keyboard.press('Control+y'); await row('folder/nested/renamed.md').waitFor();
for (const rel of ['folder', 'folder/nested', 'other']) await expanded(rel);
await rename('folder', 'renamed-folder'); await row('renamed-folder/nested/renamed.md').waitFor();
await row('renamed-folder').focus(); await page.keyboard.press('Control+z');
await row('folder/nested/renamed.md').waitFor();
for (const rel of ['folder', 'folder/nested', 'other']) await expanded(rel);
await page.keyboard.press('Control+y'); await row('renamed-folder/nested/renamed.md').waitFor();
for (const rel of ['renamed-folder', 'renamed-folder/nested', 'other']) await expanded(rel);
await paneMenu(); assert.equal(await item('Manage templates…').isVisible(), false);
await item('New note').click(); await row('untitled.md').waitFor();
assert.equal(await page.evaluate(() => window.__TEST__.files.get('untitled.md')), '');
await paneMenu(); await item('New note').focus(); await page.keyboard.press('ArrowRight');
await item('Daily').click(); await row('Daily.md').waitFor();
assert.equal(await page.evaluate(() => window.__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: 'Close templates', exact: true }).click();
for (const mode of ['light', 'dark']) {
await setMode(page, mode);
await paneMenu(); await item('New note').focus(); await page.keyboard.press('ArrowRight');
await shot(page, `note-menu-${mode}.png`);
await page.keyboard.press('Escape'); await page.keyboard.press('Escape');
}
await page.setViewportSize({ width: 600, height: 600 });
// The side pane gives way below 800 pixels. The test opens it again.
await page.locator('aside.left').waitFor({ state: 'detached' });
await page.keyboard.press('Control+Backslash');
await page.locator('aside.left').waitFor();
await paneMenu(); await item('New note').focus(); await page.keyboard.press('ArrowRight');
await shot(page, 'note-menu-dark-narrow.png');
assert.ok(await item('Manage templates…').evaluate(node => node.getBoundingClientRect().right <= innerWidth));
await page.keyboard.press('Escape'); await page.keyboard.press('Escape');
await page.setViewportSize({ width: 1200, height: 850 });
await page.evaluate(() => { window.__TEST__.files.delete('.runestone/templates/Daily.md'); window.dispatchEvent(new Event('runestone-templates-changed')); });
await paneMenu(); await item('New note').focus(); await page.keyboard.press('ArrowRight');
assert.equal(await item('Daily').count(), 0);
await item('Manage templates…').click();
await page.getByRole('button', { name: 'Close templates', exact: true }).click();
const creations = await page.evaluate(() => window.__TEST__.calls.filter(call => call.command === 'workspace_create').length);
await paneMenu(); await item('New note').focus(); await page.keyboard.press('Enter');
await page.waitForFunction(count => window.__TEST__.calls.filter(call => call.command === 'workspace_create').length === count + 1, creations);
await page.getByRole('button', { name: 'Source control', exact: true }).waitFor();
assert.equal(await page.locator('.header-left').getByRole('button', { name: 'Source control', exact: true }).count(), 1);
await page.getByRole('button', { name: 'Plug-in views', exact: true }).click();
const graph = page.getByRole('menuitem', { name: /Show Git graph/ });
await graph.waitFor();
assert.equal(await page.getByRole('menuitem', { name: /source control/i }).count(), 0);
const graphIcon = await graph.locator('.action-icon').innerHTML();
const expectedIcon = await page.evaluate(async () => (await import('/src/lib/ui/actionIcons.ts')).actionIcon('git').innerHTML);
assert.equal(graphIcon, expectedIcon, 'The real Git graph command uses the shared Git icon');
await shot(page, 'real-git-command-dark.png');
await page.keyboard.press('Escape');
await page.evaluate(async () => {
const external = await import(performance.getEntriesByType('resource').find(entry => new URL(entry.name).pathname === '/src/lib/plugins/external.ts').name);
external.pluginNavigation.set([{ owner: 'pm-test', id: 'pm', title: 'Project Management', icon: 'kanban', placement: 'editor', toolbar: true }, { owner: 'git-test', id: 'source', title: 'Source control', icon: 'git', placement: 'sidebar', toolbar: true }]);
external.pluginTools.set([{ owner: 'pm-test', id: 'pm', title: 'Project Management', kind: 'view', surface: 'open' }, { owner: 'git-test', id: 'graph', title: 'Graph view', kind: 'command', surface: 'open', icon: 'git' }]);
external.pluginTools.update(items => [...items, { owner: 'runestone.browser', id: 'new-tab', title: 'New browser tab', kind: 'command', surface: 'open' }]);
const registry = await import(performance.getEntriesByType('resource').find(entry => new URL(entry.name).pathname === '/src/lib/plugins/registry.ts').name);
registry.pluginHost.get('browser').newTab = async () => { window.__TEST__.browserOpened = true; };
});
// The app tools are in the left ribbon. Plugin view shortcuts stay out of it in this test (src/lib/layout/PluginRibbon.svelte).
await page.locator('.plugin-ribbon').getByRole('button', { name: 'New browser tab', exact: true }).click();
assert.equal(await page.evaluate(() => window.__TEST__.browserOpened), true);
assert.equal(await page.locator('.plugin-ribbon .ribbon-tools').getByRole('button', { name: 'Project Management', exact: true }).count(), 0);
assert.equal(await page.locator('.header-left').getByRole('button', { name: 'Source control', exact: true }).count(), 1);
assert.equal(await page.locator('.plugin-ribbon .ribbon-tools').getByRole('button', { name: 'Source control', exact: true }).count(), 0);
await page.getByRole('button', { name: 'Plug-in views', exact: true }).click();
assert.equal(await page.getByRole('menuitem', { name: /Project Management/ }).count(), 1);
assert.equal(await page.getByRole('menuitem', { name: /New browser tab/ }).count(), 0);
await page.getByRole('menuitem', { name: /Graph view/ }).waitFor(); await page.keyboard.press('Escape');
for (const mode of ['light', 'dark']) {
await setMode(page, mode);
await page.getByRole('button', { name: 'Plug-in views', exact: true }).click();
await shot(page, `plugin-navigation-${mode}.png`);
await page.keyboard.press('Escape');
}
const token = '00000000-0000-4000-8000-000000000001';
const saved = await page.evaluate(token => {
const layout = JSON.stringify({ leftOpen: true, rightOpen: true, leftWidth: 280, rightWidth: 260, leftView: 'files' });
localStorage.setItem('runestone.workbenchLayout', layout);
void window.__TAURI_INTERNALS__.invoke('tab_transfer_offer', { id: token, root: 'C:\\host-todo-test', payload: JSON.stringify({ buffer: { id: 'moved', relPath: 'a.md', name: 'a.md', kind: 'text', contents: '# Transferred', saved: '# Note', chrome: 'Writing', pinned: true } }) });
return layout;
}, token);
const detached = await openPage(context, { timeout: 30000 });
await detached.goto(`${smokeUrl}/?tabTransfer=${token}`);
await detached.getByRole('tab', { name: /a.md/ }).waitFor();
await detached.getByText('# Transferred', { exact: true }).waitFor();
assert.equal(await detached.locator('.shell.left-open,.shell.right-open').count(), 0);
assert.equal(await detached.getByRole('button', { name: 'Show outline', exact: true }).count(), 0);
assert.equal(await detached.evaluate(() => localStorage.getItem('runestone.workbenchLayout')), saved);
assert.equal(await detached.getByRole('button', { name: 'Files', exact: true }).count(), 0);
await detached.keyboard.press('Control+Backslash');
await detached.keyboard.press('Control+Shift+f');
assert.equal(await detached.locator('aside.left,aside.right,.plugin-ribbon,.gutter-v').count(), 0);
await detached.keyboard.press('Escape');
assert.equal(await detached.evaluate(() => localStorage.getItem('runestone.workbenchLayout')), saved);
for (const mode of ['light', 'dark']) {
await setMode(detached, mode);
await detached.setViewportSize({ width: 650, height: 600 });
await shot(detached, `detached-${mode}-narrow.png`);
}
assert.deepEqual([...page.errors, ...detached.errors], []);
console.log('Host navigation passed: nested file/folder rename undo/redo, expanded folders, blank New note parent, template submenu, plugin navigation dedup, detached layout isolation.');
});