lost-at-sea-encounter: fix and extend tests

This commit is contained in:
Felix Staud 2024-07-17 16:23:31 -07:00
parent 3fd79984cd
commit 41cacde623
1 changed files with 19 additions and 8 deletions

View File

@ -3,6 +3,7 @@ import { LostAtSeaEncounter } from "#app/data/mystery-encounters/encounters/lost
import { EncounterOptionMode } from "#app/data/mystery-encounters/mystery-encounter-option"; import { EncounterOptionMode } from "#app/data/mystery-encounters/mystery-encounter-option";
import * as MysteryEncounters from "#app/data/mystery-encounters/mystery-encounters"; import * as MysteryEncounters from "#app/data/mystery-encounters/mystery-encounters";
import * as EncounterPhaseUtils from "#app/data/mystery-encounters/utils/encounter-phase-utils"; import * as EncounterPhaseUtils from "#app/data/mystery-encounters/utils/encounter-phase-utils";
import { getPokemonSpecies } from "#app/data/pokemon-species.js";
import { Biome } from "#app/enums/biome"; import { Biome } from "#app/enums/biome";
import { Moves } from "#app/enums/moves"; import { Moves } from "#app/enums/moves";
import { MysteryEncounterType } from "#app/enums/mystery-encounter-type"; import { MysteryEncounterType } from "#app/enums/mystery-encounter-type";
@ -15,6 +16,8 @@ import { runSelectMysteryEncounterOption } from "../encounterTestUtils";
const namepsace = "mysteryEncounter:lostAtSea"; const namepsace = "mysteryEncounter:lostAtSea";
/** Blastoise for surf. Pidgeot for fly. Abra for none. */ /** Blastoise for surf. Pidgeot for fly. Abra for none. */
const defaultParty = [Species.BLASTOISE, Species.PIDGEOT, Species.ABRA]; const defaultParty = [Species.BLASTOISE, Species.PIDGEOT, Species.ABRA];
const defaultBiome = Biome.SEA;
const defaultWave = 33;
describe("Lost at Sea - Mystery Encounter", () => { describe("Lost at Sea - Mystery Encounter", () => {
let phaserGame: Phaser.Game; let phaserGame: Phaser.Game;
@ -24,10 +27,14 @@ describe("Lost at Sea - Mystery Encounter", () => {
phaserGame = new Phaser.Game({ type: Phaser.HEADLESS }); phaserGame = new Phaser.Game({ type: Phaser.HEADLESS });
}); });
beforeEach(() => { beforeEach(async () => {
game = new GameManager(phaserGame); game = new GameManager(phaserGame);
game.override.mysteryEncounterChance(100); game.override.mysteryEncounterChance(100);
game.override.startingBiome(Biome.SEA); game.override.startingBiome(defaultBiome);
game.override.startingWave(defaultWave);
vi.spyOn(MysteryEncounters, "allMysteryEncounters", "get").mockReturnValue({
[MysteryEncounterType.LOST_AT_SEA]: LostAtSeaEncounter,
});
vi.spyOn(MysteryEncounters, "mysteryEncountersByBiome", "get").mockReturnValue( vi.spyOn(MysteryEncounters, "mysteryEncountersByBiome", "get").mockReturnValue(
new Map<Biome, MysteryEncounterType[]>([[Biome.SEA, [MysteryEncounterType.LOST_AT_SEA]]]) new Map<Biome, MysteryEncounterType[]>([[Biome.SEA, [MysteryEncounterType.LOST_AT_SEA]]])
); );
@ -38,7 +45,8 @@ describe("Lost at Sea - Mystery Encounter", () => {
}); });
it("should have the correct properties", async () => { it("should have the correct properties", async () => {
await game.runToMysteryEncounter([Species.ABRA]); await workaround_reInitSceneWithOverrides(game);
await game.runToMysteryEncounter(defaultParty);
expect(LostAtSeaEncounter.encounterType).toBe(MysteryEncounterType.LOST_AT_SEA); expect(LostAtSeaEncounter.encounterType).toBe(MysteryEncounterType.LOST_AT_SEA);
expect(LostAtSeaEncounter.dialogue).toBeDefined(); expect(LostAtSeaEncounter.dialogue).toBeDefined();
@ -50,7 +58,12 @@ describe("Lost at Sea - Mystery Encounter", () => {
}); });
it("should not run outside of sea biome", async () => { it("should not run outside of sea biome", async () => {
// TODO: a little tricky game.override.startingBiome(Biome.MOUNTAIN);
await workaround_reInitSceneWithOverrides(game);
//expect the `TypeError: Cannot read properties of undefined (reading 'introVisuals')` error
await expect(() => game.runToMysteryEncounter()).rejects.toThrowError(/introVisuals/);
}); });
it("should not run below wave 11", async () => { it("should not run below wave 11", async () => {
@ -103,9 +116,7 @@ describe("Lost at Sea - Mystery Encounter", () => {
}); });
it("should award exp to surfable PKM (Blastoise)", async () => { it("should award exp to surfable PKM (Blastoise)", async () => {
const laprasBaseExp = 187; const laprasSpecies = getPokemonSpecies(Species.LAPRAS);
const wave = 33;
game.override.startingWave(wave);
await workaround_reInitSceneWithOverrides(game); await workaround_reInitSceneWithOverrides(game);
await game.runToMysteryEncounter(defaultParty); await game.runToMysteryEncounter(defaultParty);
@ -115,7 +126,7 @@ describe("Lost at Sea - Mystery Encounter", () => {
await runSelectMysteryEncounterOption(game, 2); await runSelectMysteryEncounterOption(game, 2);
expect(blastoise.exp).toBe(expBefore + laprasBaseExp * wave); expect(blastoise.exp).toBe(expBefore + laprasSpecies.baseExp * defaultWave);
}); });
it("should leave encounter without battle", async () => { it("should leave encounter without battle", async () => {