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.
54 lines
3.3 KiB
TypeScript
54 lines
3.3 KiB
TypeScript
import { test } from "node:test";
|
|
import assert from "node:assert/strict";
|
|
import { DEFAULT_SETTINGS, SETTINGS_KEY, normalizeSettings, parseSettings, readSettings, saveSettings } from "../../../src/lib/workspace/settings.ts";
|
|
|
|
test("missing or damaged preferences keep safe defaults", () => {
|
|
for (const raw of [null, "{broken", "null", "[]", "42", '"text"']) {
|
|
assert.deepEqual(parseSettings(raw), DEFAULT_SETTINGS);
|
|
}
|
|
for (const autosaveSeconds of [0, -1, 301, 1.5, "10", null]) {
|
|
assert.deepEqual(parseSettings(JSON.stringify({ autosaveEnabled: false, autosaveSeconds, showInternalFolder: false })), { autosaveEnabled: false, autosaveSeconds: 5, showInternalFolder: false, tableFormulas: true, showFileTitle: true });
|
|
}
|
|
assert.deepEqual(parseSettings('{"autosaveEnabled":"false","autosaveSeconds":10}'), { autosaveEnabled: true, autosaveSeconds: 10, showInternalFolder: false, tableFormulas: true, showFileTitle: true });
|
|
});
|
|
|
|
function withStorage(storage: Pick<Storage, "getItem" | "setItem">, body: () => void) {
|
|
const prior = globalThis.localStorage;
|
|
try { globalThis.localStorage = storage as Storage; body(); }
|
|
finally { globalThis.localStorage = prior; }
|
|
}
|
|
|
|
test("preferences persist and load at both interval limits", () => {
|
|
const store = new Map<string, string>();
|
|
withStorage({ getItem: (key: string) => store.get(key) ?? null, setItem: (key: string, value: string) => { store.set(key, value); } }, () => {
|
|
for (const autosaveSeconds of [1, 23, 300]) {
|
|
const settings = { autosaveEnabled: false, autosaveSeconds, showInternalFolder: false, tableFormulas: autosaveSeconds !== 23, showFileTitle: autosaveSeconds !== 300 };
|
|
void saveSettings(settings);
|
|
assert.deepEqual(parseSettings(store.get(SETTINGS_KEY)!), settings);
|
|
assert.deepEqual(readSettings(), settings);
|
|
}
|
|
});
|
|
});
|
|
|
|
test("invalid changes never reach storage and storage failures reach the caller", () => {
|
|
let writes = 0;
|
|
withStorage({ getItem: () => null, setItem: () => { writes++; } }, () => {
|
|
for (const autosaveSeconds of [NaN, Infinity, 0, 301, 2.5]) {
|
|
assert.throws(() => saveSettings({ autosaveEnabled: true, autosaveSeconds, showInternalFolder: false, tableFormulas: true, showFileTitle: true }));
|
|
}
|
|
});
|
|
assert.equal(writes, 0);
|
|
withStorage({ getItem: () => null, setItem: () => { throw new Error("Storage unavailable"); } }, () => {
|
|
assert.throws(() => saveSettings({ ...DEFAULT_SETTINGS }), /Storage unavailable/);
|
|
});
|
|
});
|
|
|
|
test("stored values of any type normalize to safe settings", () => {
|
|
for (const value of [undefined, null, 42, "text", [], { autosaveSeconds: 0 }]) assert.deepEqual(normalizeSettings(value), DEFAULT_SETTINGS);
|
|
assert.deepEqual(normalizeSettings({ autosaveEnabled: false, autosaveSeconds: 9, showInternalFolder: true }), { autosaveEnabled: false, autosaveSeconds: 9, showInternalFolder: true, tableFormulas: true, showFileTitle: true });
|
|
assert.equal(normalizeSettings({ tableFormulas: false }).tableFormulas, false);
|
|
for (const tableFormulas of [null, 0, "false", {}]) assert.equal(normalizeSettings({ tableFormulas }).tableFormulas, true);
|
|
assert.equal(normalizeSettings({ showFileTitle: false }).showFileTitle, false);
|
|
for (const showFileTitle of [null, 0, "false", {}]) assert.equal(normalizeSettings({ showFileTitle }).showFileTitle, true);
|
|
});
|