Files
oaktracker/legends-arceus/tests/tracker.test.mjs
T
FaroeGames 6b693cc3c6 Add Legends: Arceus tracker and bundle offline sprites on dev
Add standalone Pokémon Legends: Arceus POC tracker (Hisui 242 Pokédex, Research Tasks & RL10 mode, Satchel MP & Save Mythicals toggles, Noble/story battles, saves/movesets), bundle local sprite packs across all three trackers into Git/Docker/Nginx with attribution credits, and update Hub landing page & unified server/tests.
2026-11-17 17:53:59 -07:00

230 lines
10 KiB
JavaScript

import test from 'node:test';
import assert from 'node:assert/strict';
import http from 'node:http';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
import { SPECIES_LIST, SPECIES_BY_ID, HISUI_TOTAL_BASE, HISUI_TOTAL_MYTHICALS } from '../src/data/species.js';
import { SPECIES_MOVESETS } from '../src/data/movesets.js';
import { getGame } from '../src/data/games/index.js';
import {
computeGameProgress,
createTrackerStore,
getStarterChoiceState,
indexGameSpecies,
} from '../src/state/tracker-store.js';
import { createServer } from '../server.mjs';
import { renderHeader } from '../src/ui/header.js';
import { renderSidebar } from '../src/ui/sidebar.js';
import { renderRoutesView } from '../src/ui/routes-view.js';
import { renderPokedexView } from '../src/ui/pokedex-view.js';
import { renderGuideView } from '../src/ui/guide-view.js';
import { renderSpeciesModal } from '../src/ui/modal.js';
const __dirname = path.dirname(fileURLToPath(import.meta.url));
const APP_ROOT = path.resolve(__dirname, '..');
function makeMemoryStorage(initial = {}) {
const map = new Map(Object.entries(initial));
return {
getItem(k) {
return map.has(k) ? map.get(k) : null;
},
setItem(k, v) {
map.set(k, String(v));
},
removeItem(k) {
map.delete(k);
},
};
}
test('Hisui Pokédex data completeness: 242 entries with stats, research tasks, and movesets', () => {
assert.equal(HISUI_TOTAL_BASE, 240);
assert.equal(HISUI_TOTAL_MYTHICALS, 242);
assert.equal(SPECIES_LIST.length, 242);
for (const sp of SPECIES_LIST) {
assert.ok(SPECIES_BY_ID[sp.id], `Missing SPECIES_BY_ID[${sp.id}]`);
assert.ok(Array.isArray(sp.types) && sp.types.length >= 1, `Missing types for ${sp.id}`);
assert.ok(sp.baseStats?.hp > 0, `Missing baseStats for ${sp.id}`);
assert.ok(Array.isArray(sp.researchTasks) && sp.researchTasks.length >= 1, `Missing researchTasks for ${sp.id}`);
const ms = SPECIES_MOVESETS[sp.id];
assert.ok(ms && Array.isArray(ms.levelUp) && ms.levelUp.length >= 1, `Missing levelUp moveset for ${sp.id}`);
}
// Spot check Hisuian forms & PLA forms
assert.equal(SPECIES_BY_ID.decidueye.spriteId, 10244);
assert.deepEqual(SPECIES_BY_ID.decidueye.types, ['Grass', 'Fighting']);
assert.equal(SPECIES_BY_ID.growlithe.spriteId, 10229);
assert.equal(SPECIES_BY_ID.basculin.spriteId, 10247);
assert.equal(SPECIES_BY_ID.wyrdeer.hisuiId, 50);
assert.equal(SPECIES_BY_ID.shaymin.isMythicalSaveBonus, true);
assert.equal(SPECIES_BY_ID.darkrai.isMythicalSaveBonus, true);
});
test('Progression totals adapt dynamically for Satchel MP Shop, Save Mythicals, and RL10 Unown mode', () => {
const baseCaught = getGame('legends-arceus', { allowSatchelMp: false, includeSaveMythicals: false, researchMode: 'caught' });
const baseProg = computeGameProgress(baseCaught, new Set(), new Set(), 'caught');
assert.equal(baseProg.totalObtainable, 240);
assert.equal(baseProg.sections[0].newTotal, 78); // Pre-Kleavor
assert.equal(baseProg.sections[1].newTotal, 58); // Pre-Lilligant
// Enabling Satchel MP Shop moves Golem, Machamp, Scizor, Glaceon (+4) into Section 1 Pre-Kleavor
const mpCaught = getGame('legends-arceus', { allowSatchelMp: true, includeSaveMythicals: false, researchMode: 'caught' });
const mpProg = computeGameProgress(mpCaught, new Set(), new Set(), 'caught');
assert.equal(mpProg.totalObtainable, 240);
assert.equal(mpProg.sections[0].newTotal, 82);
assert.equal(mpProg.sections[1].newTotal, 54);
// Research Lv. 10 mode moves Unown completion from Section 2 to Section 5 (28/28 Unown Forms w/ Braviary)
const rl10Game = getGame('legends-arceus', { allowSatchelMp: false, includeSaveMythicals: false, researchMode: 'rl10' });
const rl10Prog = computeGameProgress(rl10Game, new Set(), new Set(), 'rl10');
assert.equal(rl10Prog.totalObtainable, 240);
assert.equal(rl10Prog.sections[1].newTotal, 57);
assert.equal(rl10Prog.sections[4].newTotal, 18);
// Enabling Save-Data Mythicals (+2) brings total to 242 in Section 6
const mythGame = getGame('legends-arceus', { allowSatchelMp: false, includeSaveMythicals: true, researchMode: 'caught' });
const mythProg = computeGameProgress(mythGame, new Set(), new Set(), 'caught');
assert.equal(mythProg.totalObtainable, 242);
assert.equal(mythProg.sections[5].newTotal, 22);
});
test('Starter exclusivity locks Section 1 unpicked starters while keeping Post-Game Section 6 totals invariant at 240', () => {
const store = createTrackerStore({ storage: makeMemoryStorage() });
// Pick Cyndaquil in Section 1
const ok = store.toggleCaught('cyndaquil', { sectionId: 'sec-1-kleavor', choiceOption: 'cyndaquil' });
assert.equal(ok, true);
// Rowlet in Section 1 is now locked, while Rowlet in Section 6 Post-Game is NOT locked
assert.ok(store.isStarterEntryLocked({ exclusiveGroup: 'pla-starter', choiceOption: 'rowlet' }, 'sec-1-kleavor'));
assert.equal(store.isStarterEntryLocked({ exclusiveGroup: 'pla-starter', choiceOption: 'rowlet' }, 'sec-6-postgame'), null);
const starterState = getStarterChoiceState(store.getGame(), store.getState().caught);
assert.equal(starterState.chosenStarter, 'cyndaquil');
const { earliestBySpecies } = indexGameSpecies(store.getGame(), store.getState().caught);
assert.equal(earliestBySpecies.get('cyndaquil').sectionId, 'sec-1-kleavor');
assert.equal(earliestBySpecies.get('rowlet').sectionId, 'sec-6-postgame');
assert.equal(earliestBySpecies.get('oshawott').sectionId, 'sec-6-postgame');
const prog = computeGameProgress(store.getGame(), store.getState().caught, store.getState().rl10, 'caught');
assert.equal(prog.totalObtainable, 240);
assert.equal(prog.sections[0].newTotal, 78);
assert.equal(prog.sections[5].newTotal, 20);
});
test('Caught & RL10 checkboxes sync accurately and persist across save profiles & JSON backup', () => {
const storage = makeMemoryStorage();
const store = createTrackerStore({ storage });
// Toggling RL10 automatically marks Caught too
store.toggleRl10('bidoof');
assert.equal(store.getState().caught.has('bidoof'), true);
assert.equal(store.getState().rl10.has('bidoof'), true);
// Unchecking Caught clears RL10
store.toggleCaught('bidoof');
assert.equal(store.getState().caught.has('bidoof'), false);
assert.equal(store.getState().rl10.has('bidoof'), false);
store.toggleRl10('starly');
store.setProgressMode('rl10');
store.setAllowSatchelMp(true);
store.setIncludeSaveMythicals(true);
store.toggleTrainerDefeated('sec-1-noble-kleavor');
const json = store.exportJson();
const profile2 = store.createProfile('Hisui RL10 Run');
assert.equal(store.getState().caught.size, 0);
const count = store.importJson(json);
assert.equal(count, 1);
assert.equal(store.getState().rl10.has('starly'), true);
assert.equal(store.getState().allowSatchelMp, true);
assert.equal(store.getState().includeSaveMythicals, true);
assert.equal(store.getState().defeatedTrainers.has('sec-1-noble-kleavor'), true);
const hdr = renderHeader(
store.getGame(),
store.getState(),
computeGameProgress(store.getGame(), store.getState().caught, store.getState().rl10, store.getState().progressMode),
store.getProfilesWithCounts(),
);
assert.ok(hdr.includes('href="../"'));
assert.ok(hdr.includes('https://git.trevorstocks.ca/FaroeGames/oaktracker/issues'));
assert.ok(hdr.includes('app-header version-pla'));
assert.ok(hdr.includes('class="select-input select-sm profile-select"'));
assert.ok(hdr.includes('class="btn-ghost btn-xs"'));
store.setSelectedSpeciesId('wyrdeer');
const modalHtml = renderSpeciesModal(store.getGame(), store.getState());
assert.ok(modalHtml.includes('Research Tasks'));
assert.ok(modalHtml.includes('Psyshield Bash'));
assert.ok(modalHtml.includes('class="modal-header-actions"'));
assert.ok(modalHtml.includes('btn-caught-lg'));
assert.ok(modalHtml.includes('stat-bars-grid'));
assert.ok(modalHtml.includes('research-tasks-table'));
const routesHtml = renderRoutesView(
store.getGame(),
store.getState(),
computeGameProgress(store.getGame(), store.getState().caught, store.getState().rl10, store.getState().progressMode),
);
assert.ok(routesHtml.includes('Pre-Kleavor') || routesHtml.includes('Obsidian Fieldlands'));
assert.ok(routesHtml.includes('data-toggle-rl10='));
assert.ok(routesHtml.includes('area-collapse-btn'));
assert.ok(routesHtml.includes('class="method-header"'));
assert.ok(routesHtml.includes('encounter-row'));
assert.ok(routesHtml.includes('rl10-chip-btn'));
const dexHtml = renderPokedexView(store, store.getState());
assert.ok(dexHtml.includes('Decidueye'));
assert.ok(dexHtml.includes('pill-btn'));
assert.ok(dexHtml.includes('ext-menu-trigger'));
const guideHtml = renderGuideView(store.getGame());
assert.ok(guideHtml.includes('Satchel MP Shop is ON'));
const sidebarHtml = renderSidebar(
store.getGame(),
store.getState(),
computeGameProgress(store.getGame(), store.getState().caught, store.getState().rl10, store.getState().progressMode),
);
assert.ok(sidebarHtml.includes('Noble Checkpoints (RL10)'));
assert.ok(profile2.id);
});
test('Legends: Arceus standalone HTTP server serves app assets and blocks traversal', async () => {
const server = await createServer({ rootDir: APP_ROOT });
await new Promise((resolve) => server.listen(0, '127.0.0.1', resolve));
const { port } = server.address();
try {
const res = await fetch(`http://127.0.0.1:${port}/`);
assert.equal(res.status, 200);
const html = await res.text();
assert.ok(html.includes('Pokémon Legends: Arceus'));
const statusRes = await fetch(`http://127.0.0.1:${port}/api/assets-status`);
assert.equal(statusRes.status, 200);
const statusJson = await statusRes.json();
assert.equal(typeof statusJson.hasLocalSprites, 'boolean');
const badStatus = await new Promise((resolve, reject) => {
const req = http.request(
{ hostname: '127.0.0.1', port, path: '/../../package.json', method: 'GET' },
(r) => { r.resume(); resolve(r.statusCode); },
);
req.on('error', reject);
req.end();
});
assert.equal(badStatus, 403);
} finally {
await new Promise((resolve) => server.close(resolve));
}
});