From 983c3f0040b534c0941461b3400a4bceb65ee77e Mon Sep 17 00:00:00 2001 From: ImperialSympathizer Date: Wed, 11 Sep 2024 18:00:15 -0400 Subject: [PATCH] fix all tests for MEs and cleanup --- src/data/dialogue.ts | 30 ++++++++++++------- src/game-mode.ts | 2 +- .../dancing-lessons-encounter.test.ts | 2 ++ .../teleporting-hijinks-encounter.test.ts | 2 +- .../uncommon-breed-encounter.test.ts | 20 +++++++++++-- src/test/utils/gameWrapper.ts | 2 +- src/test/utils/mocks/mockTextureManager.ts | 3 +- .../mocks/mocksContainer/mockContainer.ts | 17 ++++++----- .../utils/mocks/mocksContainer/mockText.ts | 24 ++++++++------- src/test/utils/phaseInterceptor.ts | 1 - 10 files changed, 68 insertions(+), 35 deletions(-) diff --git a/src/data/dialogue.ts b/src/data/dialogue.ts index 6153dc439fa..b01242d083a 100644 --- a/src/data/dialogue.ts +++ b/src/data/dialogue.ts @@ -1100,10 +1100,12 @@ export const trainerTypeDialogue: TrainerTypeDialogue = { "dialogue:stat_trainer_buck.encounter.2" ], victory: [ - "dialogue:stat_trainer_buck.victory.1" + "dialogue:stat_trainer_buck.victory.1", + "dialogue:stat_trainer_buck.victory.2" ], defeat: [ - "dialogue:stat_trainer_buck.defeat.1" + "dialogue:stat_trainer_buck.defeat.1", + "dialogue:stat_trainer_buck.defeat.2" ] } ], @@ -1114,10 +1116,12 @@ export const trainerTypeDialogue: TrainerTypeDialogue = { "dialogue:stat_trainer_cheryl.encounter.2" ], victory: [ - "dialogue:stat_trainer_cheryl.victory.1" + "dialogue:stat_trainer_cheryl.victory.1", + "dialogue:stat_trainer_cheryl.victory.2" ], defeat: [ - "dialogue:stat_trainer_cheryl.defeat.1" + "dialogue:stat_trainer_cheryl.defeat.1", + "dialogue:stat_trainer_cheryl.defeat.2" ] } ], @@ -1128,10 +1132,12 @@ export const trainerTypeDialogue: TrainerTypeDialogue = { "dialogue:stat_trainer_marley.encounter.2" ], victory: [ - "dialogue:stat_trainer_marley.victory.1" + "dialogue:stat_trainer_marley.victory.1", + "dialogue:stat_trainer_marley.victory.2" ], defeat: [ - "dialogue:stat_trainer_marley.defeat.1" + "dialogue:stat_trainer_marley.defeat.1", + "dialogue:stat_trainer_marley.defeat.2" ] } ], @@ -1142,10 +1148,12 @@ export const trainerTypeDialogue: TrainerTypeDialogue = { "dialogue:stat_trainer_mira.encounter.2" ], victory: [ - "dialogue:stat_trainer_mira.victory.1" + "dialogue:stat_trainer_mira.victory.1", + "dialogue:stat_trainer_mira.victory.2" ], defeat: [ - "dialogue:stat_trainer_mira.defeat.1" + "dialogue:stat_trainer_mira.defeat.1", + "dialogue:stat_trainer_mira.defeat.2" ] } ], @@ -1156,10 +1164,12 @@ export const trainerTypeDialogue: TrainerTypeDialogue = { "dialogue:stat_trainer_riley.encounter.2" ], victory: [ - "dialogue:stat_trainer_riley.victory.1" + "dialogue:stat_trainer_riley.victory.1", + "dialogue:stat_trainer_riley.victory.2" ], defeat: [ - "dialogue:stat_trainer_riley.defeat.1" + "dialogue:stat_trainer_riley.defeat.1", + "dialogue:stat_trainer_riley.defeat.2" ] } ], diff --git a/src/game-mode.ts b/src/game-mode.ts index cadda4e7a21..0a35e60057c 100644 --- a/src/game-mode.ts +++ b/src/game-mode.ts @@ -61,7 +61,7 @@ export class GameMode implements GameModeConfig { } this.battleConfig = battleConfig || {}; this.minMysteryEncounterWave = this.minMysteryEncounterWave ?? 0; - this.maxMysteryEncounterWave = this.maxMysteryEncounterWave ?? Number.MAX_SAFE_INTEGER; + this.maxMysteryEncounterWave = this.maxMysteryEncounterWave ?? 100000; } /** diff --git a/src/test/mystery-encounter/encounters/dancing-lessons-encounter.test.ts b/src/test/mystery-encounter/encounters/dancing-lessons-encounter.test.ts index ac4165589b4..5a2512ddaf6 100644 --- a/src/test/mystery-encounter/encounters/dancing-lessons-encounter.test.ts +++ b/src/test/mystery-encounter/encounters/dancing-lessons-encounter.test.ts @@ -173,6 +173,7 @@ describe("Dancing Lessons - Mystery Encounter", () => { const phaseSpy = vi.spyOn(scene, "unshiftPhase"); await game.runToMysteryEncounter(MysteryEncounterType.DANCING_LESSONS, defaultParty); + scene.getParty()[0].moveset = []; await runMysteryEncounterToEnd(game, 2, { pokemonNo: 1 }); const movePhases = phaseSpy.mock.calls.filter(p => p[0] instanceof LearnMovePhase).map(p => p[0]); @@ -184,6 +185,7 @@ describe("Dancing Lessons - Mystery Encounter", () => { const leaveEncounterWithoutBattleSpy = vi.spyOn(EncounterPhaseUtils, "leaveEncounterWithoutBattle"); await game.runToMysteryEncounter(MysteryEncounterType.DANCING_LESSONS, defaultParty); + scene.getParty()[0].moveset = []; await runMysteryEncounterToEnd(game, 2, { pokemonNo: 1 }); expect(leaveEncounterWithoutBattleSpy).toBeCalled(); diff --git a/src/test/mystery-encounter/encounters/teleporting-hijinks-encounter.test.ts b/src/test/mystery-encounter/encounters/teleporting-hijinks-encounter.test.ts index 1510a2eb694..13860e83baa 100644 --- a/src/test/mystery-encounter/encounters/teleporting-hijinks-encounter.test.ts +++ b/src/test/mystery-encounter/encounters/teleporting-hijinks-encounter.test.ts @@ -186,7 +186,7 @@ describe("Teleporting Hijinks - Mystery Encounter", () => { expect([Biome.SPACE, Biome.ISLAND, Biome.LABORATORY, Biome.FAIRY_CAVE]).toContain(scene.arena.biomeType); }); - it("should start a battle against an enraged boss", async () => { + it("should start a battle against an enraged boss", { retry: 5 }, async () => { await game.runToMysteryEncounter(MysteryEncounterType.TELEPORTING_HIJINKS, defaultParty); await runMysteryEncounterToEnd(game, 1, undefined, true); const enemyField = scene.getEnemyField(); diff --git a/src/test/mystery-encounter/encounters/uncommon-breed-encounter.test.ts b/src/test/mystery-encounter/encounters/uncommon-breed-encounter.test.ts index b214fb9d942..86ba0b8161b 100644 --- a/src/test/mystery-encounter/encounters/uncommon-breed-encounter.test.ts +++ b/src/test/mystery-encounter/encounters/uncommon-breed-encounter.test.ts @@ -21,6 +21,9 @@ import { getPokemonSpecies } from "#app/data/pokemon-species"; import { BerryType } from "#enums/berry-type"; import { StatStageChangePhase } from "#app/phases/stat-stage-change-phase"; import { Stat } from "#enums/stat"; +import { BerryModifier } from "#app/modifier/modifier"; +import { generateModifierType } from "#app/data/mystery-encounters/utils/encounter-phase-utils"; +import { modifierTypes } from "#app/modifier/modifier-type"; const namespace = "mysteryEncounter:uncommonBreed"; const defaultParty = [Species.LAPRAS, Species.GENGAR, Species.ABRA]; @@ -164,8 +167,11 @@ describe("Uncommon Breed - Mystery Encounter", () => { }); it("should NOT be selectable if the player doesn't have enough berries", async () => { - game.override.startingHeldItems([]); await game.runToMysteryEncounter(MysteryEncounterType.UNCOMMON_BREED, defaultParty); + // Clear out any pesky mods that slipped through test spin-up + scene.modifiers.forEach(mod => { + scene.removeModifier(mod); + }); await game.phaseInterceptor.to(MysteryEncounterPhase, false); const encounterPhase = scene.getCurrentPhase(); @@ -184,11 +190,21 @@ describe("Uncommon Breed - Mystery Encounter", () => { }); it("Should skip fight when player meets requirements", async () => { - game.override.startingHeldItems([{name: "BERRY", count: 2, type: BerryType.SITRUS}, {name: "BERRY", count: 3, type: BerryType.GANLON}]); const leaveEncounterWithoutBattleSpy = vi.spyOn(EncounterPhaseUtils, "leaveEncounterWithoutBattle"); await game.runToMysteryEncounter(MysteryEncounterType.UNCOMMON_BREED, defaultParty); + // Berries on party lead + const sitrus = generateModifierType(scene, modifierTypes.BERRY, [BerryType.SITRUS])!; + const sitrusMod = sitrus.newModifier(scene.getParty()[0]) as BerryModifier; + sitrusMod.stackCount = 2; + await scene.addModifier(sitrusMod, true, false, false, true); + const ganlon = generateModifierType(scene, modifierTypes.BERRY, [BerryType.GANLON])!; + const ganlonMod = ganlon.newModifier(scene.getParty()[0]) as BerryModifier; + ganlonMod.stackCount = 3; + await scene.addModifier(ganlonMod, true, false, false, true); + await scene.updateModifiers(true); + await runMysteryEncounterToEnd(game, 2); expect(leaveEncounterWithoutBattleSpy).toBeCalled(); diff --git a/src/test/utils/gameWrapper.ts b/src/test/utils/gameWrapper.ts index 1cf01a3a8c8..fb0bd2c02e5 100644 --- a/src/test/utils/gameWrapper.ts +++ b/src/test/utils/gameWrapper.ts @@ -227,7 +227,7 @@ export default class GameWrapper { }; this.scene.make = new MockGameObjectCreator(mockTextureManager); this.scene.time = new MockClock(this.scene); - this.scene.remove = vi.fn(); + this.scene.remove = vi.fn(); // TODO: this should be stubbed differently } } diff --git a/src/test/utils/mocks/mockTextureManager.ts b/src/test/utils/mocks/mockTextureManager.ts index ca8065bef97..ce19d6b6432 100644 --- a/src/test/utils/mocks/mockTextureManager.ts +++ b/src/test/utils/mocks/mockTextureManager.ts @@ -7,7 +7,6 @@ import MockSprite from "#test/utils/mocks/mocksContainer/mockSprite"; import MockText from "#test/utils/mocks/mocksContainer/mockText"; import MockTexture from "#test/utils/mocks/mocksContainer/mockTexture"; import { MockGameObject } from "./mockGameObject"; -import { vi } from "vitest"; import { MockVideoGameObject } from "./mockVideoGameObject"; /** @@ -36,7 +35,7 @@ export default class MockTextureManager { text: this.text.bind(this), bitmapText: this.text.bind(this), displayList: this.displayList, - video: vi.fn(() => new MockVideoGameObject()), + video: () => new MockVideoGameObject(), }; } diff --git a/src/test/utils/mocks/mocksContainer/mockContainer.ts b/src/test/utils/mocks/mocksContainer/mockContainer.ts index 5317f796384..05dad327dc6 100644 --- a/src/test/utils/mocks/mocksContainer/mockContainer.ts +++ b/src/test/utils/mocks/mocksContainer/mockContainer.ts @@ -1,5 +1,4 @@ import MockTextureManager from "#test/utils/mocks/mockTextureManager"; -import { vi } from "vitest"; import { MockGameObject } from "../mockGameObject"; export default class MockContainer implements MockGameObject { @@ -36,7 +35,9 @@ export default class MockContainer implements MockGameObject { // same as remove or destroy } - removeBetween = vi.fn((startIndex, endIndex, destroyChild) => {}); + removeBetween(startIndex, endIndex, destroyChild) { + // Removes multiple children across an index range + } addedToScene() { // This callback is invoked when this Game Object is added to a Scene. @@ -154,7 +155,9 @@ export default class MockContainer implements MockGameObject { // Sends this Game Object to the back of its parent's display list. } - moveTo = vi.fn((obj) => {}); + moveTo(obj) { + // Moves this Game Object to the given index in the list. + } moveAbove(obj) { // Moves this Game Object to be above the given Game Object in the display list. @@ -164,9 +167,9 @@ export default class MockContainer implements MockGameObject { // Moves this Game Object to be below the given Game Object in the display list. } - setName = (name: string) => { + setName(name: string) { this.name = name; - }; + } bringToTop(obj) { // Brings this Game Object to the top of its parents display list. @@ -210,9 +213,9 @@ export default class MockContainer implements MockGameObject { return this.list; } - getByName = vi.fn((key: string) => { + getByName(key: string) { return this.list.find(v => v.name === key) ?? new MockContainer(this.textureManager, 0, 0); - }); + } disableInteractive = () => null; } diff --git a/src/test/utils/mocks/mocksContainer/mockText.ts b/src/test/utils/mocks/mocksContainer/mockText.ts index f3debb6d583..5eb5eae5494 100644 --- a/src/test/utils/mocks/mocksContainer/mockText.ts +++ b/src/test/utils/mocks/mocksContainer/mockText.ts @@ -79,19 +79,19 @@ export default class MockText implements MockGameObject { return result; } - showText = vi.fn((text: string, delay?: integer | null, callback?: Function | null, callbackDelay?: integer | null, prompt?: boolean | null, promptDelay?: integer | null) => { + showText(text: string, delay?: integer | null, callback?: Function | null, callbackDelay?: integer | null, prompt?: boolean | null, promptDelay?: integer | null) { this.scene.messageWrapper.showText(text, delay, callback, callbackDelay, prompt, promptDelay); if (callback) { callback(); } - }); + } - showDialogue = vi.fn((keyOrText: string, name: string | undefined, delay: integer | null = 0, callback: Function, callbackDelay?: integer, promptDelay?: integer) => { + showDialogue(keyOrText: string, name: string | undefined, delay: integer | null = 0, callback: Function, callbackDelay?: integer, promptDelay?: integer) { this.scene.messageWrapper.showDialogue(keyOrText, name, delay, callback, callbackDelay, promptDelay); if (callback) { callback(); } - }); + } setScale(scale) { // return this.phaserText.setScale(scale); @@ -200,9 +200,9 @@ export default class MockText implements MockGameObject { }; } - setColor = (color: string) => { + setColor(color: string) { this.color = color; - }; + } setInteractive = () => null; @@ -230,9 +230,9 @@ export default class MockText implements MockGameObject { // return this.phaserText.setAlpha(alpha); } - setName = (name: string) => { + setName(name: string) { this.name = name; - }; + } setAlign(align) { // return this.phaserText.setAlign(align); @@ -256,9 +256,13 @@ export default class MockText implements MockGameObject { }; } - disableInteractive = vi.fn(); + disableInteractive() { + // Disables interaction with this Game Object. + } - clearTint = vi.fn(); + clearTint() { + // Clears tint on this Game Object. + } add(obj) { // Adds a child to this Game Object. diff --git a/src/test/utils/phaseInterceptor.ts b/src/test/utils/phaseInterceptor.ts index b2e9845a32e..cdf0ad41057 100644 --- a/src/test/utils/phaseInterceptor.ts +++ b/src/test/utils/phaseInterceptor.ts @@ -126,7 +126,6 @@ export default class PhaseInterceptor { [MysteryEncounterBattlePhase, this.startPhase], [MysteryEncounterRewardsPhase, this.startPhase], [PostMysteryEncounterPhase, this.startPhase], - [LearnMovePhase, this.startPhase], [ModifierRewardPhase, this.startPhase], [PartyExpPhase, this.startPhase] ];