okami.mom/strata

git clone https://git.nkp.pet/okami.mom/strata

Niko1221rc1 merge ds-coder (d6a5a7837)4fb068a8c

main
3.3 KiB49 linesraw
1import test from 'node:test';
2import assert from 'node:assert/strict';
3import { readFileSync as read } from 'node:fs';
4import { DEFAULT_CONTENT_FS, DEFAULT_UI_SCALE, SIZE_DEFAULTS_VERSION, savedSizes } from '../src/lib/default-sizes.ts';
5
6const src = name => read(new URL(`../${name}`, import.meta.url), 'utf8');
7const MIN = 10, MAX = 22;
8
9test('the defaults are a 12 px reading size and a 90 percent interface', () => {
10  assert.equal(DEFAULT_CONTENT_FS, 12);
11  assert.equal(DEFAULT_UI_SCALE, 0.9);
12  const store = src('src/lib/store.ts');
13  assert.match(store, /contentFontSize: DEFAULT_CONTENT_FS,/);
14  assert.match(store, /uiScale: DEFAULT_UI_SCALE,/);
15  assert.match(store, /contentFontSize: PREFS_DEFAULTS\.contentFontSize,[\s\S]*uiScale: PREFS_DEFAULTS\.uiScale,/, 'Reset appearance returns to the defaults, whatever they are');
16  assert.doesNotMatch(src('src/styles/app.css'), /--st-content-fs, 14px/, 'the stylesheet fallbacks follow the new default');
17});
18
19test('nothing saved gives the defaults; a size the person chose stays', () => {
20  assert.deepEqual(savedSizes(null, MIN, MAX), { contentFontSize: 12, uiScale: 0.9 });
21  assert.deepEqual(savedSizes({}, MIN, MAX), { contentFontSize: 12, uiScale: 0.9 });
22  assert.deepEqual(savedSizes({ contentFontSize: 18, uiScale: 1.25 }, MIN, MAX), { contentFontSize: 18, uiScale: 1.25 }, 'an old save that chose a size keeps it');
23  assert.deepEqual(savedSizes({ contentFontSize: 11, uiScale: 1.1 }, MIN, MAX), { contentFontSize: 11, uiScale: 1.1 });
24});
25
26test('an old save that holds the old defaults moves to the new ones once, then everything is kept as saved', () => {
27  assert.deepEqual(savedSizes({ contentFontSize: 14, uiScale: 1 }, MIN, MAX), { contentFontSize: 12, uiScale: 0.9 });
28  const marked = { sizeDefaults: SIZE_DEFAULTS_VERSION };
29  assert.deepEqual(savedSizes({ ...marked, contentFontSize: 14, uiScale: 1 }, MIN, MAX), { contentFontSize: 14, uiScale: 1 }, 'picked after the change: 14 px and 100% are a choice');
30  assert.deepEqual(savedSizes({ ...marked, contentFontSize: 12, uiScale: 0.9 }, MIN, MAX), { contentFontSize: 12, uiScale: 0.9 });
31});
32
33test('a damaged save falls back to the defaults and the reading size stays inside its range', () => {
34  assert.deepEqual(savedSizes({ contentFontSize: 'big', uiScale: 7 }, MIN, MAX), { contentFontSize: 12, uiScale: 0.9 });
35  assert.equal(savedSizes({ sizeDefaults: SIZE_DEFAULTS_VERSION, contentFontSize: 99, uiScale: 1 }, MIN, MAX).contentFontSize, MAX);
36  assert.equal(savedSizes({ sizeDefaults: SIZE_DEFAULTS_VERSION, contentFontSize: 3, uiScale: 1 }, MIN, MAX).contentFontSize, MIN);
37});
38
39test('code keeps its 12 px floor, so at the default it is the size of the prose and stays apart by its font, bar and background', () => {
40  const css = src('src/styles/app.css');
41  assert.match(css, /--st-fs-read-sm: max\(12px, calc\(var\(--st-content-fs, 12px\) \* \.8125\)\);/);
42  assert.match(css, /\.st-bubble \.st-code pre, \.st-bubble \.st-code pre code, \.st-bubble \.st-code \.syntax-text \{ font-size: var\(--st-fs-read-sm\); \}/);
43});
44
45test('the Settings controls show the stored values as they are, with no second default of their own', () => {
46  const settings = src('src/screens/Settings.tsx');
47  assert.match(settings, /value=\{prefs\.contentFontSize\}/);
48  assert.match(settings, /value=\{String\(prefs\.uiScale\)\}/);
49});