Files
Strata/app/host/tests/reply-width.test.mjs
T
Niko1221 4058aa782b Layout move for 0.2.16: the top level becomes app/, engine/, terminal/, docs/, tools/ and .github/
Made by tools/layout/move_0216.py (the commit before this one) on db8e0be9c, the final code head of 0.2.16:
- 75 git mv (renames, so `git log --follow` and blame keep working; packaging/acceptance_matrix.md shows as delete + add because its links
  changed too) and 3 removals: SETUP.bat, UPDATE.bat and update.sh (setup.py --update pulls the code now);
- 1,425 path edits in 307 files: root-relative paths in CI, Docker, .gitignore and the release scripts; Markdown links; Python and
  Node joins from a root that moved with its folder; explicit edits for code that computes a root or names a moved path; tables of
  repository paths inside tests.

engine/ holds what CMake builds (src, include, cmake, metal, sycl, spark, third_party, the C++ tests and benches). app/ is the desktop
app and its host (was apps/). terminal/ is the Terminal in the layout of the installed one (strata.py, setup.py, strata_cli,
strata_control, serve, bin, data, ref, crates, the Python tools and tests). docs/ has the documentation, docs/lang/ the translated
READMEs, docs/history and docs/bench-results. tools/ has the repository's own checks, packaging, docker, research and nix.
tests/core/test_tqp_ref.py is a pytest file and stays with the Python tests (terminal/tests/core/).
AGENTS.md, README.md, LICENSE, setup.sh and START-HERE.bat stay at the root.

No behaviour change: the same command lines, the same sources. For this head a replay of the script gave the same numbers and the path
scan (tools/layout/checks/path_scan.py) reports no hit; the suites and the builds run on this commit next.
2026-11-17 13:19:21 +01:00

58 lines
3.7 KiB
JavaScript
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// #5066: a Reply width setting (Comfortable, Wide, Full width) in Settings > Reading & focus, default unchanged, through the one --st-measure token.
import test from 'node:test';
import assert from 'node:assert/strict';
import { readFileSync } from 'node:fs';
import { transform } from 'esbuild';
const src = name => readFileSync(new URL(`../src/${name}`, import.meta.url), 'utf8').replace(/\r\n/g, '\n');
const load = async name => {
const { code } = await transform(src(name), { loader: 'ts', format: 'esm' });
return import(`data:text/javascript;base64,${Buffer.from(code).toString('base64')}`);
};
const LANGS = ['en', 'zh', 'ja', 'de', 'es', 'ru', 'pt', 'ko', 'fr', 'he'];
const STRINGS = ['Reply width', 'How wide the text of an answer can be. Tables and code always use the whole width.', 'Wide', 'Full width'];
test('the choice is one of three words; anything else is the default (today\'s width)', async () => {
const { validReplyWidth, REPLY_WIDTHS, DEFAULT_REPLY_WIDTH } = await load('lib/reply-width.ts');
assert.deepEqual([...REPLY_WIDTHS], ['comfortable', 'wide', 'full']);
assert.equal(DEFAULT_REPLY_WIDTH, 'comfortable');
for (const v of REPLY_WIDTHS) assert.equal(validReplyWidth(v), v);
for (const v of [undefined, null, '', 'huge', 3, {}, 'WIDE']) assert.equal(validReplyWidth(v), 'comfortable');
});
test('the store keeps it with the other reading prefs, applies it to the page root, and resets it', () => {
const s = src('lib/store.ts');
assert.match(s, /replyWidth: 'comfortable',\n/);
assert.match(s, /replyWidth: validReplyWidth\(parsed\.replyWidth\),/, 'an old or damaged saved value falls back');
assert.match(s, /root\.dataset\.measure = state\.replyWidth;/);
assert.match(s, /replyWidth: state\.replyWidth,\n/, 'saved with the prefs');
assert.match(s, /replyWidth: PREFS_DEFAULTS\.replyWidth,/, 'Reset appearance puts it back');
assert.match(s, /export function setReplyWidth\(replyWidth: ReplyWidth\) \{\n set\(\{ replyWidth: validReplyWidth\(replyWidth\) \}\);\n savePrefs\(\);/);
});
test('the stylesheet moves only --st-measure (so Focus reading follows); Comfortable keeps 56ch', () => {
const css = src('styles/app.css');
assert.match(css, /--st-measure: 56ch;/);
assert.match(css, /:root\[data-measure='wide'\] \{ --st-measure: 72ch; \}/);
assert.match(css, /:root\[data-measure='full'\] \{ --st-measure: 400ch; \}/);
assert.doesNotMatch(css, /data-measure='comfortable'/);
assert.match(css, /max-width: calc\(var\(--st-measure\) \+ 72px\);/, 'the Focus reading column is built from the same token');
});
test('Settings > Reading & focus has the row with the three options', () => {
const settings = src('screens/Settings.tsx');
assert.ok(settings.includes("{ section: 'Reading & focus', label: 'Reply width', hint: 'How wide the text of an answer can be. Tables and code always use the whole width.'"));
assert.ok(settings.includes("options={[{ value: 'comfortable', label: 'Comfortable' }, { value: 'wide', label: 'Wide' }, { value: 'full', label: 'Full width' }]} onChange={setReplyWidth}"));
});
test('the four strings are in the catalog in all ten languages', () => {
const cat = Object.fromEntries(LANGS.map(l => [l, JSON.parse(readFileSync(new URL(`../src/locales/guic-${l}.json`, import.meta.url), 'utf8'))]));
for (const text of STRINGS) {
const key = Object.keys(cat.en).find(k => cat.en[k] === text);
assert.ok(key, `${text} is in guic-en.json`);
for (const l of LANGS) assert.ok(cat[l][key] && cat[l][key].trim(), `${l}: ${key}`);
assert.equal(/[^  ][;:?!]| [;:?!]/.test(cat.fr[key]), false, 'French: ; : ? ! only after a no-break space');
}
assert.match(cat.de[Object.keys(cat.en).find(k => cat.en[k] === 'Full width')], /^Volle Breite$/);
});