feat: New theme + wire price adjustement

This commit is contained in:
gauvainboiche
2026-10-08 12:25:45 +02:00
parent aa9721ac2a
commit 1734487f1e
19 changed files with 348 additions and 88 deletions
+17 -14
View File
@@ -6,27 +6,33 @@ import { decode, encode } from '../public/js/services/storage.js';
import { loadContext } from './helpers.js';
const ctx = loadContext();
const themes = ['paperclip', 'witch'];
test('export then import restores the save and its theme', () => {
test('export then import restores the save', () => {
const state = createState(ctx);
state.funds = 42;
state.generators.gen1 = 7;
const text = buildExport('witch', state);
const imported = parseImport(text, ctx, themes);
assert.equal(imported.themeId, 'witch');
assert.equal(imported.state.funds, 42);
assert.equal(imported.state.generators.gen1, 7);
const imported = parseImport(buildExport(state), ctx);
assert.equal(imported.funds, 42);
assert.equal(imported.generators.gen1, 7);
});
test('the export does not depend on the theme', () => {
assert.equal('theme' in JSON.parse(buildExport(createState(ctx))), false);
});
test('first-version exports (with a theme field) still import', () => {
const legacy = { ...JSON.parse(buildExport(createState(ctx))), theme: 'witch' };
assert.equal(parseImport(JSON.stringify(legacy), ctx).units, 0);
});
test('import also accepts text with a BOM and surrounding whitespace (.txt files)', () => {
const text = ` \n${buildExport('paperclip', createState(ctx))}\n\n`;
assert.equal(parseImport(text, ctx, themes).themeId, 'paperclip');
const text = ` \n${buildExport(createState(ctx))}\n\n`;
assert.ok(parseImport(text, ctx));
});
const failure = (text) => {
try {
parseImport(text, ctx, themes);
parseImport(text, ctx);
} catch (error) {
assert.ok(error instanceof ImportError);
return error.code;
@@ -38,10 +44,7 @@ test('import rejects bad input with a specific code', () => {
assert.equal(failure(''), 'empty');
assert.equal(failure('not json'), 'invalid');
assert.equal(failure('{"hello":1}'), 'wrong_game');
const unknown = JSON.parse(buildExport('paperclip', createState(ctx)));
unknown.theme = 'dragons';
assert.equal(failure(JSON.stringify(unknown)), 'unknown_theme');
const broken = JSON.parse(buildExport('paperclip', createState(ctx)));
const broken = JSON.parse(buildExport(createState(ctx)));
broken.state = 'x';
assert.equal(failure(JSON.stringify(broken)), 'invalid');
});