BlueGit

projects-timfalken-com meteors

Files

meteors / test / offline-defeated.test.js

offline-defeated.test.js

offline-defeated.test.js 2.3 KiB Download Raw
1'use strict';
2
3// t1198: Offline Strijd result shows "X opponents defeated" over all rounds.
4
5const { describe, it } = require('node:test');
6const assert = require('node:assert/strict');
7const { makeGame, Planet, Rng } = require('./helpers.js');
8const Offline = require('../src/offline.js');
9const I18n = require('../src/i18n.js');
10
11function knockOutAll (battle, player)
12{
13 for (const b of battle.bots) b.core.state = 'gameover';
14 battle.tick(0.016, player);
15}
16
17describe('Offline defeated counter (t1198)', () =>
18{
19 it('counts every opponent knocked out, across rounds, once each', () =>
20 {
21 const battle = Offline.createBattle({ playerPlanet: Planet.defaultPlanet(), rng: Rng.create(3), round: 1 });
22 const player = makeGame({ noSpawn: true });
23 assert.equal(battle.defeated, 0);
24 knockOutAll(battle, player); // round 1: 1 bot
25 assert.equal(battle.state, 'round_won');
26 assert.equal(battle.defeated, 1);
27 battle.tick(0.016, player); // no double count
28 assert.equal(battle.defeated, 1);
29 battle.advanceRound(); // round 2: 2 bots
30 const n2 = battle.bots.length;
31 battle.bots[0].core.state = 'gameover';
32 battle.tick(0.016, player);
33 assert.equal(battle.defeated, 2, 'one of round 2 out');
34 player.state = 'gameover'; // player loses round 2
35 battle.tick(0.016, player);
36 assert.equal(battle.state, 'lost');
37 assert.equal(battle.defeated, 2, 'remaining bots of the lost round are not counted');
38 assert.ok(n2 >= 2);
39 });
40
41 it('i18n: singular / plural in every language, no skill line left', () =>
42 {
43 const cat = require('../server/lib/i18n.json');
44 for (const loc of cat.localeIds)
45 {
46 I18n.setLocale ? I18n.setLocale(loc) : (I18n.locale = loc);
47 const one = I18n.plural('offline.defeated', 1, { n: 1 });
48 const many = I18n.plural('offline.defeated', 7, { n: 7 });
49 assert.ok(one.includes('1') && many.includes('7'), loc + ': ' + one + ' / ' + many);
50 assert.equal(cat.locales[loc]['offline.detail'], undefined, loc + ' old detail removed');
51 }
52 I18n.setLocale ? I18n.setLocale('nl') : (I18n.locale = 'nl');
53 assert.equal(I18n.plural('offline.defeated', 1, { n: 1 }), '1 tegenstander verslagen');
54 assert.equal(I18n.plural('offline.defeated', 3, { n: 3 }), '3 tegenstanders verslagen');
55 I18n.setLocale ? I18n.setLocale('en') : (I18n.locale = 'en');
56 });
57});