import test from 'node:test'; import assert from 'node:assert/strict'; import http from 'node:http'; import { SPECIES_LIST, SPECIES_BY_ID } from '../src/data/species.js'; import { getPokemonMoveset, ORAS_MOVES } from '../src/data/movesets.js'; import { getExternalLinksForSpecies } from '../src/ui/external-links.js'; import { ALPHA_SAPPHIRE_DATA } from '../src/data/games/alpha-sapphire.js'; import { ALPHA_SAPPHIRE_TRAINERS_BY_AREA } from '../src/data/games/alpha-sapphire-trainers.js'; import { getGame, listGames } from '../src/data/games/index.js'; import { createTrackerStore, computeGameProgress, getExclusiveChoiceState, indexGameSpecies, isSpeciesSoloAvailableForGame, } from '../src/state/tracker-store.js'; 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 { renderProfileModal, renderSpeciesModal } from '../src/ui/modal.js'; import { extractItemsFromText, getPokemonSpriteUrls, POKEAPI_SPRITES_CDN, setSpriteBaseUrl, } from '../src/ui/sprites.js'; import { createStaticServer } from '../server.mjs'; function createMemoryStorage() { const map = new Map(); return { getItem: (k) => (map.has(k) ? map.get(k) : null), setItem: (k, v) => map.set(k, String(v)), removeItem: (k) => map.delete(k), }; } test('species catalog has unique ids, valid evolvesFrom, and complete Hoenn Dex 1..211', () => { const seenIds = new Set(); const seenNatIds = new Set(); const hoennNums = new Set(); for (const sp of SPECIES_LIST) { assert.ok(sp.id && !seenIds.has(sp.id), `Duplicate or empty species id: ${sp.id}`); seenIds.add(sp.id); assert.ok(Number.isInteger(sp.natId) && sp.natId > 0 && sp.natId <= 721, `Invalid natId for ${sp.id}: ${sp.natId}`); assert.ok(!seenNatIds.has(sp.natId), `Duplicate natId ${sp.natId} (${sp.id})`); seenNatIds.add(sp.natId); if (sp.hoennId !== null) { assert.ok(sp.hoennId >= 1 && sp.hoennId <= 211, `Out of range hoennId ${sp.hoennId} for ${sp.id}`); assert.ok(!hoennNums.has(sp.hoennId), `Duplicate hoennId ${sp.hoennId} (${sp.id})`); hoennNums.add(sp.hoennId); } if (sp.evolvesFrom) { assert.ok(SPECIES_BY_ID[sp.evolvesFrom], `Missing evolvesFrom "${sp.evolvesFrom}" on ${sp.id}`); } assert.ok(Array.isArray(sp.types) && sp.types.length > 0, `Missing types on ${sp.id}`); } assert.equal(hoennNums.size, 211, 'Hoenn Dex must contain all 211 entries'); for (let i = 1; i <= 211; i++) { assert.ok(hoennNums.has(i), `Missing Hoenn Dex #${i}`); } }); test('Alpha Sapphire and Omega Ruby datasets reference valid species, enforce version exclusives, and cover all solo species', () => { const games = listGames(); assert.equal(games.length, 2); for (const game of games) { assert.equal(game.sections.length, 10); const forbiddenAvailability = game.id === 'omega-ruby' ? 'as-only' : 'or-only'; const referenced = new Set(); for (const section of game.sections) { assert.ok(section.areas.length > 0, `Section ${section.id} has no areas in ${game.id}`); for (const area of section.areas) { assert.ok( area.groups.length > 0 || (Array.isArray(area.trainers) && area.trainers.length > 0), `Area ${area.id} has neither encounter groups nor trainers in ${game.id}`, ); for (const group of area.groups) { assert.ok(group.entries.length > 0, `Group ${area.id}::${group.method} has no entries`); for (const entry of group.entries) { const sp = SPECIES_BY_ID[entry.speciesId]; assert.ok(sp, `Unknown speciesId "${entry.speciesId}" in ${area.id}`); assert.notEqual( sp.availability, forbiddenAvailability, `Opposite-version exclusive "${entry.speciesId}" must not appear in ${game.id} (${area.id})`, ); assert.ok(entry.rate, `Missing rate for ${entry.speciesId} in ${area.id}`); assert.ok(entry.levels, `Missing levels for ${entry.speciesId} in ${area.id}`); referenced.add(entry.speciesId); } } } } for (const sp of SPECIES_LIST) { if (isSpeciesSoloAvailableForGame(sp, game.id)) { assert.ok( referenced.has(sp.id), `Solo-available ${game.id} species "${sp.id}" (#${sp.natId}) is missing from all sections`, ); } } } }); test('all section evolutions in both games obey upcoming Gym Leader / Champion level caps and pre-evolution ordering', () => { const expectedCaps = [14, 16, 21, 28, 30, 35, 45, 46, 59, 79]; for (const game of listGames()) { const { earliestBySpecies } = indexGameSpecies(game); assert.deepEqual( game.sections.map((s) => s.levelCap), expectedCaps, ); for (const section of game.sections) { for (const area of section.areas) { for (const group of area.groups) { if (group.method !== 'Evolution') continue; for (const entry of group.entries) { const lvlMatch = /^Lv\.\s*(\d+)$/.exec(entry.rate); if (lvlMatch) { assert.ok( Number(lvlMatch[1]) <= section.levelCap, `${game.id}: ${entry.speciesId} (${entry.rate}) exceeds ${section.id} level cap (${section.levelCap})`, ); } const sp = SPECIES_BY_ID[entry.speciesId]; if (sp?.evolvesFrom) { const pre = earliestBySpecies.get(sp.evolvesFrom); assert.ok( pre && pre.badgeNumber <= section.badgeNumber, `${game.id}: ${entry.speciesId} cannot evolve before ${sp.evolvesFrom} (${pre?.sectionId || 'missing'})`, ); } } } } } } }); test('exclusive choice locking locks alternative branches once one option is checked and releases when unchecked', () => { const storage = createMemoryStorage(); const store = createTrackerStore({ storage }); // By default (Secret Super Training OFF), Pre-Badge 1 cap Lv. 14 has 20 unlocks while total Solo POC is 410 let prog = computeGameProgress(ALPHA_SAPPHIRE_DATA, store.getState().caught, 'solo'); assert.equal(prog.sections[0].levelCap, 14); assert.equal(prog.sections[0].newTotal, 20); assert.equal(prog.totalObtainable, 410); assert.equal(store.isSpeciesLocked('treecko'), null); assert.equal(store.isSpeciesLocked('torchic'), null); assert.equal(store.isSpeciesLocked('mudkip'), null); // Check Torchic -> locks Treecko & Mudkip lines across sections, keeps Torchic/Combusken/Blaziken unlocked assert.equal(store.toggleCaught('torchic'), true); assert.equal(store.isSpeciesLocked('combusken'), null); assert.equal(store.isSpeciesLocked('blaziken'), null); assert.equal(store.isSpeciesLocked('treecko')?.chosenOption, 'torchic'); assert.equal(store.isSpeciesLocked('sceptile')?.chosenOption, 'torchic'); assert.equal(store.isSpeciesLocked('mudkip')?.chosenOption, 'torchic'); assert.equal(store.isSpeciesLocked('swampert')?.chosenOption, 'torchic'); // Cannot check locked-out starter assert.equal(store.toggleCaught('mudkip'), false); assert.equal(store.getState().caught.has('mudkip'), false); // Fossil exclusive lock works identically assert.equal(store.toggleCaught('anorith'), true); assert.equal(store.isSpeciesLocked('lileep')?.chosenOption, 'claw'); assert.equal(store.isSpeciesLocked('cradily')?.chosenOption, 'claw'); assert.equal(store.isSpeciesLocked('armaldo'), null); // Unchecking Torchic releases the starter lock assert.equal(store.toggleCaught('torchic'), true); assert.equal(store.isSpeciesLocked('mudkip'), null); assert.equal(store.isSpeciesLocked('treecko'), null); // Batch check section skips unchosen exclusive group and later-stone evolutions when Super Training is OFF store.setSectionCaught('pre-badge-1', true); assert.equal(store.getState().caught.has('mudkip'), false); assert.equal(store.getState().caught.has('treecko'), false); assert.equal(store.getState().caught.has('torchic'), false); assert.equal(store.getState().caught.has('zigzagoon'), true); assert.equal(store.getState().caught.has('lombre'), true); assert.equal(store.getState().caught.has('ludicolo'), false, 'Water Stone waits for Dive Shards unless Secret Super Training is checked'); assert.equal(store.getState().caught.has('exploud'), false, 'Lv. 40 Exploud waits for Pre-Badge 7'); // Checking Mudkip & batch-checking Pre-Badge 2 (cap Lv. 16) checks Marshtomp, leaving Swampert for Pre-Badge 7 store.toggleCaught('mudkip'); store.setSectionCaught('pre-badge-2', true); assert.equal(store.getState().caught.has('marshtomp'), true); assert.equal(store.getState().caught.has('swampert'), false); assert.equal(store.getState().caught.has('grovyle'), false); // Switching to 'all' ruleset lifts exclusive locks const { lockedBySpecies } = getExclusiveChoiceState(ALPHA_SAPPHIRE_DATA, store.getState().caught, 'all'); assert.equal(lockedBySpecies.size, 0); }); test('store syncs caught species globally, persists to storage, filters, sorts, and imports/exports JSON', () => { const storage = createMemoryStorage(); const store = createTrackerStore({ storage }); store.toggleCaught('zigzagoon'); store.toggleCaught('lotad'); const state = store.getState(); assert.equal(state.caught.has('zigzagoon'), true); assert.equal(state.caught.has('lotad'), true); // Recreate store from same storage to confirm persistence const restored = createTrackerStore({ storage }); assert.equal(restored.getState().caught.has('zigzagoon'), true); assert.equal(restored.getState().caught.has('lotad'), true); // Confirm Pokédex rows reflect caught state and solo filtering const soloRows = restored.getPokedexRows(); const zigRow = soloRows.find((r) => r.id === 'zigzagoon'); assert.equal(zigRow.caught, true); assert.equal(soloRows.some((r) => r.id === 'seedot'), false, 'OR exclusive hidden in solo mode'); restored.setRuleset('all'); const allRows = restored.getPokedexRows(); assert.equal(allRows.some((r) => r.id === 'seedot'), true, 'OR exclusive visible in all mode'); assert.equal(allRows.some((r) => r.id === 'alakazam'), true, 'Trade evo visible in all mode'); // Search & uncaughtOnly filter restored.setRuleset('solo'); restored.setSearchQuery('Lotad'); assert.equal(restored.getPokedexRows().length, 1); restored.setUncaughtOnly(true); assert.equal(restored.getPokedexRows().length, 0); // Sorting restored.setUncaughtOnly(false); restored.setSearchQuery(''); restored.setPokedexSort('name'); const byNameAsc = restored.getPokedexRows(); assert.ok(byNameAsc[0].name.localeCompare(byNameAsc[1].name) <= 0); restored.setPokedexSort('name'); const byNameDesc = restored.getPokedexRows(); assert.ok(byNameDesc[0].name.localeCompare(byNameDesc[1].name) >= 0); // Export & Import round-trip const backup = restored.exportJson(); restored.resetProgress(); assert.equal(restored.getState().caught.size, 0); const importedCount = restored.importJson(backup); assert.equal(importedCount, 2); assert.equal(restored.getState().caught.has('lotad'), true); assert.throws(() => restored.importJson('{"bad": true}')); }); test('UI views list all starter/fossil choices, show Caught checkboxes, and render locked states cleanly', () => { const store = createTrackerStore({ storage: createMemoryStorage() }); store.toggleCaught('mudkip'); store.setSelectedSpeciesId('ralts'); const state = store.getState(); const game = store.getGame(); const progress = computeGameProgress(game, state.caught, state.ruleset); // Check section banner renders Level Cap and UI views render starter/fossil choices const headerHtml = renderHeader(game, state, progress); const sidebarHtml = renderSidebar(game, state, progress); const routesHtml = renderRoutesView(game, state, progress); const pokedexHtml = renderPokedexView(store, state); const guideHtml = renderGuideView(game); const modalHtml = renderSpeciesModal(game, state); assert.match(headerHtml, /Pokémon Alpha Sapphire/); assert.match(headerHtml, /Gym Leader \/ Champion level cap/); assert.match(headerHtml, /id="super-training-toggle"/); assert.doesNotMatch(headerHtml, /id="super-training-toggle"\s+checked/); assert.doesNotMatch(headerHtml, /choices-drawer/); assert.match(sidebarHtml, /Pre-Badge 1/); assert.match(sidebarHtml, /Cap Lv\.14/); assert.match(routesHtml, /Level Cap: Lv\. 14/); // All 3 starters appear in Route 101 checklist, with Treecko/Torchic locked after Mudkip is checked assert.match(routesHtml, /Treecko/); assert.match(routesHtml, /Torchic/); assert.match(routesHtml, /Mudkip/); assert.match(routesHtml, /encounter-row is-caught/); assert.match(routesHtml, /encounter-row\s+is-locked/); assert.match(routesHtml, /Locked · Mudkip chosen/); assert.match(routesHtml, /type="checkbox"/); // Pokédex header reads "Caught" (not "X's") and renders checkboxes assert.match(pokedexHtml, /Caught\s* { setSpriteBaseUrl(POKEAPI_SPRITES_CDN); const reg = getPokemonSpriteUrls(258, { shiny: false }); const shn = getPokemonSpriteUrls(258, { shiny: true }); assert.equal( reg.primary, 'https://raw.githubusercontent.com/PokeAPI/sprites/master/sprites/pokemon/versions/generation-vi/omega-ruby-alpha-sapphire/258.png', ); assert.equal( reg.fallback, 'https://raw.githubusercontent.com/PokeAPI/sprites/master/sprites/pokemon/258.png', ); assert.equal( shn.primary, 'https://raw.githubusercontent.com/PokeAPI/sprites/master/sprites/pokemon/versions/generation-vi/omega-ruby-alpha-sapphire/shiny/258.png', ); const items = extractItemsFromText('Dawn Stone (Male Kirlia) + Sea Incense + Helix Fossil'); assert.deepEqual( items.map((i) => i.slug), ['dawn-stone', 'sea-incense', 'helix-fossil'], ); setSpriteBaseUrl('./assets/sprites'); assert.equal(getPokemonSpriteUrls(1).fallback, './assets/sprites/pokemon/1.png'); setSpriteBaseUrl(POKEAPI_SPRITES_CDN); }); test('static server serves index.html and rejects traversal', async () => { const server = createStaticServer(); 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 body = await res.text(); assert.match(body, /Alpha Sapphire — Professor Oak Challenge Tracker/); const cssRes = await fetch(`http://127.0.0.1:${port}/src/styles/main.css`); assert.equal(cssRes.status, 200); 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 rawStatus = await new Promise((resolve, reject) => { const req = http.request( { host: '127.0.0.1', port, path: '/../package.json', method: 'GET' }, (r) => resolve(r.statusCode), ); req.on('error', reject); req.end(); }); assert.equal(rawStatus, 403); } finally { await new Promise((resolve) => server.close(resolve)); } }); test('all Alpha Sapphire sections & routes define valid regular and key trainer battles under route headers', () => { const game = getGame('alpha-sapphire'); const seenAreaIds = new Set(); const seenTrainerIds = new Set(); let regularCount = 0; let keyCount = 0; for (const section of game.sections) { let sectionTrainerCount = 0; for (const area of section.areas) { assert.ok(area.id && !seenAreaIds.has(area.id), `Duplicate/empty area id: ${area.id}`); seenAreaIds.add(area.id); assert.ok(Array.isArray(area.trainers), `Area ${area.id} missing trainers array`); for (const trainer of area.trainers) { assert.ok(trainer.id && !seenTrainerIds.has(trainer.id), `Duplicate/empty trainer id: ${trainer.id}`); seenTrainerIds.add(trainer.id); assert.ok(trainer.name && trainer.role && trainer.location, `Incomplete metadata on ${trainer.id}`); sectionTrainerCount++; if (trainer.role === 'Trainer') regularCount++; else keyCount++; const teams = trainer.starterTeams ? [ trainer.starterTeams.treecko, trainer.starterTeams.torchic, trainer.starterTeams.mudkip, ] : [trainer.team]; for (const team of teams) { assert.ok(Array.isArray(team) && team.length > 0, `Empty team on trainer ${trainer.id}`); for (const mon of team) { assert.ok( Number.isInteger(mon.natId) && mon.natId > 0 && mon.natId <= 721, `Invalid natId ${mon.natId} on ${trainer.id}`, ); assert.ok( Number.isInteger(mon.level) && mon.level > 0 && mon.level <= 100, `Invalid level ${mon.level} on ${trainer.id}`, ); assert.ok(mon.name, `Missing Pokémon name on ${trainer.id}`); assert.ok(Array.isArray(mon.types) && mon.types.length > 0, `Missing types for ${mon.name} on ${trainer.id}`); } } } } assert.ok(sectionTrainerCount > 0, `Section ${section.id} must have trainers under its areas`); } for (const areaId of Object.keys(ALPHA_SAPPHIRE_TRAINERS_BY_AREA)) { assert.ok(seenAreaIds.has(areaId), `Orphaned trainer area key "${areaId}" not found in ALPHA_SAPPHIRE_DATA`); } assert.ok(regularCount > 250, `Expected full ORAS regular trainer roster (>250), got ${regularCount}`); assert.ok(keyCount >= 40, `Expected key story/gym/boss battles (>=40), got ${keyCount}`); }); test('route-level trainer cards start collapsed, expand per route/gym, track defeated state, adapt Rival team, and search cleanly', () => { const storage = createMemoryStorage(); const store = createTrackerStore({ storage }); const game = store.getGame(); // Collapsed by default under route & gym headers let state = store.getState(); let progress = computeGameProgress(game, state.caught, state.ruleset); assert.equal(progress.totalObtainable, 410); assert.equal(state.expandedTrainerAreas.size, 0); assert.equal(state.defeatedTrainers.size, 0); let routesHtml = renderRoutesView(game, state, progress); assert.doesNotMatch(routesHtml, /Key Trainer & Gym Battles/); assert.match(routesHtml, /data-toggle-area-trainers="route-102"[^>]*aria-expanded="false"/); assert.match(routesHtml, /data-toggle-area-trainers="rustboro-gym"[^>]*aria-expanded="false"/); assert.doesNotMatch(routesHtml, /Youngster Calvin/); assert.doesNotMatch(routesHtml, /Gym Leader Roxanne/); // Expand Route 102 (regular trainers) & Rustboro City Gym (gym trainers + Roxanne) store.toggleAreaTrainersExpanded('route-102'); store.toggleAreaTrainersExpanded('rustboro-gym'); store.toggleAreaTrainersExpanded('route-103-land'); state = store.getState(); progress = computeGameProgress(game, state.caught, state.ruleset); routesHtml = renderRoutesView(game, state, progress); assert.match(routesHtml, /data-toggle-area-trainers="route-102"[^>]*aria-expanded="true"/); assert.match(routesHtml, /Youngster Calvin/); assert.match(routesHtml, /Bug Catcher Rick/); assert.match(routesHtml, /Youngster Josh/); assert.match(routesHtml, /Schoolkid Georgia/); assert.match(routesHtml, /Gym Leader Roxanne/); assert.match(routesHtml, /Nosepass/); assert.match(routesHtml, /Lv\.14/); assert.match(routesHtml, /If Treecko:/); assert.match(routesHtml, /If Torchic:/); assert.match(routesHtml, /If Mudkip:/); // Pick Mudkip starter & defeat Roxanne store.toggleCaught('mudkip'); store.toggleTrainerDefeated('as-gym-roxanne'); state = store.getState(); progress = computeGameProgress(game, state.caught, state.ruleset); assert.equal(progress.totalObtainable, 410, 'Trainer defeats must not alter Pokémon POC total'); routesHtml = renderRoutesView(game, state, progress); assert.match(routesHtml, /Opponent team for your Mudkip<\/strong> starter pick:/); assert.doesNotMatch(routesHtml, /If Torchic:/); assert.match(routesHtml, /trainer-battle-card is-defeated/); assert.match(routesHtml, /1 \/ 4 defeated/); assert.match(routesHtml, /Defeated<\/span>/); // Storage persistence + JSON export/import round-trip const restored = createTrackerStore({ storage }); assert.equal(restored.getState().defeatedTrainers.has('as-gym-roxanne'), true); assert.equal(restored.getState().expandedTrainerAreas.has('route-102'), true); const backup = restored.exportJson(); restored.resetProgress(); assert.equal(restored.getState().defeatedTrainers.size, 0); restored.importJson(backup); assert.equal(restored.getState().defeatedTrainers.has('as-gym-roxanne'), true); // Searching a wild species keeps trainer drawers collapsed; searching a trainer name auto-expands that route restored.toggleAreaTrainersExpanded('route-102'); restored.toggleAreaTrainersExpanded('rustboro-gym'); restored.setSearchQuery('Zigzagoon'); let searchState = restored.getState(); let searchHtml = renderRoutesView(game, searchState, computeGameProgress(game, searchState.caught, searchState.ruleset)); assert.match(searchHtml, /data-toggle-area-trainers="route-102"[^>]*aria-expanded="false"/); restored.setSearchQuery('Youngster Calvin'); searchState = restored.getState(); searchHtml = renderRoutesView(game, searchState, computeGameProgress(game, searchState.caught, searchState.ruleset)); assert.match(searchHtml, /Youngster Calvin/); assert.match(searchHtml, /data-toggle-area-trainers="route-102"[^>]*aria-expanded="true"/); restored.setSearchQuery('Roxanne'); searchState = restored.getState(); searchHtml = renderRoutesView(game, searchState, computeGameProgress(game, searchState.caught, searchState.ruleset)); assert.match(searchHtml, /Gym Leader Roxanne/); assert.match(searchHtml, /data-toggle-area-trainers="rustboro-gym"[^>]*aria-expanded="true"/); }); test('Omega Ruby dataset defines Team Magma & OR-specific trainers accurately', () => { const game = getGame('omega-ruby'); const seenAreaIds = new Set(); const seenTrainerIds = new Set(); const trainersByArea = new Map(); for (const section of game.sections) { for (const area of section.areas) { assert.ok(!seenAreaIds.has(area.id), `Duplicate OR area id: ${area.id}`); seenAreaIds.add(area.id); trainersByArea.set(area.id, area.trainers || []); for (const t of area.trainers || []) { assert.ok(!seenTrainerIds.has(t.id), `Duplicate OR trainer id: ${t.id}`); seenTrainerIds.add(t.id); assert.notEqual(t.role, 'Team Aqua', `Found Team Aqua trainer "${t.id}" inside Omega Ruby`); } } } const r115Hector = trainersByArea.get('route-115-north')?.find((t) => t.name === 'Collector Hector'); assert.equal(r115Hector?.team?.[0]?.name, 'Seviper'); const chimney = trainersByArea.get('mt-chimney') || []; assert.ok(chimney.some((t) => t.name === 'Team Magma Leader Maxie')); assert.ok(trainersByArea.has('lilycove-magma-hideout')); assert.ok(trainersByArea.has('delta-magma-hideout')); }); test('game switcher and multi-save profiles isolate saves per game/profile, migrate legacy saves, and render switcher/modal UI', () => { const storage = createMemoryStorage(); // Seed legacy pre-profile Alpha Sapphire save storage.setItem( 'poc-tracker:v1:alpha-sapphire', JSON.stringify({ version: 1, gameId: 'alpha-sapphire', caught: ['mudkip'], defeatedTrainers: ['as-gym-roxanne'] }), ); const store = createTrackerStore({ storage }); assert.equal(store.getGame().id, 'alpha-sapphire'); assert.equal(store.getActiveProfile().id, 'default'); assert.equal(store.getState().caught.has('mudkip'), true); assert.equal(store.getState().defeatedTrainers.has('as-gym-roxanne'), true); // Create second Alpha Sapphire profile -> clean save, Save 1 stays intact const second = store.createProfile('Treecko Challenge'); assert.equal(store.getState().profileId, second.id); assert.equal(store.getState().caught.size, 0); store.toggleCaught('treecko'); assert.equal(store.getState().caught.has('treecko'), true); // Swap back to Save 1 -> Mudkip + Roxanne defeat preserved store.switchProfile('default'); assert.equal(store.getState().caught.has('mudkip'), true); assert.equal(store.getState().caught.has('treecko'), false); // Rename Save 2 and inspect profile counts store.renameProfile(second.id, 'Treecko Speedrun'); const profilesWithCounts = store.getProfilesWithCounts(); assert.equal(profilesWithCounts.length, 2); assert.equal(profilesWithCounts[1].name, 'Treecko Speedrun'); assert.equal(profilesWithCounts[1].caughtCount, 1); // Render header & profile modal const asHeader = renderHeader( store.getGame(), store.getState(), computeGameProgress(store.getGame(), store.getState().caught, store.getState().ruleset), profilesWithCounts, ); assert.match(asHeader, /data-switch-game="alpha-sapphire"[^>]*aria-pressed="true"/); assert.match(asHeader, /data-switch-game="omega-ruby"/); assert.match(asHeader, /Treecko Speedrun \(1\)/); assert.match(asHeader, /Strict Solo AS Cartridge/); store.setProfileModal({ mode: 'create' }); const modalHtml = renderProfileModal(store.getGame(), store.getState()); assert.match(modalHtml, /New Alpha Sapphire Save Profile/); assert.match(modalHtml, /id="profile-name-input"/); // Export AS Save 1 backup const asBackup = store.exportJson(); // Switch to Omega Ruby mode -> clean independent OR profile + OR encounters + OR trainers store.switchGame('omega-ruby'); assert.equal(store.getGame().id, 'omega-ruby'); assert.equal(store.getState().caught.size, 0); store.toggleCaught('seedot'); store.toggleCaught('latios'); assert.equal(store.getState().caught.has('seedot'), true); const orProgress = computeGameProgress(store.getGame(), store.getState().caught, store.getState().ruleset); assert.equal(orProgress.totalObtainable, 410); const orHeader = renderHeader( store.getGame(), store.getState(), orProgress, store.getProfilesWithCounts(), ); assert.match(orHeader, /Strict Solo OR Cartridge/); assert.match(orHeader, /version-or/); // Cross-version JSON import throws cleanly assert.throws(() => store.importJson(asBackup), /Switch versions before importing/); // Re-create store from storage without gameId -> remembers active game (Omega Ruby) & saves const reloaded = createTrackerStore({ storage }); assert.equal(reloaded.getGame().id, 'omega-ruby'); assert.equal(reloaded.getState().caught.has('seedot'), true); // Deleting last remaining profile is blocked; switching back to AS allows deleting extra profile assert.equal(reloaded.deleteProfile('default'), false); reloaded.switchGame('alpha-sapphire'); assert.equal(reloaded.deleteProfile(second.id), true); assert.equal(reloaded.getState().profiles.length, 1); assert.equal(reloaded.getState().caught.has('mudkip'), true); }); test('ORAS wild encounters match Serebii Pokearth & Pokedex-XY across routes, caves, Safari Zone, Shoal Cave, Sky Pillar, and Mirage Spots', () => { const areaById = (game, id) => { for (const s of game.sections) { const found = s.areas.find((a) => a.id === id); if (found) return { section: s, area: found }; } return null; }; const speciesInArea = (game, id) => { const found = areaById(game, id); assert.ok(found, `Missing area "${id}" in ${game.id}`); return new Set(found.area.groups.flatMap((g) => g.entries.map((e) => e.speciesId))); }; for (const game of listGames()) { // Route 116: Zigzagoon, Whismur, Nincada, Taillow, Skitty — no Abra or Poochyena const r116 = speciesInArea(game, 'route-116'); assert.equal(r116.has('abra'), false); assert.equal(r116.has('poochyena'), false); assert.equal(r116.has('taillow'), true); assert.equal(r116.has('skitty'), true); // Petalburg Woods: both Silcoon and Cascoon in both games, no Poochyena const woods = speciesInArea(game, 'petalburg-woods'); assert.equal(woods.has('silcoon'), true); assert.equal(woods.has('cascoon'), true); assert.equal(woods.has('poochyena'), false); // Route 104 South & North: no Poochyena assert.equal(speciesInArea(game, 'route-104-south').has('poochyena'), false); assert.equal(speciesInArea(game, 'route-104-north').has('poochyena'), false); // Granite Cave 1F (Pre-Badge 2) has Abra; B1F/B2F (Mach Bike -> Pre-Badge 3) has Aron & Sableye/Mawile const gc1f = areaById(game, 'granite-cave'); assert.equal(gc1f.section.id, 'pre-badge-2'); assert.equal(speciesInArea(game, 'granite-cave').has('abra'), true); assert.equal(speciesInArea(game, 'granite-cave').has('aron'), false); const gcBasement = areaById(game, 'granite-cave-basement'); assert.equal(gcBasement.section.id, 'pre-badge-3'); const gcBaseSpecies = speciesInArea(game, 'granite-cave-basement'); assert.equal(gcBaseSpecies.has('aron'), true); assert.equal(gcBaseSpecies.has(game.id === 'omega-ruby' ? 'mawile' : 'sableye'), true); // Jagged Pass has no Koffing; Route 111 Desert Horde is Sandshrew-only assert.equal(speciesInArea(game, 'jagged-pass').has('koffing'), false); const desertHorde = areaById(game, 'route-111-desert').area.groups.find((g) => g.method === 'Horde'); assert.deepEqual(desertHorde.entries.map((e) => e.speciesId), ['sandshrew']); // Safari Zone has Donphan, Wobbuffet, Xatu, Seaking; Natu & Phanpy are bred in Pre-Badge 7 const safari = speciesInArea(game, 'safari-zone'); assert.equal(safari.has('donphan'), true); assert.equal(safari.has('wobbuffet'), true); assert.equal(safari.has('xatu'), true); assert.equal(safari.has('seaking'), true); assert.equal(safari.has('natu'), false); assert.equal(safari.has('phanpy'), false); const b7Evos = speciesInArea(game, 'pre-badge-7-evolutions'); assert.equal(b7Evos.has('natu'), true); assert.equal(b7Evos.has('phanpy'), true); assert.equal(b7Evos.has('glalie'), true); // Shoal Cave has no wild Glalie assert.equal(speciesInArea(game, 'shoal-cave').has('glalie'), false); // Sky Pillar Walking has Claydol + version-exclusive Sableye/Mawile; Horde has Golbat, Ariados, Swablu const sky = areaById(game, 'sky-pillar-delta').area; const skyWalk = new Set(sky.groups.find((g) => g.method === 'Walking').entries.map((e) => e.speciesId)); const skyHorde = new Set(sky.groups.find((g) => g.method === 'Horde').entries.map((e) => e.speciesId)); assert.equal(skyWalk.has('claydol'), true); assert.equal(skyWalk.has(game.id === 'omega-ruby' ? 'mawile' : 'sableye'), true); assert.equal(skyHorde.has('swablu'), true); assert.equal(skyHorde.has('sableye'), false); assert.equal(skyHorde.has('mawile'), false); // Mirage Island Rock Smash Binacle + Barbaracle Lv. 39 are included assert.equal(speciesInArea(game, 'mirage-spots').has('binacle'), true); assert.equal(speciesInArea(game, 'pre-badge-8-breeding-evos').has('barbaracle'), true); } // Omega Ruby swaps Route 110 Minun, Route 117 Illumise (20%), and Fiery Path Koffing Horde const orGame = getGame('omega-ruby'); const or110Walk = orGame.sections[2].areas.find((a) => a.id === 'route-110').groups[0].entries; assert.equal(or110Walk.some((e) => e.speciesId === 'minun' && e.rate === '16%'), true); const or117Walk = orGame.sections[2].areas.find((a) => a.id === 'route-117').groups[0].entries; assert.equal(or117Walk.some((e) => e.speciesId === 'illumise' && e.rate === '20%'), true); const orFieryHorde = orGame.sections[3].areas.find((a) => a.id === 'fiery-path').groups[1].entries; assert.equal(orFieryHorde.some((e) => e.speciesId === 'koffing'), true); // X&Y-only species (Caterpie, Mareep, Hoppip, Wooper lines) are excluded from ORAS catalog for (const xyOnly of ['caterpie', 'butterfree', 'mareep', 'ampharos', 'hoppip', 'jumpluff', 'wooper', 'quagsire']) { assert.equal(SPECIES_BY_ID[xyOnly], undefined, `${xyOnly} is X&Y-only and must not be in ORAS catalog`); } }); test('optional Secret Super Training flag shifts stone evolutions between overworld pickups and minigame unlocks per save profile', () => { const storage = createMemoryStorage(); const store = createTrackerStore({ storage }); // Default: Secret Super Training is OFF assert.equal(store.getState().includeSuperTraining, false); const asOff = store.getGame(); assert.equal(asOff.includeSuperTraining, false); assert.equal(computeGameProgress(asOff, new Set(), 'solo').totalObtainable, 410); const asOffEarliest = indexGameSpecies(asOff).earliestBySpecies; assert.equal(asOffEarliest.get('delcatty')?.sectionId, 'pre-badge-4'); assert.equal(asOffEarliest.get('vileplume')?.sectionId, 'pre-badge-6'); assert.equal(asOffEarliest.get('bellossom')?.sectionId, 'pre-badge-7'); assert.equal(asOffEarliest.get('roserade')?.sectionId, 'pre-badge-7'); assert.equal(asOffEarliest.get('ludicolo')?.sectionId, 'pre-badge-8'); assert.equal(asOffEarliest.get('raichu')?.sectionId, 'pre-badge-8'); assert.equal(asOffEarliest.get('starmie')?.sectionId, 'pre-badge-8'); assert.equal(asOffEarliest.get('gallade')?.sectionId, 'pre-elite-4'); assert.equal(asOffEarliest.get('froslass')?.sectionId, 'pre-elite-4'); // Omega Ruby uses Route 119 Leaf Stone for Shiftry in Pre-Badge 6 and Route 124 Green Shard for Vileplume in Pre-Badge 8 const orOff = getGame('omega-ruby', { includeSuperTraining: false }); assert.equal(computeGameProgress(orOff, new Set(), 'solo').totalObtainable, 410); const orOffEarliest = indexGameSpecies(orOff).earliestBySpecies; assert.equal(orOffEarliest.get('delcatty')?.sectionId, 'pre-badge-4'); assert.equal(orOffEarliest.get('shiftry')?.sectionId, 'pre-badge-6'); assert.equal(orOffEarliest.get('vileplume')?.sectionId, 'pre-badge-8'); assert.equal(orOffEarliest.get('gallade')?.sectionId, 'pre-elite-4'); // Guide view states Secret Super Training is OFF const guideOffHtml = renderGuideView(asOff); assert.match(guideOffHtml, /Secret Super Training is currently OFF/); // Create a second save profile and enable Secret Super Training only on that save const sstProfile = store.createProfile('Super Training Run'); assert.equal(store.getState().includeSuperTraining, false); store.setIncludeSuperTraining(true); assert.equal(store.getState().includeSuperTraining, true); const asOn = store.getGame(); assert.equal(asOn.includeSuperTraining, true); assert.equal(computeGameProgress(asOn, new Set(), 'solo').totalObtainable, 410); const asOnProg = computeGameProgress(asOn, new Set(), 'solo'); assert.equal(asOnProg.sections[0].newTotal, 22); const asOnEarliest = indexGameSpecies(asOn).earliestBySpecies; assert.equal(asOnEarliest.get('ludicolo')?.sectionId, 'pre-badge-1'); assert.equal(asOnEarliest.get('delcatty')?.sectionId, 'pre-badge-1'); assert.equal(asOnEarliest.get('gallade')?.sectionId, 'pre-badge-3'); assert.equal(asOnEarliest.get('vileplume')?.sectionId, 'pre-badge-3'); assert.equal(asOnEarliest.get('bellossom')?.sectionId, 'pre-badge-3'); assert.equal(asOnEarliest.get('roserade')?.sectionId, 'pre-badge-3'); assert.equal(asOnEarliest.get('raichu')?.sectionId, 'pre-badge-7'); assert.equal(asOnEarliest.get('starmie')?.sectionId, 'pre-badge-7'); assert.equal(asOnEarliest.get('froslass')?.sectionId, 'pre-badge-7'); const orOn = getGame('omega-ruby', { includeSuperTraining: true }); assert.equal(computeGameProgress(orOn, new Set(), 'solo').totalObtainable, 410); assert.equal(indexGameSpecies(orOn).earliestBySpecies.get('shiftry')?.sectionId, 'pre-badge-1'); // Batch check Pre-Badge 1 when Secret Super Training is ON includes Ludicolo & Delcatty store.setSectionCaught('pre-badge-1', true); assert.equal(store.getState().caught.has('ludicolo'), true); assert.equal(store.getState().caught.has('delcatty'), true); // Header checkbox renders checked & Guide reflects ON state const headerOnHtml = renderHeader(asOn, store.getState(), computeGameProgress(asOn, store.getState().caught, 'solo')); const guideOnHtml = renderGuideView(asOn); assert.match(headerOnHtml, /id="super-training-toggle" checked/); assert.match(guideOnHtml, /Secret Super Training is ON\./); // Switching back to Save 1 restores Secret Super Training = false independently store.switchProfile('default'); assert.equal(store.getState().includeSuperTraining, false); // Reloading store and JSON export/import both persist includeSuperTraining store.switchProfile(sstProfile.id); const backup = store.exportJson(); assert.equal(JSON.parse(backup).includeSuperTraining, true); const reloaded = createTrackerStore({ storage }); assert.equal(reloaded.getState().includeSuperTraining, true); reloaded.switchProfile('default'); assert.equal(reloaded.getState().includeSuperTraining, false); reloaded.importJson(backup); assert.equal(reloaded.getState().includeSuperTraining, true); }); test('ORAS Movedex covers all 478 species with Gen 6 stats, sorted TM/HMs, and renders tabs & filter in modal', () => { const validCategories = new Set(['Physical', 'Special', 'Status']); for (const sp of SPECIES_LIST) { const ms = getPokemonMoveset(sp.natId); assert.ok(ms.totalUniqueMoves > 0, `Expected moveset for ${sp.name} (#${sp.natId})`); for (const m of [...ms.levelUp, ...ms.machine, ...ms.tutor, ...ms.egg]) { assert.ok(m.name && m.type, `Move missing name/type on ${sp.name}`); assert.ok(validCategories.has(m.category), `Invalid move category "${m.category}" on ${m.name}`); } } // Verify Gen 6 ORAS stats via move_changelog restoration (Tackle 50 power, Leech Life 20 power) assert.equal(ORAS_MOVES[33][3], 50); assert.equal(ORAS_MOVES[141][3], 20); // Verify Mudkip TMs sort numerically (TM06..TM100 then HM01..HM07) & Pichu preserves Volt Tackle (Light Ball) const mudkipMoves = getPokemonMoveset(258); const tmNums = mudkipMoves.machine.filter((m) => m.machine.startsWith('TM')).map((m) => Number(m.machine.slice(2))); assert.deepEqual( tmNums, [...tmNums].sort((a, b) => a - b), ); const firstHmIdx = mudkipMoves.machine.findIndex((m) => m.machine.startsWith('HM')); assert.ok(firstHmIdx > 0 && mudkipMoves.machine.slice(firstHmIdx).every((m) => m.machine.startsWith('HM'))); assert.equal( getPokemonMoveset(172).egg.some((m) => m.name === 'Volt Tackle' && m.note === 'Volt Tackle (Light Ball)'), true, ); // Modal renders ORAS Movedex section, switches tabs cleanly, and filters moves const store = createTrackerStore({ storage: createMemoryStorage() }); store.setSelectedSpeciesId('mudkip'); let modalHtml = renderSpeciesModal(store.getGame(), store.getState()); assert.match(modalHtml, new RegExp(`ORAS Movedex \\(${mudkipMoves.totalUniqueMoves} moves\\)`)); assert.match(modalHtml, /Level-Up \(13\)<\/span>/); assert.match(modalHtml, /TM \/ HM \(30\)<\/span>/); assert.match(modalHtml, /Water Gun/); assert.doesNotMatch(modalHtml, /TM06/); store.setMovedexTab('machine'); modalHtml = renderSpeciesModal(store.getGame(), store.getState()); assert.match(modalHtml, /TM06/); assert.match(modalHtml, /HM03/); assert.match(modalHtml, /Surf/); store.setMovedexSearch('waterfall'); modalHtml = renderSpeciesModal(store.getGame(), store.getState()); assert.match(modalHtml, /HM05/); assert.match(modalHtml, /Waterfall/); assert.doesNotMatch(modalHtml, /TM06/); // Non-matching search in current tab offers jump link to All Moves when another tab matches store.setMovedexSearch('hydro pump'); modalHtml = renderSpeciesModal(store.getGame(), store.getState()); assert.match(modalHtml, /View 1 match in All Moves/); }); test('external guide arrow trigger and popup menu generate Serebii, Bulbapedia, PokemonDB, and Smogon links in Pokedex and Modal', () => { const hoOhLinks = getExternalLinksForSpecies(SPECIES_BY_ID['ho-oh']); assert.deepEqual( hoOhLinks.map((l) => l.id), ['serebii', 'bulbapedia', 'pokemondb', 'smogon'], ); assert.equal(hoOhLinks[0].url, 'https://www.serebii.net/pokedex-xy/250.shtml'); assert.equal(hoOhLinks[1].url, 'https://bulbapedia.bulbagarden.net/wiki/Ho-Oh_(Pok%C3%A9mon)'); assert.equal(hoOhLinks[2].url, 'https://pokemondb.net/pokedex/ho-oh'); assert.equal(hoOhLinks[3].url, 'https://www.smogon.com/dex/xy/pokemon/ho-oh/'); const store = createTrackerStore({ storage: createMemoryStorage() }); // Pokédex table renders closed arrow trigger by default, then opens popup menu when toggled let dexHtml = renderPokedexView(store, store.getState()); assert.match(dexHtml, /data-open-ext-menu="mudkip"/); assert.doesNotMatch(dexHtml, /data-ext-menu-panel="mudkip"/); store.toggleExternalMenu('mudkip', 'pokedex'); dexHtml = renderPokedexView(store, store.getState()); assert.match(dexHtml, /data-ext-menu-panel="mudkip"/); assert.match(dexHtml, /https:\/\/www\.serebii\.net\/pokedex-xy\/258\.shtml/); assert.match(dexHtml, /https:\/\/bulbapedia\.bulbagarden\.net\/wiki\/Mudkip_\(Pok%C3%A9mon\)/); assert.match(dexHtml, /https:\/\/pokemondb\.net\/pokedex\/mudkip/); assert.match(dexHtml, /https:\/\/www\.smogon\.com\/dex\/xy\/pokemon\/mudkip\//); // Clicking same trigger closes menu cleanly store.toggleExternalMenu('mudkip', 'pokedex'); assert.equal(store.getState().openExternalMenu, null); // Species modal header also exposes the external links popup store.setSelectedSpeciesId('porygon-z'); store.toggleExternalMenu('porygon-z', 'modal'); const modalHtml = renderSpeciesModal(store.getGame(), store.getState()); assert.match(modalHtml, /data-ext-menu-panel="porygon-z"[\s\S]*?data-ext-context="modal"/); assert.match(modalHtml, /https:\/\/www\.serebii\.net\/pokedex-xy\/474\.shtml/); assert.match(modalHtml, /https:\/\/bulbapedia\.bulbagarden\.net\/wiki\/Porygon-Z_\(Pok%C3%A9mon\)/); }); test('ORAS checklist renders sprites and type pills, and Pokedex tab & modal show authentic Gen 6 stats', () => { // All 478 ORAS species have valid Gen 6 baseStats & abilities for (const sp of SPECIES_LIST) { assert.ok(sp.baseStats, `Missing baseStats on ${sp.id}`); const { hp, atk, def, spa, spd, spe, total } = sp.baseStats; assert.equal(hp + atk + def + spa + spd + spe, total, `BST mismatch on ${sp.id}`); assert.ok(Array.isArray(sp.abilities) && sp.abilities.length > 0, `Missing abilities on ${sp.id}`); } assert.equal(SPECIES_BY_ID.swellow.baseStats.spa, 50); assert.equal(SPECIES_BY_ID.swellow.baseStats.total, 430); assert.equal(SPECIES_BY_ID.pelipper.baseStats.spa, 85); const store = createTrackerStore({ storage: createMemoryStorage() }); const game = store.getGame(); const state = store.getState(); const progress = computeGameProgress(game, state.caught, state.ruleset); // Main checklist rows include mini sprite + inline type pill(s) const routesHtml = renderRoutesView(game, state, progress); assert.match(routesHtml, /class="pkmn-mini-sprite"[^>]*src="[^"]*\/261\.png"/); assert.match(routesHtml, /class="inline-types">[\s\S]*?Dark<\/span>/); // Pokédex tab displays Gen 6 Base Stats & BST and supports sorting by bst const dexHtml = renderPokedexView(store, store.getState()); assert.match(dexHtml, /data-sort-col="bst"/); assert.match(dexHtml, /class="dex-bst-pill">430<\/span>/); store.setPokedexSort('bst'); // asc -> lowest BST first (Sunkern 180) const sortedAsc = store.getPokedexRows(); assert.ok(sortedAsc[0].baseStats.total <= sortedAsc[1].baseStats.total); store.setPokedexSort('bst'); // desc -> highest BST first (Slaking / Kyogre / Groudon / Rayquaza >= 670) const sortedDesc = store.getPokedexRows(); assert.ok(sortedDesc[0].baseStats.total >= 670); // Pokédex detail modal displays Base Stats (BST), Abilities, and 6 colored stat bars store.setSelectedSpeciesId('swellow'); const modalHtml = renderSpeciesModal(store.getGame(), store.getState()); assert.match(modalHtml, /Base Stats \(BST 430\)/); assert.match(modalHtml, /Scrappy \(HA\)/); assert.equal((modalHtml.match(/class="stat-bar-row"/g) || []).length, 6); });