mirror of
https://github.com/wekan/wekan.git
synced 2026-11-25 04:49:41 -05:00
Their line read "Admin Panel -> Problems -> database" (and integrity, mail): STREAM_LABEL_KEY had no entry for them. They now say Database problems, Filesystem integrity and Email, the keys their panes have in the Problems menu, and a test requires every stream of EVENT_STREAMS to have the same name there as in the menu. Thanks to xet7 !
94 lines
5.2 KiB
JavaScript
94 lines
5.2 KiB
JavaScript
'use strict';
|
|
// Admin Panel / Problems / Summary (2026-11-19, .tools/log/wekan10): "1 new
|
|
// problems" did not agree with its number, Data health's "Last Run: ... - 8/31"
|
|
// did not say what 8 and 31 were, and the menu said "Memory Usage" beside
|
|
// "CPU usage" and "Disk usage". Each label is now one translated sentence with
|
|
// its numbers as placeholders, in every locale.
|
|
// Run: node --test tests/problemsSummaryLabels.test.cjs
|
|
const test = require('node:test');
|
|
const assert = require('node:assert');
|
|
const fs = require('node:fs');
|
|
const path = require('node:path');
|
|
|
|
const ROOT = path.join(__dirname, '..');
|
|
const DIR = path.join(ROOT, 'imports/i18n/data');
|
|
const read = rel => fs.readFileSync(path.join(ROOT, rel), 'utf8');
|
|
const locales = fs.readdirSync(DIR).filter(f => f.endsWith('.i18n.json')
|
|
&& !fs.lstatSync(path.join(DIR, f)).isSymbolicLink());
|
|
const load = f => JSON.parse(fs.readFileSync(path.join(DIR, f), 'utf8'));
|
|
const tokens = s => (s.match(/__[A-Za-z0-9]+__|%\d*\$?[sd]/g) || []).sort();
|
|
const en = load('en.i18n.json');
|
|
|
|
test('the summary counts problems and checks through one sentence each', () => {
|
|
const jade = read('client/components/settings/problemsSummary.jade');
|
|
assert.match(jade, /span\.admin-problem-count \{\{_ 'new-problems-count' count=area\.count\}\}/);
|
|
const js = read('client/components/settings/problemsSummary.js');
|
|
const at = js.indexOf('dataHealthStatus() {');
|
|
const body = js.slice(at, js.indexOf('\n },', at));
|
|
assert.match(body, /TAPi18n\.__\('data-health-checks-found', \{ found: d\.found, checks: d\.checks \}\)/);
|
|
assert.strictEqual(en['new-problems-count'], 'New problems: __count__');
|
|
assert.strictEqual(en['data-health-checks-found'], 'Checks with findings: __found__ / __checks__');
|
|
assert.strictEqual(en['memory-usage'], 'Memory usage');
|
|
});
|
|
|
|
test('negative: no bare number is glued to a label any more', () => {
|
|
const jade = read('client/components/settings/problemsSummary.jade');
|
|
assert.doesNotMatch(jade, /\{\{area\.count\}\} \{\{_ 'new-problems'\}\}/);
|
|
const js = read('client/components/settings/problemsSummary.js');
|
|
assert.doesNotMatch(js, /\$\{d\.found\}\/\$\{d\.checks\}/);
|
|
});
|
|
|
|
test('every locale has both sentences, in order, with exactly the English placeholders', () => {
|
|
assert.ok(locales.length > 200);
|
|
for (const f of locales) {
|
|
const j = load(f);
|
|
const keys = Object.keys(j);
|
|
for (const [key, anchor] of [['new-problems-count', 'new-problems'],
|
|
['data-health-checks-found', 'data-health-never-run']]) {
|
|
assert.ok(typeof j[key] === 'string' && j[key].trim(), `${f}: ${key}`);
|
|
assert.deepStrictEqual(tokens(j[key]), tokens(en[key]), `${f}: ${key} placeholders`);
|
|
assert.strictEqual(keys.indexOf(key), keys.indexOf(anchor) + 1, `${f}: ${key} after ${anchor}`);
|
|
if (!f.startsWith('en')) assert.notStrictEqual(j[key], en[key], `${f}: ${key} is translated`);
|
|
}
|
|
}
|
|
});
|
|
|
|
test('negative: "Memory usage" is no longer wrong-language or split in these locales', () => {
|
|
const fixed = { lv: 'Atmiņas lietojums', nl: 'Geheugengebruik', fy: 'Unthâldgebrûk',
|
|
tl: 'Paggamit ng memorya', tn: 'Tiriso ya segopotso', yo: 'Lílo ìrántí' };
|
|
for (const [tag, value] of Object.entries(fixed)) {
|
|
assert.strictEqual(load(`${tag}.i18n.json`)['memory-usage'], value, tag);
|
|
}
|
|
assert.doesNotMatch(load('ay.i18n.json')['memory-usage'], /Memory|Aymar aruna/);
|
|
// Latvian had Lithuanian text.
|
|
assert.doesNotMatch(load('lv.i18n.json')['memory-usage'], /Atminties|naudojimas/);
|
|
for (const f of locales.filter(n => n.startsWith('en'))) {
|
|
assert.strictEqual(load(f)['memory-usage'], 'Memory usage', f);
|
|
}
|
|
});
|
|
|
|
// Every problem stream is named on Summary by its pane's own name. database,
|
|
// integrity and mail had no entry, so their line read "Admin Panel ->
|
|
// Problems -> database" (2026-11-24).
|
|
test('every problem stream has the name of its pane on Summary', () => {
|
|
const streams = JSON.parse(read('models/eventLog.js').match(/export const EVENT_STREAMS = (\[[^\]]*\])/)[1].replace(/'/g, '"'));
|
|
const js = read('client/components/settings/problemsSummary.js');
|
|
const map = js.slice(js.indexOf('const STREAM_LABEL_KEY = {'), js.indexOf('\n};', js.indexOf('const STREAM_LABEL_KEY = {')));
|
|
const labelOf = Object.fromEntries([...map.matchAll(/^\s+(\w+): '([^']+)',/gm)].map(m => [m[1], m[2]]));
|
|
const menu = read('client/components/settings/adminProblems.js');
|
|
for (const stream of streams) {
|
|
assert.ok(labelOf[stream], `${stream} has no name on Summary`);
|
|
const entry = menu.match(new RegExp(`id: 'report-${stream}'[^}]*labelKey: '([^']+)'`));
|
|
assert.ok(entry, `the Problems menu has a report-${stream} pane`);
|
|
assert.strictEqual(labelOf[stream], entry[1], `${stream}: Summary and the menu name it the same`);
|
|
assert.ok(en[labelOf[stream]], `${labelOf[stream]} is in the English catalog`);
|
|
}
|
|
assert.deepStrictEqual(streams.slice(-3), ['database', 'integrity', 'mail']);
|
|
});
|
|
|
|
test('negative: no stream falls back to its id on Summary', () => {
|
|
const js = read('client/components/settings/problemsSummary.js');
|
|
// The fallback stays for a stream added later, but the test above makes it unreachable today.
|
|
assert.match(js, /TAPi18n\.__\(STREAM_LABEL_KEY\[stream\] \|\| stream\)/);
|
|
});
|