RuneStone 1.0.0
This commit is contained in:
@@ -0,0 +1,145 @@
|
||||
// One full-width document Find in Writer, table cells, Source source, and Reading: replacement, regex, CRLF, focus return, both themes, and narrow controls.
|
||||
import assert from "node:assert/strict";
|
||||
import { chooseView, mockTauri, outputDir, runSmoke, smokeUrl } from "../_harness/index.mjs";
|
||||
|
||||
await runSmoke("find/documentFind", async ({ page }) => {
|
||||
const output = await outputDir("find/documentFind");
|
||||
await mockTauri(page, {
|
||||
commands: test => {
|
||||
const workspace = test.workspace({
|
||||
root: "C:\\smoke-workspace",
|
||||
writeEvents: true,
|
||||
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",
|
||||
},
|
||||
});
|
||||
return {
|
||||
...workspace,
|
||||
workspace_write: args => {
|
||||
if (args.expected !== undefined && workspace.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": () => "Cancel",
|
||||
};
|
||||
},
|
||||
});
|
||||
|
||||
const sample = "# Alpha\n\nAlpha alpha alphabet\n\n| Name | Value |\n| --- | --- |\n| Alpha | One |\n| Beta | Two |\n\nLast Alpha paragraph.\n";
|
||||
const find = page.getByRole("textbox", { name: "Find in document", exact: true });
|
||||
const replace = page.getByRole("textbox", { name: "Replace with", exact: true });
|
||||
async function onePanel() {
|
||||
assert.equal(await page.locator('.rs-find-bar:visible').count(), 1);
|
||||
assert.equal(await page.locator('.cm-search').count(), 0, 'No default CodeMirror search panel');
|
||||
const bar = await page.locator('.rs-find-bar:visible').boundingBox();
|
||||
const pane = await page.locator('.editor.pane-active').boundingBox();
|
||||
assert.ok(Math.abs(bar.width - pane.width) < 3, 'Find spans the document pane');
|
||||
}
|
||||
async function sourceEditor() {
|
||||
await page.waitForFunction(() => !!document.querySelector('.source-editor .cm-content'));
|
||||
return page.evaluate(async () => {
|
||||
const { EditorView } = await import('/node_modules/@codemirror/view/dist/index.js');
|
||||
window.__SOURCE__ = EditorView.findFromDOM(document.querySelector('.source-editor .cm-content'));
|
||||
window.__SOURCE__.focus();
|
||||
});
|
||||
}
|
||||
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();
|
||||
for (const theme of ['dark', 'light']) {
|
||||
await page.evaluate(async theme => {
|
||||
const { saveAppearance } = await import('/src/lib/theme/appearance.ts');
|
||||
saveAppearance({ theme: 'default', mode: theme });
|
||||
}, theme);
|
||||
await page.getByRole('textbox', { name: 'Writing editor', exact: true }).waitFor();
|
||||
await page.evaluate(async sample => {
|
||||
const { EditorView } = await import('/node_modules/@codemirror/view/dist/index.js');
|
||||
window.__CM__ = EditorView.findFromDOM(document.querySelector('.live-writer > .cm-editor .cm-content'));
|
||||
window.__CM__.dispatch({ changes: { from: 0, to: window.__CM__.state.doc.length, insert: sample }, selection: { anchor: 0 } });
|
||||
window.__CM__.focus();
|
||||
}, sample);
|
||||
await page.keyboard.press('Control+f');
|
||||
await find.fill('Alpha');
|
||||
await onePanel();
|
||||
await page.screenshot({ path: `${output}/writer-${theme}.png` });
|
||||
await page.keyboard.press('Escape');
|
||||
await page.locator('.live-writer td').first().dblclick();
|
||||
await page.locator('.writer-cell-editor').waitFor();
|
||||
await page.keyboard.press('Control+f');
|
||||
await onePanel();
|
||||
assert.equal(await find.evaluate(node => node === document.activeElement), true, 'Table focus opens the document find');
|
||||
assert.equal(await page.locator('.writer-cell-editor .rs-find-bar').count(), 0);
|
||||
await find.fill('Last Alpha');
|
||||
await page.keyboard.press('Enter');
|
||||
assert.match(await page.evaluate(() => window.__CM__.state.sliceDoc(window.__CM__.state.selection.main.from, window.__CM__.state.selection.main.to)), /Last Alpha/);
|
||||
await page.screenshot({ path: `${output}/table-focus-${theme}.png` });
|
||||
await page.keyboard.press('Escape');
|
||||
await chooseView(page, 'Source');
|
||||
await sourceEditor();
|
||||
await page.evaluate(() => { const view = window.__SOURCE__; view.dispatch({ changes: { from: 0, to: view.state.doc.length, insert: 'Alpha alpha alphabet\r\nAlpha second\r\nAlpha third' }, selection: { anchor: 0 } }); });
|
||||
await page.keyboard.press('Control+f');
|
||||
await find.fill('Alpha');
|
||||
await onePanel();
|
||||
await page.keyboard.press('Enter');
|
||||
const selection = () => page.evaluate(() => JSON.stringify(window.__SOURCE__.state.selection.main));
|
||||
const first = await selection();
|
||||
await page.keyboard.press('Enter');
|
||||
assert.notEqual(await selection(), first);
|
||||
await page.keyboard.press('Shift+Enter');
|
||||
assert.equal(await selection(), first);
|
||||
await page.getByRole('checkbox', { name: 'Match case' }).check();
|
||||
await page.getByRole('checkbox', { name: 'Whole word' }).check();
|
||||
await replace.fill('Gamma');
|
||||
await page.getByRole('button', { name: 'Replace all', exact: true }).click();
|
||||
assert.equal(await page.evaluate(() => window.__SOURCE__.state.doc.toString()), 'Gamma alpha alphabet\nGamma second\nGamma third');
|
||||
await page.getByRole('checkbox', { name: 'Regex' }).check();
|
||||
await find.fill('[');
|
||||
assert.equal(await find.getAttribute('aria-invalid'), 'true');
|
||||
assert.equal(await page.getByRole('button', { name: 'Replace all', exact: true }).isDisabled(), true);
|
||||
await find.fill('(?<=G)(amma)');
|
||||
await page.getByRole('checkbox', { name: 'Whole word' }).uncheck();
|
||||
await replace.fill('$1!');
|
||||
await page.getByRole('button', { name: 'Replace all', exact: true }).click();
|
||||
assert.match(await page.evaluate(() => window.__SOURCE__.state.doc.toString()), /^Gamma! alpha/);
|
||||
await page.getByRole('checkbox', { name: 'Regex' }).uncheck();
|
||||
await find.fill('Gamma');
|
||||
await page.getByRole('button', { name: 'Select all', exact: true }).click();
|
||||
assert.equal(await page.evaluate(() => window.__SOURCE__.state.selection.ranges.length), 3);
|
||||
await page.screenshot({ path: `${output}/source-${theme}.png` });
|
||||
await find.focus(); await page.keyboard.press('Escape');
|
||||
assert.equal(await find.count(), 0);
|
||||
assert.equal(await page.evaluate(() => window.__SOURCE__.hasFocus), true);
|
||||
await page.keyboard.press('Control+h');
|
||||
assert.equal(await replace.evaluate(node => node === document.activeElement), true);
|
||||
await find.fill('Gamma');
|
||||
await page.keyboard.press('Enter');
|
||||
await page.keyboard.press('F3');
|
||||
await page.screenshot({ path: `${output}/source-replace-${theme}.png` });
|
||||
await page.setViewportSize({ width: 800, height: 700 });
|
||||
await onePanel();
|
||||
assert.equal(await page.locator('.rs-find-bar').evaluate(node => node.scrollWidth <= node.clientWidth), true);
|
||||
await page.screenshot({ path: `${output}/source-narrow-${theme}.png` });
|
||||
await page.setViewportSize({ width: 1440, height: 1000 });
|
||||
await find.focus(); await page.keyboard.press('Escape');
|
||||
await page.evaluate(sample => { const view = window.__SOURCE__; view.dispatch({ changes: { from: 0, to: view.state.doc.length, insert: sample } }); }, sample);
|
||||
await chooseView(page, 'Read');
|
||||
await page.locator('.reading').focus();
|
||||
await page.keyboard.press('Control+f');
|
||||
await find.fill('Alpha'); await page.keyboard.press('Enter');
|
||||
await onePanel();
|
||||
assert.equal(await replace.count(), 0, 'Reading search does not offer replacement');
|
||||
assert.equal(await page.evaluate(() => window.getSelection().toString()), 'Alpha');
|
||||
const anchor = await page.evaluate(() => window.getSelection().anchorNode.parentElement.outerHTML);
|
||||
await page.keyboard.press('Enter');
|
||||
assert.notEqual(await page.evaluate(() => window.getSelection().anchorNode.parentElement.outerHTML), anchor);
|
||||
await page.screenshot({ path: `${output}/reading-${theme}.png` });
|
||||
await page.keyboard.press('Escape');
|
||||
assert.equal(await page.locator('.reading').evaluate(node => node === document.activeElement), true);
|
||||
await chooseView(page, 'Write');
|
||||
}
|
||||
console.log('PASS: one full-width document Find in Writer, nested table focus, Source/source, and Reading, with replacement, regex, CRLF, focus return, both themes, and narrow controls.');
|
||||
});
|
||||
@@ -0,0 +1,168 @@
|
||||
// Find in plug-in views: privacy attributes, Project Management views, plug-in documents, custom find handlers, focus, both themes, and narrow layouts.
|
||||
// Project Management is a native feature. Its board is in the hidden storage of the workspace (.runestone/pm/).
|
||||
import assert from 'node:assert/strict';
|
||||
import { mockTauri, outputDir, runSmoke, smokeUrl } from '../_harness/index.mjs';
|
||||
|
||||
const board = {
|
||||
schema: 1, kind: 'board', id: 'host-find-board',
|
||||
lists: [
|
||||
{ id: 'todo', name: 'To do', status: 'todo', collapsed: false },
|
||||
{ id: 'doing', name: 'In progress', status: 'doing', collapsed: false },
|
||||
{ id: 'done', name: 'Done', status: 'done', collapsed: false },
|
||||
],
|
||||
defaults: { todo: 'todo', doing: 'doing', done: 'done' },
|
||||
};
|
||||
|
||||
await runSmoke('find/pluginViews', async ({ page }) => {
|
||||
const output = await outputDir('find/pluginViews');
|
||||
// Unknown commands return null, as the original mock did.
|
||||
await mockTauri(page, {
|
||||
strict: false,
|
||||
state: { catalog: JSON.stringify({ schema: 1, boards: [{ name: 'Find board', value: board }] }, null, 2) + '\n' },
|
||||
commands: test => {
|
||||
const workspace = test.workspace({
|
||||
root: 'C:/find-test',
|
||||
files: {
|
||||
'untitled.md': '# Existing note\n',
|
||||
'sample.finddoc': 'Alpha alpha alphabet',
|
||||
'.runestone/pm/.gitignore': '*\n',
|
||||
'.runestone/pm/workspace.json': test.state.catalog,
|
||||
},
|
||||
});
|
||||
test.files = workspace.files;
|
||||
const manifest = { schemaVersion: 1, id: 'test.find', name: 'Find test', author: 'Test', description: 'Search checks', version: '1.0.0', apiVersion: 1, entry: 'main.js', access: 'full-app' };
|
||||
const code = `export function activate(api) {
|
||||
api.registerDocumentType({ id: 'document', title: 'Test document', extensions: ['finddoc'], identify: path => ({ id: path }), mount(root) {
|
||||
root.innerHTML = '<section><h2>Test document</h2><p>Alpha alpha alphabet</p><button>Alpha card</button><p hidden>Hidden Alpha</p><button class="focus-return">Details</button></section>';
|
||||
}});
|
||||
for (const name of ['Board', 'Changes']) api.registerView({ id: name.toLowerCase(), title: name, placement: 'editor', navigation: true, icon: 'list', mount(root) {
|
||||
root.innerHTML = '<section><h2>' + name + '</h2><p>Alpha alpha alphabet</p><button>Alpha card</button><p hidden>Hidden Alpha</p><button class="focus-return">Details</button></section>';
|
||||
}});
|
||||
api.registerView({ id: 'native', title: 'Custom find', placement: 'editor', navigation: true, find() { window.customFindCalls = (window.customFindCalls || 0) + 1; }, mount(root) { root.innerHTML = '<p>Native content</p>'; } });
|
||||
}`;
|
||||
return {
|
||||
...workspace,
|
||||
workspace_read: args => {
|
||||
if (!workspace.files.has(args.rel) && args.missingOk) return null;
|
||||
return workspace.workspace_read(args);
|
||||
},
|
||||
plugins_snapshot: () => ({ root: 'C:/test/plugins', plugins: [manifest].map(item => ({ manifest: item, hash: item.id, enabled: true, path: 'C:/test/plugins/' + item.id, error: null, removal: false })) }),
|
||||
plugins_load: () => code,
|
||||
plugins_data: () => 'null',
|
||||
browser_connect: () => 'test',
|
||||
};
|
||||
},
|
||||
});
|
||||
await page.goto(smokeUrl);
|
||||
await page.locator('.ws').getByText('find-test', { exact: true }).waitFor();
|
||||
await page.getByRole('button', { name: 'Plug-in views', exact: true }).waitFor();
|
||||
const note = page.locator('.tree-tools').getByRole('button', { name: 'New note', exact: true });
|
||||
assert.equal(await page.locator('.tree-tools').getByRole('button', { name: 'New file', exact: true }).count(), 0);
|
||||
await note.click();
|
||||
await page.waitForFunction(() => window.__TEST__.files.has('untitled 2.md'));
|
||||
await page.getByRole('textbox', { name: 'Writing editor', exact: true }).waitFor();
|
||||
await page.getByRole('textbox', { name: 'Writing editor', exact: true }).click();
|
||||
await page.keyboard.press('Control+f');
|
||||
for (const label of ['Find in document', 'Replace with']) {
|
||||
assert.equal(await page.getByRole('textbox', { name: label, exact: true }).getAttribute('autocomplete'), 'off');
|
||||
}
|
||||
await page.keyboard.press('Escape');
|
||||
await page.screenshot({ path: `${output}/new-note-dark.png` });
|
||||
assert.equal(await page.getByRole('dialog').count(), 0, 'The note opens without a filename dialog');
|
||||
await note.click();
|
||||
await page.waitForFunction(() => window.__TEST__.files.has('untitled 3.md'));
|
||||
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 page.getByRole('tab', { name: 'untitled 3.md', exact: true }).click();
|
||||
await page.getByRole('textbox', { name: 'Writing editor', exact: true }).click();
|
||||
await page.keyboard.press('Control+f');
|
||||
const writerFind = page.getByRole('textbox', { name: 'Find in document', exact: true });
|
||||
await writerFind.fill('fift');
|
||||
assert.equal(await writerFind.getAttribute('autocomplete'), 'off');
|
||||
assert.equal(await page.getByRole('textbox', { name: 'Replace with', exact: true }).getAttribute('autocomplete'), 'off');
|
||||
await page.screenshot({ path: `${output}/find-privacy-${theme}.png` });
|
||||
await page.setViewportSize({ width: 650, height: 800 });
|
||||
await page.screenshot({ path: `${output}/find-privacy-${theme}-narrow.png` });
|
||||
await page.keyboard.press('Escape');
|
||||
await page.setViewportSize({ width: 1440, height: 1000 });
|
||||
await page.mouse.move(900, 400);
|
||||
await note.hover();
|
||||
await page.getByRole('tooltip').filter({ hasText: /^New note$/ }).waitFor();
|
||||
await page.screenshot({ path: `${output}/new-note-tooltip-${theme}.png` });
|
||||
for (const name of ['Board', 'Changes']) {
|
||||
await page.getByRole('navigation', { name: 'Plugin shortcuts' }).getByRole('button', { name, exact: true }).click();
|
||||
const pane = page.getByRole('tabpanel', { name, exact: true });
|
||||
await pane.getByRole('button', { name: 'Details', exact: true }).focus();
|
||||
await page.keyboard.press('Control+f');
|
||||
assert.equal(await pane.locator('.rs-find-bar').count(), 0, 'Non-document plugin views do not show document Find');
|
||||
await page.screenshot({ path: `${output}/${name}-${theme}.png` });
|
||||
await page.setViewportSize({ width: 650, height: 800 });
|
||||
await page.keyboard.press('Control+f');
|
||||
assert.equal(await pane.locator('.rs-find-bar').count(), 0);
|
||||
await page.screenshot({ path: `${output}/${name}-${theme}-narrow.png` });
|
||||
await page.setViewportSize({ width: 1440, height: 1000 });
|
||||
}
|
||||
for (const surface of ['all-tasks', 'board']) {
|
||||
// The ribbon button opens All tasks. The board scope opens the board in the same tab.
|
||||
if (surface === 'all-tasks') await page.locator('.plugin-ribbon').getByRole('button', { name: 'Project Management', exact: true }).click();
|
||||
else {
|
||||
await page.locator('.plugin-editor-pane:visible').getByRole('button', { name: /^Board scope:/ }).click();
|
||||
await page.getByRole('menuitemradio', { name: 'Find board', exact: true }).click();
|
||||
await page.getByRole('tab', { name: 'Find board', exact: true }).waitFor();
|
||||
}
|
||||
const pane = page.locator('.plugin-editor-pane:visible');
|
||||
await pane.locator('.pm-board').waitFor();
|
||||
await pane.focus();
|
||||
await page.keyboard.press('Control+f');
|
||||
assert.equal(await pane.locator('.rs-find-bar').count(), 0, 'Actual PM views do not show host Find');
|
||||
await page.screenshot({ path: `${output}/pm-${surface}-${theme}.png` });
|
||||
await page.setViewportSize({ width: 650, height: 800 });
|
||||
await page.keyboard.press('Control+f');
|
||||
assert.equal(await pane.locator('.rs-find-bar').count(), 0);
|
||||
await page.screenshot({ path: `${output}/pm-${surface}-${theme}-narrow.png` });
|
||||
await page.setViewportSize({ width: 1440, height: 1000 });
|
||||
}
|
||||
await page.getByRole('tree', { name: 'Workspace files' }).getByText('sample', { exact: true }).dblclick();
|
||||
for (const name of ['sample']) {
|
||||
const pane = page.getByRole('tabpanel', { name, exact: true });
|
||||
const returnButton = pane.getByRole('button', { name: 'Details', exact: true });
|
||||
await returnButton.focus();
|
||||
await page.keyboard.press('Control+f');
|
||||
const find = pane.getByRole('textbox', { name: 'Find in document', exact: true });
|
||||
assert.equal(await find.getAttribute('autocomplete'), 'off');
|
||||
await find.fill('Alpha');
|
||||
assert.equal(await page.locator('.rs-find-bar:visible').count(), 1);
|
||||
assert.equal(await pane.getByRole('textbox', { name: 'Replace with' }).count(), 0);
|
||||
await page.keyboard.press('Enter');
|
||||
assert.equal(await page.evaluate(() => getSelection().toString()), 'Alpha');
|
||||
await page.keyboard.press('F3');
|
||||
assert.equal(await page.evaluate(() => getSelection().toString()), 'alpha');
|
||||
await pane.getByText('Whole word', { exact: true }).click();
|
||||
await find.focus();
|
||||
const matches = [];
|
||||
for (let i = 0; i < 4; i++) {
|
||||
await page.keyboard.press('Enter');
|
||||
matches.push(await page.evaluate(() => ({ text: getSelection().toString(), button: !!getSelection().anchorNode?.parentElement?.closest('button') })));
|
||||
}
|
||||
assert.equal(matches.filter(match => match.button).length, 1, 'Rendered card buttons participate in search');
|
||||
assert.ok(matches.every(match => /^alpha$/i.test(match.text)));
|
||||
await page.screenshot({ path: `${output}/${name}-${theme}.png` });
|
||||
await page.setViewportSize({ width: 650, height: 800 });
|
||||
await page.screenshot({ path: `${output}/${name}-${theme}-narrow.png` });
|
||||
const bar = await pane.locator('.rs-find-bar').boundingBox(), bounds = await pane.boundingBox();
|
||||
assert.ok(bar.x >= bounds.x && bar.x + bar.width <= bounds.x + bounds.width + 1);
|
||||
// The side panes give way in a narrow window and come back in a wide one (src/lib/layout/Workbench.svelte).
|
||||
await page.screenshot({ path: `${output}/${name}-${theme}-narrow-focused.png` });
|
||||
await find.focus();
|
||||
await page.keyboard.press('Escape');
|
||||
assert.equal(await returnButton.evaluate(node => node === document.activeElement), true);
|
||||
await page.setViewportSize({ width: 1440, height: 1000 });
|
||||
}
|
||||
}
|
||||
await page.getByRole('navigation', { name: 'Plugin shortcuts' }).getByRole('button', { name: 'Custom find', exact: true }).click();
|
||||
await page.getByRole('tabpanel', { name: 'Custom find' }).focus();
|
||||
await page.keyboard.press('Control+f');
|
||||
assert.equal(await page.evaluate(() => window.customFindCalls), 1, 'Plugin find handlers retain ownership');
|
||||
assert.equal(await page.locator('.rs-find-bar:visible').count(), 0);
|
||||
console.log('PASS: Find privacy attributes, actual PM All Tasks and board scope, plugin document Find, custom handlers, focus, both themes, and narrow layouts');
|
||||
});
|
||||
@@ -0,0 +1,122 @@
|
||||
// Writer find bar in the top editor panel: shortcuts, replacement, query sync, invalid regex, tooltip, outline filtering, focus return, and narrow layout.
|
||||
import assert from "node:assert/strict";
|
||||
import path from "node:path";
|
||||
import { mockTauri, outputDir, runSmoke, smokeUrl } from "../_harness/index.mjs";
|
||||
|
||||
await runSmoke("find/searchPanel", async ({ page }) => {
|
||||
const output = await outputDir("find/searchPanel");
|
||||
await mockTauri(page, {
|
||||
commands: test => {
|
||||
const workspace = test.workspace({
|
||||
root: "C:\\smoke-workspace",
|
||||
writeEvents: true,
|
||||
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",
|
||||
},
|
||||
});
|
||||
return {
|
||||
...workspace,
|
||||
workspace_write: args => {
|
||||
if (args.expected !== undefined && workspace.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": () => "Cancel",
|
||||
};
|
||||
},
|
||||
});
|
||||
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();
|
||||
const editor = page.getByRole("textbox", { name: "Writing editor", exact: true });
|
||||
await editor.waitFor();
|
||||
await page.evaluate(async () => {
|
||||
const { EditorView } = await import("/node_modules/@codemirror/view/dist/index.js");
|
||||
window.__CM__ = EditorView.findFromDOM(document.querySelector(".cm-content"));
|
||||
window.__CM__.dispatch({ changes: { from: 0, to: window.__CM__.state.doc.length, insert: "# Alpha\n\nalpha Alpha alphabet\n\n## Beta\n\nBeta text\n" }, selection: { anchor: 0 } });
|
||||
window.__CM__.focus();
|
||||
});
|
||||
await page.keyboard.press("Control+f");
|
||||
const find = page.getByRole("textbox", { name: "Find in document", exact: true });
|
||||
await find.waitFor();
|
||||
assert.equal(await find.evaluate(el => document.activeElement === el), true);
|
||||
assert.equal(await page.locator(".cm-panels-top .rs-editor-search").count(), 1);
|
||||
const panelBounds = await page.locator(".rs-editor-search").boundingBox();
|
||||
const scrollBounds = await page.locator(".cm-scroller").boundingBox();
|
||||
assert.ok(panelBounds.y + panelBounds.height <= scrollBounds.y + 1);
|
||||
await find.fill("Alpha");
|
||||
await page.keyboard.press("Enter");
|
||||
const first = await page.evaluate(() => window.__CM__.state.selection.main.from);
|
||||
await page.keyboard.press("Enter");
|
||||
const second = await page.evaluate(() => window.__CM__.state.selection.main.from);
|
||||
assert.notEqual(first, second);
|
||||
await page.keyboard.press("Shift+Enter");
|
||||
assert.equal(await page.evaluate(() => window.__CM__.state.selection.main.from), first);
|
||||
await page.getByRole("checkbox", { name: "Match case" }).check();
|
||||
await page.getByRole("checkbox", { name: "Whole word" }).check();
|
||||
await page.getByRole("textbox", { name: "Replace with" }).fill("Gamma");
|
||||
await page.getByRole("button", { name: "Replace all", exact: true }).click();
|
||||
assert.match(await page.evaluate(() => window.__CM__.state.sliceDoc()), /# Gamma\n\nalpha Gamma alphabet/);
|
||||
await page.getByRole("checkbox", { name: "Regex" }).check();
|
||||
await find.fill("[");
|
||||
assert.equal(await find.getAttribute("aria-invalid"), "true");
|
||||
assert.equal(await page.getByRole("button", { name: "Replace all", exact: true }).isDisabled(), true);
|
||||
await page.getByText("Invalid expression", { exact: true }).waitFor();
|
||||
await find.fill("Gamma");
|
||||
await page.getByRole("checkbox", { name: "Regex" }).uncheck();
|
||||
await page.evaluate(async () => {
|
||||
const moduleUrl = performance.getEntriesByType("resource").find(entry => entry.name.includes("/@codemirror_search.js"))?.name;
|
||||
if (!moduleUrl) throw new Error("Search module was not loaded");
|
||||
const { SearchQuery, setSearchQuery } = await import(moduleUrl);
|
||||
window.__CM__.dispatch({ effects: setSearchQuery.of(new SearchQuery({ search: "Beta" })) });
|
||||
});
|
||||
await page.waitForFunction(() => document.querySelector('input[name="search"]').value === "Beta");
|
||||
await find.focus();
|
||||
await page.keyboard.press("Escape");
|
||||
assert.equal(await find.count(), 0);
|
||||
assert.equal(await editor.evaluate(el => document.activeElement === el), true);
|
||||
await page.keyboard.press("Control+f");
|
||||
await find.waitFor();
|
||||
await page.getByRole("button", { name: "Next match (Enter)" }).focus();
|
||||
await page.getByRole("tooltip", { name: "Next match (Enter)" }).waitFor({ state: "visible" });
|
||||
await find.focus();
|
||||
|
||||
const outline = page.getByRole("region", { name: "Outline", exact: true });
|
||||
if (!await outline.count()) await page.getByRole("button", { name: "Outline", exact: true }).click();
|
||||
await outline.focus();
|
||||
await page.keyboard.press("Control+f");
|
||||
const outlineFind = page.getByRole("textbox", { name: "Find in outline", exact: true });
|
||||
await outlineFind.fill("beta");
|
||||
assert.equal(await outline.locator("li").count(), 1);
|
||||
assert.equal(await outline.locator("li button").textContent(), "Beta");
|
||||
await outlineFind.fill("missing");
|
||||
await outline.getByText("No matching headings or symbols.").waitFor();
|
||||
await outlineFind.fill("Gamma");
|
||||
await page.screenshot({ path: path.join(output, "find-bars.png") });
|
||||
await page.keyboard.press("Escape");
|
||||
assert.equal(await outlineFind.count(), 0);
|
||||
assert.equal(await outline.locator("li").count(), 2);
|
||||
assert.equal(await outline.evaluate(el => document.activeElement === el), true);
|
||||
await page.keyboard.press("Control+f");
|
||||
await outlineFind.fill("Beta");
|
||||
await page.keyboard.press("Enter");
|
||||
await page.waitForFunction(() => window.__CM__.state.doc.lineAt(window.__CM__.state.selection.main.head).text === "## Beta");
|
||||
assert.equal(await editor.evaluate(el => document.activeElement === el), true);
|
||||
|
||||
await page.setViewportSize({ width: 880, height: 760 });
|
||||
// The outline gives way below 1100 pixels. The test opens it again to check its search field.
|
||||
await page.getByRole("button", { name: "Show outline", exact: true }).click();
|
||||
await outline.focus();
|
||||
await page.keyboard.press("Control+f");
|
||||
await outlineFind.waitFor();
|
||||
await find.focus();
|
||||
await page.screenshot({ path: path.join(output, "find-bars-narrow.png") });
|
||||
for (const selector of [".rs-editor-search", ".outline-search"]) {
|
||||
assert.equal(await page.locator(selector).evaluate(el => el.scrollWidth <= el.clientWidth), true, selector);
|
||||
}
|
||||
console.log("PASS: Top search panel, shortcuts, replacement, query sync, invalid regex, focus tooltip, outline filtering, focus return and narrow layout.");
|
||||
});
|
||||
Reference in New Issue
Block a user