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.
116 lines
7.4 KiB
JavaScript
116 lines
7.4 KiB
JavaScript
// Writer text menu on empty and whitespace lines: submenus, disabled actions, links, the file picker, keyboard focus, both themes, a narrow window, and the Source.
|
|
import assert from "node:assert/strict";
|
|
import { chooseView, mockTauri, outputDir, runSmoke, smokeUrl } from "../_harness/index.mjs";
|
|
|
|
await runSmoke("editor/emptyMenu", async ({ page }) => {
|
|
await mockTauri(page, {
|
|
commands: test => 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 output = await outputDir("editor/emptyMenu");
|
|
await page.goto(smokeUrl);
|
|
await page.getByText('smoke-workspace', { exact: true }).waitFor();
|
|
await page.keyboard.press('Control+p');
|
|
await page.getByRole('textbox', { name: 'Find a file' }).fill('welcome.md');
|
|
await page.getByRole('dialog').getByRole('button').filter({ hasText: 'welcome.md' }).first().click();
|
|
await page.getByRole('textbox', { name: 'Writing editor', exact: true }).waitFor();
|
|
await page.evaluate(async () => {
|
|
const { EditorView } = await import('/node_modules/@codemirror/view/dist/index.js');
|
|
window.__CM__ = EditorView.findFromDOM(document.querySelector('.cm-content'));
|
|
});
|
|
const menu = () => page.getByRole('menu', { name: 'Markdown text actions', exact: true });
|
|
async function setSource(value, anchor = 0, head = anchor) {
|
|
await page.evaluate(({value,anchor,head}) => window.__CM__.dispatch({changes:{from:0,to:window.__CM__.state.doc.length,insert:value},selection:{anchor,head}}), {value,anchor,head});
|
|
}
|
|
async function openKeyboard() { await page.locator('.cm-content').focus(); await page.keyboard.press('Shift+F10'); await menu().waitFor(); }
|
|
async function source() { return page.evaluate(() => window.__CM__.state.doc.toString()); }
|
|
for (const theme of ['light', 'dark']) {
|
|
await page.evaluate(async mode => { const { saveAppearance } = await import('/src/lib/theme/appearance.ts'); saveAppearance({theme:'default',mode}); }, theme);
|
|
await setSource('');
|
|
await page.locator('.cm-line').first().click({button:'right'});
|
|
await menu().waitFor();
|
|
for (const label of ['Add link','Add external link Ctrl+K','Format','Paragraph','Insert','Paste Ctrl+V','Paste as plain text','Select all Ctrl+A']) assert.equal(await menu().getByRole('menuitem', {name:label,exact:true}).count(),1,label);
|
|
assert.equal(await menu().getByRole('menuitem',{name:'Cut Ctrl+X',exact:true}).isDisabled(),true);
|
|
assert.equal(await menu().getByRole('menuitem',{name:'Copy Ctrl+C',exact:true}).isDisabled(),true);
|
|
await page.screenshot({path:`${output}/empty-${theme}.png`});
|
|
await menu().getByRole('menuitem',{name:'Format',exact:true}).focus();
|
|
await page.keyboard.press('ArrowRight');
|
|
const format = page.getByRole('menu',{name:'Format',exact:true});
|
|
for (const label of ['Bold Ctrl+B','Italic Ctrl+I','Strikethrough Ctrl+Shift+X','Highlight Ctrl+Shift+H','Code','Math','Comment','Clear formatting']) assert.equal(await format.getByRole('menuitem',{name:label,exact:true}).count(),1);
|
|
await page.keyboard.press('End');
|
|
assert.equal(await page.getByRole('menuitem',{name:'Comment',exact:true}).evaluate(el=>el===document.activeElement),true);
|
|
await page.screenshot({path:`${output}/format-${theme}.png`});
|
|
await page.keyboard.press('ArrowLeft');
|
|
await page.keyboard.press('Escape');
|
|
assert.equal(await page.locator('.cm-content').evaluate(el=>el===document.activeElement),true);
|
|
await openKeyboard();
|
|
await menu().getByRole('menuitem',{name:'Paragraph',exact:true}).click();
|
|
await page.getByRole('menu',{name:'Paragraph',exact:true}).getByRole('menuitem',{name:'Heading 6',exact:true}).click();
|
|
assert.equal(await source(),'###### ');
|
|
await setSource(''); await openKeyboard();
|
|
await menu().getByRole('menuitem',{name:'Insert',exact:true}).click();
|
|
await page.screenshot({path:`${output}/insert-${theme}.png`});
|
|
await page.getByRole('menu',{name:'Insert',exact:true}).getByRole('menuitem',{name:'Code block',exact:true}).click();
|
|
assert.match(await source(),/^```\nCode\n```/);
|
|
await setSource(''); await openKeyboard();
|
|
await menu().getByRole('menuitem',{name:'Add external link Ctrl+K',exact:true}).click();
|
|
assert.equal(await source(),'[]()');
|
|
assert.equal(await page.evaluate(()=>window.__CM__.state.selection.main.head),1);
|
|
assert.equal(await page.getByRole('dialog').count(),0);
|
|
await setSource('label',0,5); await openKeyboard();
|
|
await menu().getByRole('menuitem',{name:'Add external link Ctrl+K',exact:true}).click();
|
|
assert.equal(await source(),'[label]()');
|
|
assert.equal(await page.evaluate(()=>window.__CM__.state.selection.main.head),8);
|
|
await setSource(''); await openKeyboard();
|
|
await menu().getByRole('menuitem',{name:'Add link',exact:true}).click();
|
|
await page.getByRole('textbox',{name:'Find a file'}).fill('second');
|
|
await page.screenshot({path:`${output}/workspace-picker-${theme}.png`});
|
|
await page.keyboard.press('Enter');
|
|
await page.getByRole('dialog').waitFor({state:'detached'});
|
|
assert.equal(await source(),'[[/notes/second.md]]');
|
|
await setSource('Keep this text'); await openKeyboard();
|
|
await menu().getByRole('menuitem',{name:'Add link',exact:true}).click();
|
|
await page.getByRole('textbox',{name:'Find a file'}).waitFor();
|
|
await page.keyboard.press('Escape');
|
|
await page.getByRole('dialog').waitFor({state:'detached'});
|
|
assert.equal(await source(),'Keep this text');
|
|
await setSource('Populated paragraph\n\n');
|
|
await page.locator('.cm-line').last().click({button:'right'});
|
|
await menu().waitFor();
|
|
await page.keyboard.press('Escape');
|
|
await setSource('');
|
|
await page.getByRole('button',{name:'Hide outline',exact:true}).click();
|
|
await page.setViewportSize({width:560,height:420});
|
|
await page.locator('.cm-scroller').click({button:'right',position:{x:60,y:180}});
|
|
await menu().waitFor();
|
|
const box = await menu().boundingBox(); assert.ok(box.x>=8 && box.y>=8 && box.x+box.width<=552 && box.y+box.height<=412);
|
|
await page.screenshot({path:`${output}/narrow-${theme}.png`});
|
|
await page.keyboard.press('Escape');
|
|
await page.setViewportSize({width:1440,height:1000});
|
|
await page.getByRole('button',{name:'Show outline',exact:true}).click();
|
|
}
|
|
await chooseView(page, 'Source');
|
|
await page.locator('.source-editor .cm-content').waitFor();
|
|
await page.locator('.source-editor .cm-content').focus();
|
|
await page.keyboard.press('Shift+F10');
|
|
await menu().waitFor();
|
|
await menu().getByRole('menuitem',{name:'Add external link Ctrl+K',exact:true}).click();
|
|
assert.equal(await page.getByRole('dialog').count(),0);
|
|
await page.locator('.source-editor .cm-content').focus();
|
|
await page.keyboard.press('Control+a');
|
|
await page.keyboard.press('Backspace');
|
|
await page.keyboard.press('Shift+F10');
|
|
await menu().getByRole('menuitem',{name:'Add link',exact:true}).click();
|
|
await page.getByRole('textbox',{name:'Find a file'}).fill('second');
|
|
await page.keyboard.press('Enter');
|
|
await page.getByRole('dialog').waitFor({state:'detached'});
|
|
await page.screenshot({path:`${output}/ide-links.png`});
|
|
console.log('PASS: empty and whitespace Writer menus, full submenus, disabled actions, links, picker, selection, keyboard focus, two themes, narrow viewport and Source.');
|
|
});
|