Files
RuneStone/tests/smoke/links/workspaceLinks.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

99 lines
5.6 KiB
JavaScript

// Workspace links: wiki resolution across folders, backlink navigation, live edits, discarded drafts, created, moved, and deleted notes, and the duplicate-name guard.
import assert from "node:assert/strict";
import path from "node:path";
import { mockTauri, outputDir, runSmoke, smokeUrl } from "../_harness/index.mjs";
await runSmoke("links/workspaceLinks", async ({ page }) => {
const output = await outputDir("links/workspaceLinks");
await mockTauri(page, {
commands: test => {
const workspace = test.workspace({
root: "C:\\smoke-workspace",
writeEvents: true,
files: {
"projects/source.md": "# Source\n\n[[Target]]\n",
"archive/deep/Target.md": "# Target\n",
"other.md": "# Other\n\n[Target](archive/deep/Target.md)\n",
},
});
const { files } = workspace;
Object.assign(test, { files, root: workspace.root });
return {
...workspace,
workspace_write: args => {
if (args.expected !== undefined && files.get(args.rel) !== args.expected) throw new Error("Save blocked: file changed on disk");
return workspace.workspace_write(args);
},
workspace_search: () => [],
"plugin:dialog|message": () => test.answer ?? "Cancel",
};
},
});
await page.addInitScript(() => localStorage.setItem('runestone.settings',JSON.stringify({autosaveEnabled:false})));
async function openNote(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.getByRole('textbox',{name:'Writing editor',exact:true}).waitFor();
}
const backlink=path=>page.getByRole('button',{name:'Open '+path+', line 3',exact:true});
await page.goto(smokeUrl);
await page.getByText('smoke-workspace',{exact:true}).waitFor();
await openNote('projects/source.md');
await page.locator('.cm-content .writer-link').filter({hasText:'Target'}).click({modifiers:['Control']});
await page.getByRole('tab',{name:'Target.md',exact:true}).waitFor();
await backlink('projects/source.md').waitFor();
await backlink('other.md').waitFor();
assert.equal(await page.getByRole('tab',{name:'source.md',exact:true}).count(),1);
await page.screenshot({path:path.join(output, 'workspace-links-dark.png')});
await backlink('projects/source.md').click();
await page.waitForFunction(()=>document.querySelector('.breadcrumb')?.title==='projects/source.md');
const writer=page.getByRole('textbox',{name:'Writing editor',exact:true});
await writer.focus(); await page.keyboard.press('Control+Home'); await page.keyboard.press('Control+a'); await page.keyboard.type('# Source\n\nNo links now.');
await page.getByRole('tab',{name:'Target.md',exact:true}).click();
await page.waitForFunction(()=>!document.querySelector('button[aria-label="Open projects/source.md, line 3"]'));
await backlink('other.md').waitFor();
await page.evaluate(()=>{
window.__TEST__.files.set('duplicates/Target.md','# Another target');
window.__TEST__.emit('workspace-event',{root:window.__TEST__.root,kind:'create',paths:['duplicates/Target.md']});
});
await page.waitForTimeout(350);
await openNote('other.md');
await page.locator('.cm-content .writer-link').filter({hasText:'Target'}).click({modifiers:['Control']});
await page.waitForFunction(()=>document.querySelector('.breadcrumb')?.title==='archive/deep/Target.md');
await page.evaluate(()=>{
window.__TEST__.files.set('wiki.md','# Wiki\n\n[[Target]]\n');
window.__TEST__.emit('workspace-event',{root:window.__TEST__.root,kind:'create',paths:['wiki.md']});
});
await openNote('wiki.md');
await page.locator('.cm-content .writer-link').filter({hasText:'Target'}).click({modifiers:['Control']});
await page.locator('.status').filter({hasText:'More than one note matches Target'}).waitFor();
assert.equal(await page.locator('.breadcrumb').getAttribute('title'),'wiki.md');
await page.evaluate(()=>{
window.__TEST__.files.delete('duplicates/Target.md');
window.__TEST__.emit('workspace-event',{root:window.__TEST__.root,kind:'remove',paths:['duplicates/Target.md']});
});
await page.waitForTimeout(350);
await page.locator('.cm-content .writer-link').filter({hasText:'Target'}).click({modifiers:['Control']});
await page.waitForFunction(()=>document.querySelector('.breadcrumb')?.title==='archive/deep/Target.md');
await backlink('wiki.md').waitFor();
await page.evaluate(()=>{
const {files,emit,root}=window.__TEST__;
files.set('moved/wiki.md',files.get('wiki.md')); files.delete('wiki.md');
emit('workspace-event',{root,kind:'rename',paths:['wiki.md','moved/wiki.md']});
});
await backlink('moved/wiki.md').waitFor();
assert.equal(await backlink('wiki.md').count(),0);
await page.evaluate(()=>{window.__TEST__.answer='Ok';});
await page.getByRole('tab',{name:/^source\.md(?: •)?$/}).click();
await page.keyboard.press('Control+w');
await page.getByRole('tab',{name:/^source\.md(?: •)?$/}).waitFor({state:'detached'});
await page.getByRole('tab',{name:'Target.md',exact:true}).click();
await backlink('projects/source.md').waitFor();
await page.setViewportSize({width:620,height:850});
await page.evaluate(()=>{document.documentElement.dataset.theme='light';});
await page.getByRole('tab',{name:'Target.md',exact:true}).click();
await page.screenshot({path:path.join(output, 'workspace-links-narrow.png')});
console.log('Workspace link integration passed: workspace wiki resolution, new tabs, backlinks navigation, live edits, discarded drafts, creation, move, deletion and duplicate guard.');
});