Phase 5-6. - Side panes give way when the window becomes narrow: the outline below 1100 pixels, the side pane below 800 pixels. They come back when the window grows. A pane that the user opens in a narrow window stays open, and the saved layout keeps the wide-window choice. - One function has one icon. The SDK icon set gets duplicate, template, and tab. The reveal action has one label for each platform (Show in Explorer, Show in Finder, Show in file manager). - The file menu follows one order: open, clipboard, organize, show and copy path, history, then Delete and Delete permanently in the error color after a separator. The tree copies paths through a Copy path submenu, as the tab menu does. - The tree uses the shared chevron. Search hits come in groups by file, with counts and marked matches. Bookmarks show the name, the folder, and a remove button. - All boolean settings use one switch design (src/lib/ui/switch.css). Browser settings apply at once, and the Save button is gone. The Settings window opens with the focus on its search. - Targets of at least 24 pixels: the tab close button, outline rows, switches, and the settings search. - Catalog rows in French, Japanese, and Simplified Chinese. - Docs: UI-052, ui-design.md, and the user guide. Tests: the new layout/panesAndSettings. Tests that closed or opened panes by hand around narrow windows now rely on the new behavior, or wait for the panes to give way before they reopen one. Tests that read the old menu labels or the browser Save button use the new ones.
101 lines
7.4 KiB
JavaScript
101 lines
7.4 KiB
JavaScript
// The built-in browser: navigation, profiles, independence from the legacy package, same-tab view replacement, a plug-in sidebar, and settings.
|
|
import assert from 'node:assert/strict';
|
|
import path from 'node:path';
|
|
import { mockTauri, outputDir, runSmoke, smokeUrl } from '../_harness/index.mjs';
|
|
|
|
await runSmoke('browser/builtin', async ({ page }) => {
|
|
await mockTauri(page, {
|
|
commands: test => {
|
|
const snapshot = { profiles: [{ id: 'user', name: 'Existing user' }], tabs: [], bookmarks: [{ id: 'saved', profileId: 'user', title: 'Existing bookmark', url: 'https://example.com' }], settings: { search: 'duckduckgo', adblock: true, linkDestination: 'internal', personalRules: '', homepage: '', filterLists: [] } };
|
|
const check = Object.assign(test, { loads: [], commands: [], legacy: false, removed: false, mounts: [], cleanups: [] });
|
|
let next = 0;
|
|
const plugin = (id, name, version, hash) => ({ manifest: { schemaVersion: 1, id, name, author: 'Test', description: '', version, apiVersion: 1, entry: 'main.js', access: 'full-app' }, hash, enabled: true, installedAt: 1, path: '', error: null, removal: false });
|
|
return {
|
|
browser_connect: () => 'window-session',
|
|
workspace_last_path: () => null,
|
|
'plugin:window|is_maximized': () => false,
|
|
plugins_snapshot: () => ({ root: 'test', plugins: [
|
|
plugin('org.test.boards', 'Boards', '0.1.0', 'fixture'),
|
|
...(check.legacy && !check.removed ? [plugin('runestone.browser', 'Browser', '0.1.6', 'old')] : []),
|
|
] }),
|
|
plugins_load: ({ id }) => {
|
|
check.loads.push(id);
|
|
if (id === 'runestone.browser') throw Error('The old browser package must not load');
|
|
return `export function activate(api) {
|
|
for (const id of ['board-a', 'board-b']) api.registerView({ id, title: id, placement: 'editor', mount(el) {
|
|
window.__TEST__.mounts.push(id); el.textContent = id;
|
|
if (id === 'board-a') { const b = document.createElement('button'); b.textContent = 'Select board B'; b.onclick = () => api.replaceView('board-a', 'board-b'); el.append(b); }
|
|
return () => { window.__TEST__.cleanups.push(id); };
|
|
}});
|
|
api.registerView({ id:'source-control', title:'Source control', placement:'sidebar', navigation:true, icon:'git', mount(el) { el.textContent='Git sidebar fixture'; }});
|
|
}`;
|
|
},
|
|
browser_request: ({ session, command, args }) => {
|
|
if (session !== 'window-session') throw Error('Missing browser session');
|
|
check.commands.push(command);
|
|
if (command === 'newTab') { const tabId = 'native-' + (++next); snapshot.tabs.push({ id: tabId, profileId: args.profileId || 'user', url: 'about:blank', title: 'Browser', loading: false, blocked: 0, canBack: false, canForward: false }); return { tabId }; }
|
|
if (command === 'closeTab') snapshot.tabs = snapshot.tabs.filter(tab => tab.id !== args.tabId);
|
|
if (command === 'navigate') { const tab = snapshot.tabs.find(tab => tab.id === args.tabId); tab.url = args.input; tab.title = 'Example'; }
|
|
if (command === 'settings') Object.assign(snapshot.settings, args);
|
|
return structuredClone(snapshot);
|
|
},
|
|
};
|
|
},
|
|
});
|
|
const output = await outputDir('browser/builtin');
|
|
const external = () => page.evaluate(() => performance.getEntriesByType('resource').find(entry => new URL(entry.name).pathname === '/src/lib/plugins/external.ts').name);
|
|
const editorKeys = module => page.evaluate(async module => {
|
|
const { get } = await import('/node_modules/.vite/deps/svelte_store.js');
|
|
return get((await import(module)).pluginEditors).map(view => view.key);
|
|
}, module);
|
|
try {
|
|
await page.goto(smokeUrl);
|
|
await page.waitForFunction(async () => { const { pluginHost } = await import('/src/lib/plugins/registry.ts'); return !!pluginHost.get('browser'); });
|
|
await page.getByRole('button', { name: 'Open browser', exact: true }).click();
|
|
await page.locator('[data-browser-state="ready"]').waitFor();
|
|
await page.getByRole('textbox', { name: 'Address or search' }).fill('https://example.com');
|
|
await page.getByRole('textbox', { name: 'Address or search' }).press('Enter');
|
|
await page.waitForFunction(() => window.__TEST__.commands.includes('navigate'));
|
|
await page.getByRole('button', { name: 'Browser profile' }).click();
|
|
assert.equal(await page.getByRole('menuitemradio', { checked: true }).count(), 1);
|
|
await page.keyboard.press('Escape');
|
|
const module = await external();
|
|
await page.evaluate(async module => { window.__TEST__.legacy = true; await (await import(module)).refreshPlugins(); }, module);
|
|
assert.equal(await page.evaluate(() => window.__TEST__.loads.includes('runestone.browser')), false);
|
|
await page.evaluate(async module => { window.__TEST__.removed = true; await (await import(module)).refreshPlugins(); }, module);
|
|
assert.equal(await page.locator('[data-browser-state="ready"]').count(), 1);
|
|
await page.evaluate(async module => { (await import(module)).openPluginView('org.test.boards', 'board-a'); }, module);
|
|
const before = await editorKeys(module);
|
|
await page.getByRole('button', { name: 'Select board B' }).click();
|
|
await page.getByRole('tabpanel', { name: 'board-b', exact: true }).waitFor();
|
|
await page.waitForFunction(() => window.__TEST__.mounts.includes('board-b') && window.__TEST__.cleanups.includes('board-a'));
|
|
assert.deepEqual(await editorKeys(module), before);
|
|
await page.getByRole('button', { name: 'Source control', exact: true }).click();
|
|
await page.getByText('Git sidebar fixture', { exact: true }).waitFor();
|
|
assert.equal(await page.getByRole('tabpanel', { name: 'board-b', exact: true }).count(), 1);
|
|
for (const theme of ['dark', 'light']) {
|
|
await page.evaluate(theme => document.documentElement.dataset.theme = theme, theme);
|
|
await page.screenshot({ path: path.join(output, `builtin-browser-${theme}.png`) });
|
|
}
|
|
await page.goto(smokeUrl + '/?settingsWindow=true');
|
|
await page.getByRole('button', { name: 'Browser', exact: true }).click();
|
|
await page.getByRole('button', { name: 'Search engine', exact: true }).waitFor({ state: 'visible' });
|
|
assert.match(await page.getByRole('button', { name: 'Profile', exact: true }).innerText(), /Existing user/);
|
|
await page.setViewportSize({ width: 360, height: 800 });
|
|
for (const theme of ['dark', 'light']) {
|
|
await page.evaluate(theme => document.documentElement.dataset.theme = theme, theme);
|
|
await page.screenshot({ path: path.join(output, `browser-settings-${theme}.png`) });
|
|
assert.equal(await page.evaluate(() => document.documentElement.scrollWidth > innerWidth), false);
|
|
}
|
|
} catch (error) {
|
|
console.error(await page.evaluate(async () => {
|
|
const m = await import(performance.getEntriesByType('resource').find(entry => new URL(entry.name).pathname === '/src/lib/plugins/external.ts').name);
|
|
const read = store => { let value; store.subscribe(x => value = x)(); return value; };
|
|
const { calls, emit, workspace, ...state } = window.__TEST__;
|
|
return { state, text: document.body.innerText, errors: read(m.externalErrors), views: read(m.pluginEditors), tools: read(m.pluginTools) };
|
|
}).catch(reason => ({ diagnosticError: String(reason) })), page.errors);
|
|
throw error;
|
|
}
|
|
console.log('Built-in browser, legacy package independence, same-tab replacement and plugin sidebar checks passed.');
|
|
}, { viewport: { width: 1280, height: 800 } });
|