114 lines
6.6 KiB
JavaScript
114 lines
6.6 KiB
JavaScript
// Splash actions and order, and New folder with inline rename in the root, collapsed, and empty folders, with and without a workspace.
|
|
import assert from 'node:assert/strict';
|
|
import { writeFile } from 'node:fs/promises';
|
|
import path from 'node:path';
|
|
import { mockTauri, openPage, outputDir, runSmoke, smokeUrl } from '../_harness/index.mjs';
|
|
|
|
await runSmoke('tree/navigation', async ({ browser }) => {
|
|
const context = await browser.newContext({ viewport: { width: 1280, height: 850 } });
|
|
await mockTauri(context, {
|
|
strict: false,
|
|
commands: test => {
|
|
const ws = test.workspace({ root: 'C:\\navigation-check', folders: ['Untitled', 'Parent', 'Empty'], files: { 'note.md': '# Note', 'Parent/existing.md': '# Existing' } });
|
|
test.folders = ws.folders;
|
|
return {
|
|
...ws,
|
|
workspace_last_path: () => test.noWorkspace ? null : ws.root,
|
|
workspace_list: args => ws.workspace_list(args).filter(entry => !entry.rel_path.startsWith('.runestone')),
|
|
workspace_search: () => [],
|
|
plugins_snapshot: () => ({ root: 'C:/plugins', plugins: [] }),
|
|
'plugin:window|is_maximized': () => false,
|
|
};
|
|
},
|
|
});
|
|
const page = await openPage(context);
|
|
const output = await outputDir('tree/navigation');
|
|
const shot = name => page.screenshot({ path: path.join(output, name) });
|
|
const row = rel => page.locator(`[data-tree-rel="${rel}"]`);
|
|
const input = () => page.locator('.tree input');
|
|
const folderAction = () => page.getByRole('menuitem', { name: 'New folder', exact: true });
|
|
async function checkRename(name) {
|
|
await input().waitFor();
|
|
await page.waitForFunction(() => document.activeElement?.matches('.tree input'));
|
|
const state = await input().evaluate(node => ({ name: node.value, start: node.selectionStart, end: node.selectionEnd }));
|
|
assert.deepEqual(state, { name, start: 0, end: name.length });
|
|
assert.equal(await page.getByRole('dialog').count(), 0, 'New folder uses inline rename');
|
|
}
|
|
async function setMode(mode) {
|
|
await page.evaluate(async mode => { const { saveAppearance } = await import('/src/lib/theme/appearance.ts'); saveAppearance({ theme: 'default', mode }); }, mode);
|
|
}
|
|
|
|
await page.goto(smokeUrl);
|
|
await row('Untitled').waitFor();
|
|
const welcome = page.locator('.welcome-actions');
|
|
await welcome.waitFor();
|
|
await welcome.getByRole('button', { name: 'Open browser', exact: true }).waitFor();
|
|
assert.deepEqual(await welcome.locator('button').allTextContents().then(values => values.map(value => value.replace(/Ctrl\+[NOP]/g, '').trim())), ['New file', 'New note', 'Find file', 'Open folder', 'Open browser']);
|
|
const firstRow = welcome.locator('.welcome-row').first();
|
|
assert.equal(await firstRow.locator('button').count(), 3);
|
|
const tops = await firstRow.locator('button').evaluateAll(nodes => nodes.map(node => node.getBoundingClientRect().top));
|
|
assert.ok(tops.every(top => top === tops[0]), 'Wide layout has three actions in the first row');
|
|
await welcome.getByRole('button', { name: /^New file/ }).focus();
|
|
for (const name of ['New note', 'Find file', 'Open folder', 'Open browser']) {
|
|
await page.keyboard.press('Tab');
|
|
assert.ok((await page.evaluate(() => document.activeElement.textContent)).includes(name), `Tab reaches ${name} in order`);
|
|
}
|
|
for (const mode of ['dark', 'light']) {
|
|
await setMode(mode);
|
|
await welcome.getByRole('button', { name: /^New file/ }).focus();
|
|
await shot(`splash-${mode}.png`);
|
|
await page.setViewportSize({ width: 850, height: 650 });
|
|
await shot(`splash-${mode}-narrow.png`);
|
|
assert.ok(await welcome.locator('button').evaluateAll(nodes => nodes.every(node => { const rect = node.getBoundingClientRect(); return rect.left >= 0 && rect.right <= innerWidth; })), 'Narrow splash controls fit');
|
|
await page.setViewportSize({ width: 1280, height: 850 });
|
|
}
|
|
await page.getByRole('navigation', { name: 'Workspace files' }).click({ button: 'right', position: { x: 80, y: 320 } });
|
|
await folderAction().focus();
|
|
await page.keyboard.press('Enter');
|
|
await checkRename('untitled 2');
|
|
await input().fill('Created folder');
|
|
await input().press('Enter');
|
|
await row('Created folder').waitFor();
|
|
await row('Parent').click();
|
|
await row('Parent').click();
|
|
assert.equal(await row('Parent').getAttribute('aria-expanded'), 'false');
|
|
await row('Parent').click({ button: 'right' });
|
|
await folderAction().click();
|
|
await checkRename('untitled');
|
|
assert.equal(await row('Parent').getAttribute('aria-expanded'), 'true', 'Cached collapsed parent opens for rename');
|
|
await input().press('Escape');
|
|
await row('Parent/untitled').waitFor();
|
|
for (const mode of ['dark', 'light']) {
|
|
await setMode(mode);
|
|
await row('Parent').click({ button: 'right' });
|
|
await folderAction().click();
|
|
const expected = mode === 'dark' ? 'untitled 2' : 'untitled 3';
|
|
await checkRename(expected);
|
|
await shot(`new-folder-${mode}.png`);
|
|
await page.setViewportSize({ width: 850, height: 650 });
|
|
await shot(`new-folder-${mode}-narrow.png`);
|
|
await input().press('Escape');
|
|
await page.setViewportSize({ width: 1280, height: 850 });
|
|
}
|
|
await row('Empty').click({ button: 'right' });
|
|
await folderAction().click();
|
|
await checkRename('untitled');
|
|
await input().fill('First folder');
|
|
await input().press('Enter');
|
|
await row('Empty/First folder').waitFor();
|
|
assert.equal(await page.evaluate(() => window.__TEST__.folders.has('Empty/First folder')), true);
|
|
|
|
const emptyPage = await openPage(context);
|
|
await emptyPage.addInitScript(() => { window.__TEST__.noWorkspace = true; });
|
|
await emptyPage.goto(smokeUrl);
|
|
await emptyPage.locator('.welcome-actions').waitFor();
|
|
await emptyPage.locator('.welcome-actions').getByRole('button', { name: 'Open browser', exact: true }).waitFor();
|
|
assert.deepEqual(await emptyPage.locator('.welcome-actions button').allTextContents().then(values => values.map(value => value.replace(/Ctrl\+O/g, '').trim())), ['Open folder', 'Open browser']);
|
|
await emptyPage.screenshot({ path: path.join(output, 'splash-no-workspace.png') });
|
|
await emptyPage.close();
|
|
const errors = [...page.errors, ...emptyPage.errors];
|
|
assert.deepEqual(errors, []);
|
|
await writeFile(path.join(output, 'checks.json'), JSON.stringify({ passed: true, checks: ['Case-insensitive root name collision', 'Selected inline name and no dialog', 'Enter saves rename', 'Escape retains created folder', 'Collapsed cached parent opens', 'Empty parent', 'Repeated unique names', 'Splash order and three-column maximum', 'Keyboard tab order', 'No workspace actions', 'Dark/light wide/narrow screenshots'], errors }, null, 2));
|
|
console.log(`Navigation checks passed. Evidence: ${output}`);
|
|
});
|