RuneStone 1.0.0
This commit is contained in:
@@ -0,0 +1,99 @@
|
||||
// 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);
|
||||
// A changed tab asks Save, Don't save, or Cancel (src/lib/layout/Workbench.svelte).
|
||||
await page.evaluate(()=>{window.__TEST__.answer="Don't save";});
|
||||
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.');
|
||||
});
|
||||
Reference in New Issue
Block a user