Files
wekan/tests/ruleDetailsLocalization.test.cjs
T
Lauri Ojansivu 793f760ea8 Fix alltests fixtures and HTTP cookie assertions
Exclude generated Playwright artifacts from documentation coverage, follow current Finnish translations, keep report fixtures within display limits and provide valid attachment metadata. Require the named HttpOnly login cookie on both transports and Secure on HTTPS.

All 790 Node suites and 15 targeted HTTP/HTTPS browser checks pass.

Thanks to xet7.
2026-09-07 20:13:04 +03:00

69 lines
3.0 KiB
JavaScript

'use strict';
const assert = require('assert');
const fs = require('fs');
const path = require('path');
const root = path.resolve(__dirname, '..');
const read = relative => fs.readFileSync(path.join(root, relative), 'utf8');
const en = JSON.parse(read('imports/i18n/data/en.i18n.json'));
const fi = JSON.parse(read('imports/i18n/data/fi.i18n.json'));
// Load the dependency-free ES module through a data URL, as the existing Node
// suites do for pure model helpers without asking Meteor to boot.
const moduleSource = read('models/lib/ruleDescriptionLocalization.js');
(async () => {
const encoded = Buffer.from(moduleSource).toString('base64');
const { localizeStoredRuleDescription } = await import(
`data:text/javascript;base64,${encoded}`
);
const translations = Object.keys(en)
.filter(key => key.startsWith('r-'))
.map(key => ({ source: en[key], translated: fi[key] }));
assert.strictEqual(
localizeStoredRuleDescription('Move card to top of its list', translations),
fi['r-d-move-to-top-gen'],
'a whole action uses its natural Finnish sentence',
);
assert.strictEqual(localizeStoredRuleDescription('by', translations), fi['r-by'],
'the current human translation remains authoritative');
// Pin the grammar used by the boundary examples independently of future
// Transifex wording; these assertions test replacement boundaries, not a
// translator's choice of the Finnish rendering of the ambiguous word 'by'.
const fragmentTranslations = [...translations, { source: 'by', translated: 'tekijänä' }];
assert.strictEqual(
localizeStoredRuleDescription(
'when a card is moved to archive by *',
fragmentTranslations,
),
'kun kortti on siirretty arkistoon tekijänä *',
'an assembled legacy trigger is translated piece by piece',
);
assert.strictEqual(
localizeStoredRuleDescription('when a card is moved by byron', fragmentTranslations),
'kun kortti on siirretty tekijänä byron',
'a short rule word is translated without changing a username containing it',
);
assert.strictEqual(localizeStoredRuleDescription('', translations), '',
'an absent legacy description remains harmless');
assert.strictEqual(localizeStoredRuleDescription('Custom opaque value', []),
'Custom opaque value', 'unknown imported prose is preserved');
const details = read('client/components/rules/ruleDetails.js');
assert.match(details, /getDefaultTranslations\('r-'\)/,
'rule details use the complete canonical rule vocabulary');
assert.match(details, /localizeStoredRuleDescription\(description, translations\)/,
'both trigger and action pass through the common localizer');
const tap = read('imports/i18n/tap.js');
assert.match(tap, /getDefaultTranslations\(prefix = ''\)/,
'the canonical English source is exposed without another static data import');
console.log('ruleDetailsLocalization: Finnish legacy descriptions passed');
})().catch(error => {
console.error(error);
process.exitCode = 1;
});