okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
4fb068a8c
main
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' , () => { 10assert . equal ( DEFAULT_CONTENT_FS , 12 ); 11assert . equal ( DEFAULT_UI_SCALE , 0.9 ); 12const store = src ( 'src/lib/store.ts' ); 13assert . match ( store , / contentFontSize: DEFAULT_CONTENT_FS, / ); 14assert . match ( store , / uiScale: DEFAULT_UI_SCALE, / ); 15assert . match ( store , / contentFontSize: PREFS_DEFAULTS\.contentFontSize, [ \s\S ] * uiScale: PREFS_DEFAULTS\.uiScale, / , 'Reset appearance returns to the defaults, whatever they are' ); 16assert . 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' , () => { 20assert . deepEqual ( savedSizes ( null , MIN , MAX ), { contentFontSize :12 , uiScale :0.9 }); 21assert . deepEqual ( savedSizes ({}, MIN , MAX ), { contentFontSize :12 , uiScale :0.9 }); 22assert . deepEqual ( savedSizes ({ contentFontSize :18 , uiScale :1.25 }, MIN , MAX ), { contentFontSize :18 , uiScale :1.25 }, 'an old save that chose a size keeps it' ); 23assert . 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' , () => { 27assert . deepEqual ( savedSizes ({ contentFontSize :14 , uiScale :1 }, MIN , MAX ), { contentFontSize :12 , uiScale :0.9 }); 28const marked = { sizeDefaults :SIZE_DEFAULTS_VERSION }; 29assert . deepEqual ( savedSizes ({ ...marked , contentFontSize :14 , uiScale :1 }, MIN , MAX ), { contentFontSize :14 , uiScale :1 }, 'picked after the change: 14 px and 100% are a choice' ); 30assert . 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' , () => { 34assert . deepEqual ( savedSizes ({ contentFontSize :'big' , uiScale :7 }, MIN , MAX ), { contentFontSize :12 , uiScale :0.9 }); 35assert . equal ( savedSizes ({ sizeDefaults :SIZE_DEFAULTS_VERSION , contentFontSize :99 , uiScale :1 }, MIN , MAX ). contentFontSize , MAX ); 36assert . 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' , () => { 40const css = src ( 'src/styles/app.css' ); 41assert . match ( css , / --st-fs-read-sm: max\(12px, calc\(var\(--st-content-fs, 12px\) \* \.8125\)\); / ); 42assert . 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' , () => { 46const settings = src ( 'src/screens/Settings.tsx' ); 47assert . match ( settings , / value=\{prefs\.contentFontSize\} / ); 48assert . match ( settings , / value=\{String\(prefs\.uiScale\)\} / ); 49});