Keep the user preferences in settings.json in the app config folder. WebView storage can be lost, and the host cannot read it. The file has a schema number, a revision number, and one value for each section: general, appearance, customThemes, customThemesLegacy, and language. - settings_read gives all sections, the revision, and a one-time notice. - settings_write replaces one section, writes the file atomically, and sends settings-changed to all windows. The limit is 8 MiB. - settings_migrate writes the first file only when no file exists. - The host moves a damaged file to settings.corrupt-<seconds>.json, starts from the defaults, and reports this one time. Each window loads the sections before its first render. One store in src/lib/settings/store.ts replaces the storage listeners. When no file exists, the window normalizes the old localStorage values and migrates them. The old keys stay in place for one release. The window layout and the open tabs stay in localStorage on purpose. The browser preview keeps all preferences in localStorage. Keep tab transfer offers in host memory, not in localStorage, because an offer can hold unsaved text. A window takes an offer once. The host checks the workspace root and a 120 second expiry. When the receiver accepts the tab, the host sends tab-transfer-accepted to the source window only. A refused offer stays open, and the source tab stays open. A new window and a drop on the tab ribbon use one check. The smoke harness serves the new commands from one shared state for each browser context. Tests read saved values from the mock settings file. Rust, unit, and smoke tests cover the changes.
107 lines
7.1 KiB
JavaScript
107 lines
7.1 KiB
JavaScript
// Display language: four locales, persistence, cross-window updates, menu keyboard focus, translated editor menus, and transparency settings.
|
|
import assert from 'node:assert/strict';
|
|
import path from 'node:path';
|
|
import { mockTauri, openPage, outputDir, runSmoke, smokeUrl } from '../_harness/index.mjs';
|
|
|
|
await runSmoke('settings/displayLanguage', async ({ browser }) => {
|
|
const output = await outputDir('settings/displayLanguage');
|
|
const context = await browser.newContext({ viewport: { width: 1100, height: 800 } });
|
|
await mockTauri(context, {
|
|
commands: test => ({
|
|
...test.workspace({
|
|
root: 'C:\\appearance-smoke',
|
|
files: Object.fromEntries(Array.from({ length: 12 }, (_, index) => [`theme-${index}.py`, `# Theme sample ${index}\ndef sample(parameter):\n return parameter\nname = "RuneStone"\nprint(name, 42)\n`])),
|
|
}),
|
|
plugins_snapshot: () => ({ root: 'C:/appearance-smoke-plugins', plugins: [] }),
|
|
'plugin:window|is_maximized': () => false,
|
|
}),
|
|
});
|
|
const settings = await openPage(context, { timeout: 15000 });
|
|
const main = await openPage(context, { timeout: 15000 });
|
|
const languagePicker = settings.locator('#language-picker');
|
|
const surfaceOpacity = () => settings.evaluate(() => getComputedStyle(document.documentElement).getPropertyValue('--rs-surface-opacity').trim());
|
|
await main.goto(smokeUrl);
|
|
await settings.goto(`${smokeUrl}/?settingsWindow=true`);
|
|
await languagePicker.waitFor();
|
|
for (const [language, name, heading, appearance, enabled, files] of [
|
|
['fr', 'Français', 'Paramètres', 'Apparence', 'Surfaces transparentes', 'Fichiers'],
|
|
['ja', '日本語', '設定', '外観', '背景を透過', 'ファイル'],
|
|
['zh-CN', '简体中文', '设置', '外观', '透明界面', '文件'],
|
|
['en', 'English', 'Settings', 'Appearance', 'Transparent surfaces', 'Files'],
|
|
]) {
|
|
await languagePicker.click();
|
|
await settings.getByRole('menuitemradio', { name, exact: true }).click();
|
|
await settings.getByRole('heading', { name: heading, exact: true }).waitFor();
|
|
await main.getByRole('button', { name: files, exact: true }).waitFor();
|
|
assert.equal(await settings.locator('html').getAttribute('lang'), language);
|
|
assert.equal(await main.locator('html').getAttribute('lang'), language);
|
|
assert.equal(await settings.evaluate(() => window.__TEST__.settings('language')), language);
|
|
await settings.reload();
|
|
await settings.getByRole('heading', { name: heading, exact: true }).waitFor();
|
|
// Arrow keys and Escape retain shared menu focus behavior.
|
|
await languagePicker.focus();
|
|
await settings.keyboard.press('Enter');
|
|
await settings.keyboard.press('End');
|
|
await settings.keyboard.press('Home');
|
|
await settings.keyboard.press('Escape');
|
|
assert(await languagePicker.evaluate(node => node === document.activeElement));
|
|
assert(await main.evaluate(async () => {
|
|
const { imageControls } = await import('/src/lib/editor/imageControls.ts');
|
|
const root = document.createElement('div'); root.innerHTML = '<img data-md-src="sample.png" alt="sample">'; document.body.append(root);
|
|
let removed = false;
|
|
const cleanup = imageControls(root, { remove: () => { removed = true; } });
|
|
root.querySelector('.md-image-frame').dispatchEvent(new KeyboardEvent('keydown', { key: 'Delete', bubbles: true }));
|
|
cleanup(); root.remove(); return removed;
|
|
}), `${language}: Delete image keyboard action`);
|
|
assert(await main.evaluate(async () => {
|
|
const { tableSelectionControls } = await import('/src/lib/editor/tableSelectionControls.ts');
|
|
const root = document.createElement('div'); root.innerHTML = '<div><table><tr><th>A</th><th>B</th></tr><tr><td>one</td><td>two</td></tr></table></div>'; document.body.append(root);
|
|
const wrapper = root.firstElementChild, table = root.querySelector('table');
|
|
let text = '| A | B |\n| --- | --- |\n| one | two |';
|
|
const view = { posAtDOM: () => 0, dom: root, focus() {} };
|
|
const controls = tableSelectionControls(root, wrapper, table, view, () => text, () => {}, next => { text = next; }, { get: () => undefined, activate() {}, editSource() {} }, {});
|
|
controls.select({ anchor: { row: 1, column: 0 }, head: { row: 1, column: 0 } });
|
|
wrapper.dispatchEvent(new KeyboardEvent('keydown', { key: 'Delete', bubbles: true }));
|
|
controls.destroy(); root.remove(); return !text.includes('one') && text.includes('two');
|
|
}), `${language}: Delete selected table cell keyboard action`);
|
|
await settings.screenshot({ path: path.join(output, `${language}-general.png`) });
|
|
await main.locator('[data-tree-rel="theme-0.py"]').click();
|
|
await main.locator('.monaco-editor textarea').waitFor();
|
|
await main.locator('.view-lines').first().click({ button: 'right' });
|
|
await main.locator('.rs-menu').waitFor();
|
|
const copyLabels = { fr: 'Copier', ja: 'コピー', 'zh-CN': '复制', en: 'Copy' };
|
|
await main.locator('.rs-menu .action-label').filter({ hasText: new RegExp('^' + copyLabels[language] + '$') }).waitFor();
|
|
await main.screenshot({ path: path.join(output, `${language}-workbench-editor-menu.png`) });
|
|
await main.keyboard.press('Escape');
|
|
await settings.getByRole('button', { name: appearance, exact: true }).click();
|
|
for (const mode of ['dark', 'light']) {
|
|
await settings.evaluate(async mode => {
|
|
const appearance = await import('/src/lib/theme/appearance.ts');
|
|
appearance.saveAppearance({ theme: 'default', mode, transparency: { enabled: true, amount: 18 } });
|
|
window.dispatchEvent(new Event('focus'));
|
|
}, mode);
|
|
const toggle = settings.getByRole('switch', { name: enabled, exact: true });
|
|
await toggle.uncheck();
|
|
assert.equal(await settings.locator('html').getAttribute('data-transparency'), 'off');
|
|
await main.waitForFunction(() => document.documentElement.dataset.transparency === 'off');
|
|
assert.equal(await surfaceOpacity(), '100%');
|
|
await settings.locator('.picker').first().click();
|
|
const bg = await settings.getByRole('menu').evaluate(node => getComputedStyle(node).backgroundColor);
|
|
assert(!bg.endsWith('/ 0.82)') && !bg.startsWith('rgba'), `Opaque menu: ${bg}`);
|
|
await settings.screenshot({ path: path.join(output, `${language}-${mode}-opaque-menu.png`) });
|
|
await settings.keyboard.press('Escape');
|
|
await toggle.check();
|
|
await settings.locator('#surface-transparency').fill('30');
|
|
assert.equal(await surfaceOpacity(), '70%');
|
|
await settings.setViewportSize({ width: 360, height: 640 });
|
|
await settings.locator('#surface-transparency').scrollIntoViewIfNeeded();
|
|
assert(await settings.locator('.content').evaluate(node => node.scrollWidth <= node.clientWidth), `${language} ${mode}: narrow overflow`);
|
|
await settings.screenshot({ path: path.join(output, `${language}-${mode}-narrow.png`) });
|
|
await settings.setViewportSize({ width: 1100, height: 800 });
|
|
}
|
|
await settings.reload();
|
|
}
|
|
assert.deepEqual([...settings.errors, ...main.errors], []);
|
|
console.log('PASS: 4 locales, persistence, cross-window updates, keyboard menu focus, both themes, opaque menus, transparency levels, narrow layout.');
|
|
});
|