| 1 | 'use strict'; |
| 2 | |
| 3 | // t1201: "Play" starts the rounds against bots (internal 'offline'), |
| 4 | // "Survival" starts endless solo (internal 'solo'). Labels in all locales. |
| 5 | |
| 6 | const { describe, it } = require('node:test'); |
| 7 | const assert = require('node:assert/strict'); |
| 8 | const fs = require('fs'); |
| 9 | const path = require('path'); |
| 10 | |
| 11 | const root = path.join(__dirname, '..'); |
| 12 | const html = fs.readFileSync(path.join(root, 'build/index.html'), 'utf8'); |
| 13 | const main = fs.readFileSync(path.join(root, 'src/main.js'), 'utf8'); |
| 14 | const cat = require('../server/lib/i18n.json'); |
| 15 | |
| 16 | function fnBody (name) |
| 17 | { |
| 18 | const i = main.indexOf('function ' + name + ' ('); |
| 19 | assert.ok(i >= 0, name + ' exists'); |
| 20 | return main.slice(i, main.indexOf('\n}\n', i)); |
| 21 | } |
| 22 | |
| 23 | describe('Main menu modes (t1201)', () => |
| 24 | { |
| 25 | it('menu has Play + Survival, no Offline Battle button', () => |
| 26 | { |
| 27 | assert.match(html, /id="btn-play"[^>]*data-i18n="menu.play"/); |
| 28 | assert.match(html, /id="btn-survival"[^>]*data-i18n="menu.survival"/); |
| 29 | assert.ok(!/id="btn-offline"/.test(html)); |
| 30 | assert.ok(!/menu\.offline/.test(html + main)); |
| 31 | }); |
| 32 | |
| 33 | it('Play opens the bot-rounds planet select, Survival the endless solo one', () => |
| 34 | { |
| 35 | assert.match(fnBody('onPlay'), /openPlanetSelect\('offline'\)/); |
| 36 | assert.match(fnBody('onSurvival'), /openPlanetSelect\('solo'\)/); |
| 37 | assert.match(main, /getElementById\('btn-survival'\)[\s\S]{0,200}onSurvival/); |
| 38 | assert.ok(!/function onOffline/.test(main)); |
| 39 | }); |
| 40 | |
| 41 | it('Survival is translated in every language; old name keys are gone', () => |
| 42 | { |
| 43 | const want = { en: 'Survival', nl: 'Overleven', de: 'Überleben', fr: 'Survie', es: 'Supervivencia', pl: 'Przetrwanie', ru: 'Выживание' }; |
| 44 | for (const loc of cat.localeIds) |
| 45 | { |
| 46 | const L = cat.locales[loc]; |
| 47 | assert.ok(L['menu.survival'], loc + ' menu.survival'); |
| 48 | if (want[loc]) assert.equal(L['menu.survival'], want[loc]); |
| 49 | assert.equal(L['menu.offline'], undefined, loc + ' menu.offline removed'); |
| 50 | assert.notEqual(L['menu.survival'], L['menu.play'], loc); |
| 51 | } |
| 52 | }); |
| 53 | |
| 54 | it('no player-facing text still names the old "Offline Battle" mode or "solo" play', () => |
| 55 | { |
| 56 | const old = /Offline Strijd|Offline Battle|Offline-Kampf|Combat hors ligne|Combate sin conexión|Walka offline|Офлайн-бой|オフライン対戦|离线对战|오프라인 대결|play solo|alleen spelen|jouer en solo|en solitario|allein spielen/i; |
| 57 | for (const loc of cat.localeIds) |
| 58 | for (const [k, v] of Object.entries(cat.locales[loc])) |
| 59 | assert.ok(!old.test(v), loc + ' ' + k + ': ' + v); |
| 60 | assert.equal(cat.locales.nl['offline.resultTitle'], 'Uitslag'); |
| 61 | assert.equal(cat.locales.en['offline.resultTitle'], 'Results'); |
| 62 | const visible = html.replace(/<!--[\s\S]*?-->/g, '').replace(/<script[\s\S]*?<\/script>/g, ''); |
| 63 | assert.ok(!/Offline Battle|play solo/i.test(visible), 'index.html fallbacks updated'); |
| 64 | }); |
| 65 | |
| 66 | it('mode labels: planet select and pause menu name the mode', () => |
| 67 | { |
| 68 | assert.match(html, /id="planet-mode"/); |
| 69 | assert.match(html, /id="game-menu-mode"/); |
| 70 | const body = fnBody('modeLabel'); |
| 71 | assert.match(body, /'offline' \? 'menu.play'/); |
| 72 | assert.match(body, /'menu.survival'/); |
| 73 | }); |
| 74 | }); |
projects-timfalken-com meteors