feat: New features (research, invest, gambling, new game+, trophies)
This commit is contained in:
+71
-1
@@ -2,7 +2,7 @@
|
||||
// missing translation is caught by `npm test` instead of showing a raw key.
|
||||
|
||||
import assert from 'node:assert/strict';
|
||||
import { readdirSync } from 'node:fs';
|
||||
import { readdirSync, readFileSync } from 'node:fs';
|
||||
import { test } from 'node:test';
|
||||
import { flatKeys, loadContext, PUBLIC_DIR, readJson } from './helpers.js';
|
||||
|
||||
@@ -49,6 +49,12 @@ test('every theme names every resource, generator and upgrade, in every language
|
||||
'theme.action.buyMaterial',
|
||||
...ctx.generators.flatMap((g) => [`theme.gen.${g.id}.name`, `theme.gen.${g.id}.desc`]),
|
||||
...ctx.upgrades.map((u) => `theme.upg.${u.id}`),
|
||||
'theme.tab.gamble',
|
||||
'theme.action.gamble',
|
||||
'theme.res.chips',
|
||||
'theme.res.research',
|
||||
'theme.res.legacy',
|
||||
...ctx.investments.societies.map((s) => `theme.inv.${s.id}.name`),
|
||||
];
|
||||
|
||||
for (const id of themes) {
|
||||
@@ -68,3 +74,67 @@ test('every theme is translated in every core language', () => {
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// ------------------------------------------------- the new systems' vocabulary
|
||||
|
||||
const coreKeys = new Set(flatKeys(readJson('locales/en.json')));
|
||||
const coreHas = (key) => coreKeys.has(key);
|
||||
|
||||
test('every effect type used anywhere has a text', () => {
|
||||
const effects = [
|
||||
...ctx.upgrades.map((u) => u.effect),
|
||||
...ctx.research.map((r) => r.effect),
|
||||
...ctx.legacy.map((p) => p.effect),
|
||||
...ctx.achievements.map((a) => a.effect),
|
||||
];
|
||||
for (const e of effects) assert.ok(coreHas(`effect.${e.type}`), `effect.${e.type}`);
|
||||
});
|
||||
|
||||
test('research, perks, achievements, events, contracts and tiers all have core texts', () => {
|
||||
const need = [
|
||||
...ctx.research.map((r) => `research.node.${r.id}`),
|
||||
...[...new Set(ctx.research.map((r) => r.branch))].map((b) => `research.branch.${b}`),
|
||||
...ctx.legacy.map((p) => `legacy.perk.${p.id}`),
|
||||
...ctx.achievements.map((a) => `ach.title.${a.id}`),
|
||||
...[...new Set(ctx.achievements.map((a) => a.condition.stat))].map((s) => `ach.cond.${s}`),
|
||||
...ctx.rules.events.types.flatMap((e) => [`event.${e.id}.title`, `event.${e.id}.text`]),
|
||||
...ctx.rules.contracts.templates.map((c) => `contracts.template.${c.id}`),
|
||||
...ctx.rules.contracts.rewards.map((r) => `contracts.reward.${r}`),
|
||||
...Object.keys(ctx.investments.tiers).map((tier) => `invest.tier.${tier}`),
|
||||
...['win', 'jackpot', 'lose', 'crash'].map((o) => `gamble.result.${o}`),
|
||||
];
|
||||
for (const key of need) assert.ok(coreHas(key), key);
|
||||
});
|
||||
|
||||
test('every section has a label (core, or themed for the gamble)', () => {
|
||||
for (const tab of ctx.tabs) {
|
||||
assert.ok(coreHas(`tab.${tab.id}`) || tab.id === 'gamble', `tab.${tab.id}`);
|
||||
}
|
||||
});
|
||||
|
||||
test('every key used by the code and the page exists', () => {
|
||||
const themeKeys = new Set(flatKeys(readJson('themes/paperclip/locales/en.json')));
|
||||
const known = (key) => coreKeys.has(key) || themeKeys.has(key);
|
||||
|
||||
const used = new Set();
|
||||
const walk = (dir) => {
|
||||
for (const entry of readdirSync(dir, { withFileTypes: true })) {
|
||||
const path = `${dir}/${entry.name}`;
|
||||
if (entry.isDirectory()) walk(path);
|
||||
else if (entry.name.endsWith('.js')) {
|
||||
for (const m of readFileSync(path, 'utf8').matchAll(/\bt\(\s*'([\w.]+)'/g)) used.add(m[1]);
|
||||
}
|
||||
}
|
||||
};
|
||||
walk(`${PUBLIC_DIR}js`);
|
||||
|
||||
const html = readFileSync(`${PUBLIC_DIR}index.html`, 'utf8');
|
||||
for (const m of html.matchAll(/data-i18n="([\w.]+)"/g)) used.add(m[1]);
|
||||
for (const m of html.matchAll(/data-i18n-attr="([^"]+)"/g)) {
|
||||
for (const pair of m[1].split(';')) used.add(pair.split(':')[1].trim());
|
||||
}
|
||||
|
||||
const missing = [...used].filter((key) => !known(key));
|
||||
assert.deepEqual(missing, [], `texts used but not defined: ${missing.join(', ')}`);
|
||||
assert.ok(used.size > 100, 'the scan found the texts');
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user