add test to cover hp update after evo (#4)

- add evolution phase to phase interceptor
- add mock for video game object
- add returning video mock on add.video()
This commit is contained in:
flx-sta 2024-08-16 10:09:31 +02:00 committed by NightKev
parent 9cca4131c2
commit 0a036d1720
4 changed files with 45 additions and 0 deletions

View File

@ -1,9 +1,12 @@
import { pokemonEvolutions, SpeciesFormEvolution, SpeciesWildEvolutionDelay } from "#app/data/pokemon-evolutions.js";
import { Abilities } from "#app/enums/abilities.js";
import { Moves } from "#app/enums/moves.js";
import { Species } from "#app/enums/species.js";
import GameManager from "#test/utils/gameManager";
import Phaser from "phaser";
import { afterEach, beforeAll, beforeEach, describe, expect, it } from "vitest";
import { getMovePosition } from "./utils/gameManagerUtils";
import { SPLASH_ONLY } from "./utils/testUtils";
describe("Evolution", () => {
let phaserGame: Phaser.Game;
@ -89,4 +92,29 @@ describe("Evolution", () => {
expect(speciesFormEvo.wildDelay).toBe(SpeciesWildEvolutionDelay.NONE);
});
it("should increase both HP and max HP when evolving", async () => {
game.override.moveset([Moves.SURF])
.enemySpecies(Species.GOLEM)
.enemyMoveset(SPLASH_ONLY)
.startingWave(21)
.startingLevel(16)
.enemyLevel(50);
await game.startBattle([Species.TOTODILE]);
const totodile = game.scene.getPlayerPokemon()!;
const hpBefore = totodile.hp;
const enemyGolem = game.scene.getEnemyPokemon()!;
enemyGolem.hp = 1;
expect(totodile.hp).toBe(totodile.getMaxHp());
game.doAttack(getMovePosition(game.scene, 0, Moves.SURF));
await game.phaseInterceptor.to("EvolutionPhase");
expect(totodile.hp).toBe(totodile.getMaxHp());
expect(totodile.hp).toBeGreaterThan(hpBefore);
}, TIMEOUT);
});

View File

@ -7,6 +7,8 @@ import MockText from "#test/utils/mocks/mocksContainer/mockText";
import MockPolygon from "#test/utils/mocks/mocksContainer/mockPolygon";
import { MockGameObject } from "./mockGameObject";
import MockTexture from "#test/utils/mocks/mocksContainer/mockTexture";
import { vi } from "vitest";
import { MockVideoGameObject } from "./mockVideoGameObject";
/**
* Stub class for Phaser.Textures.TextureManager
@ -34,6 +36,7 @@ export default class MockTextureManager {
text: this.text.bind(this),
bitmapText: this.text.bind(this),
displayList: this.displayList,
video: vi.fn(() => new MockVideoGameObject()),
};
}

View File

@ -0,0 +1,12 @@
import { vi } from "vitest";
import { MockGameObject } from "./mockGameObject";
export class MockVideoGameObject implements MockGameObject {
constructor() {}
public play = vi.fn();
public stop = vi.fn(() => this);
public setOrigin = vi.fn();
public setScale = vi.fn();
public setVisible = vi.fn();
}

View File

@ -38,6 +38,7 @@ import UI, { Mode } from "#app/ui/ui";
import { Phase } from "#app/phase";
import ErrorInterceptor from "#app/test/utils/errorInterceptor";
import { QuietFormChangePhase } from "#app/form-change-phase";
import { EvolutionPhase } from "#app/evolution-phase.js";
export default class PhaseInterceptor {
public scene;
@ -92,6 +93,7 @@ export default class PhaseInterceptor {
[QuietFormChangePhase, this.startPhase],
[SwitchPhase, this.startPhase],
[SwitchSummonPhase, this.startPhase],
[EvolutionPhase, this.startPhase],
];
private endBySetMode = [