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.
70 lines
3.8 KiB
TypeScript
70 lines
3.8 KiB
TypeScript
import { test } from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
import { migrateLegacyPreferences } from '../../../src/lib/settings/migration.ts';
|
|
import { LEGACY_KEYS } from '../../../src/lib/settings/store.ts';
|
|
|
|
const palette = { bg: '#123', text: '#abcdef', accent: '#AABBCC' };
|
|
const reader = (values: Record<string, string>) => (key: string) => Object.hasOwn(values, key) ? values[key] : null;
|
|
|
|
test('Migration reads the four old keys and the theme backup, and normalizes each value', () => {
|
|
const custom = { schema: 2, id: 'night', name: 'Night', colors: { ...palette, bg: '#000000' } };
|
|
const sections = migrateLegacyPreferences(reader({
|
|
'runestone.settings': JSON.stringify({ autosaveEnabled: false, autosaveSeconds: 900, extra: true }),
|
|
'runestone.appearance': JSON.stringify({ theme: 'custom:night', mode: 'light', transparency: { amount: 140 } }),
|
|
'runestone.custom-themes': JSON.stringify([custom, { schema: 2, id: '../bad' }]),
|
|
'runestone.custom-themes.legacy': JSON.stringify([{ schema: 1, id: 'kept' }]),
|
|
'runestone.language': 'fr',
|
|
}));
|
|
assert.deepEqual(sections, {
|
|
general: { autosaveEnabled: false, autosaveSeconds: 5, showInternalFolder: false, tableFormulas: true, showFileTitle: true },
|
|
language: 'fr',
|
|
customThemes: [{ ...custom, schema: 3, mode: 'dark' }],
|
|
customThemesLegacy: [{ schema: 1, id: 'kept' }],
|
|
// The mode comes from the migrated custom theme, not from a store that is still empty.
|
|
appearance: { theme: 'custom:night', mode: 'dark', transparency: { enabled: true, amount: 100 } },
|
|
});
|
|
});
|
|
|
|
test('Migration of version 1 themes keeps the saved palette and adds the originals to the backup once', () => {
|
|
const legacy = { schema: 1, id: 'old', name: 'Old', light: { ...palette, bg: '#fff' }, dark: palette };
|
|
const sections = migrateLegacyPreferences(reader({
|
|
'runestone.appearance': JSON.stringify({ theme: 'custom:old', mode: 'light' }),
|
|
'runestone.custom-themes': JSON.stringify([legacy]),
|
|
'runestone.custom-themes.legacy': JSON.stringify([legacy]),
|
|
}));
|
|
assert.deepEqual(sections.customThemes, [{ schema: 3, id: 'old', name: 'Old', mode: 'light', colors: legacy.light }]);
|
|
assert.deepEqual(sections.customThemesLegacy, [legacy]);
|
|
assert.deepEqual(sections.appearance, { theme: 'custom:old', mode: 'light' });
|
|
});
|
|
|
|
test('Missing keys give no sections, so the defaults apply', () => {
|
|
assert.deepEqual(migrateLegacyPreferences(() => null), {});
|
|
assert.deepEqual(migrateLegacyPreferences(() => { throw new Error('Storage unavailable'); }), {});
|
|
});
|
|
|
|
test('Damaged old values become defaults and unknown languages become English', () => {
|
|
const sections = migrateLegacyPreferences(reader({
|
|
'runestone.settings': '{broken',
|
|
'runestone.appearance': '[1, 2]',
|
|
'runestone.custom-themes': '{"not":"a list"}',
|
|
'runestone.language': 'de',
|
|
}));
|
|
assert.deepEqual(sections, {
|
|
general: { autosaveEnabled: true, autosaveSeconds: 5, showInternalFolder: false, tableFormulas: true, showFileTitle: true },
|
|
language: 'en',
|
|
appearance: { theme: 'default', mode: 'dark' },
|
|
});
|
|
});
|
|
|
|
test('Migration keeps renamed theme IDs and a background image data URL', () => {
|
|
const image = 'data:image/png;base64,' + 'A'.repeat(40);
|
|
const sections = migrateLegacyPreferences(reader({
|
|
'runestone.appearance': JSON.stringify({ theme: 'holo', mode: 'dark', newTabBackground: { image, overlay: 0.4 } }),
|
|
}));
|
|
assert.deepEqual(sections.appearance, { theme: 'harvest-moon', mode: 'dark', newTabBackground: { image, overlay: 0.4, position: 'center', size: 'cover' } });
|
|
});
|
|
|
|
test('Every section has one old key', () => {
|
|
assert.deepEqual(Object.values(LEGACY_KEYS).sort(), ['runestone.appearance', 'runestone.custom-themes', 'runestone.custom-themes.legacy', 'runestone.language', 'runestone.settings']);
|
|
});
|