From f7a3c0ea008d5ca552b0247835bcd34484dff74e Mon Sep 17 00:00:00 2001 From: NightKev <34855794+DayKev@users.noreply.github.com> Date: Mon, 18 Nov 2024 21:42:27 -0800 Subject: [PATCH] Add tests for Honey Gather --- src/test/abilities/honey_gather.test.ts | 74 +++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 src/test/abilities/honey_gather.test.ts diff --git a/src/test/abilities/honey_gather.test.ts b/src/test/abilities/honey_gather.test.ts new file mode 100644 index 00000000000..fc9d6cdd150 --- /dev/null +++ b/src/test/abilities/honey_gather.test.ts @@ -0,0 +1,74 @@ +import type { CommandPhase } from "#app/phases/command-phase"; +import { Command } from "#app/ui/command-ui-handler"; +import { Abilities } from "#enums/abilities"; +import { Moves } from "#enums/moves"; +import { Species } from "#enums/species"; +import GameManager from "#test/utils/gameManager"; +import Phaser from "phaser"; +import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest"; + +describe("Abilities - Honey Gather", () => { + let phaserGame: Phaser.Game; + let game: GameManager; + + beforeAll(() => { + phaserGame = new Phaser.Game({ + type: Phaser.HEADLESS, + }); + }); + + afterEach(() => { + game.phaseInterceptor.restoreOg(); + }); + + beforeEach(() => { + game = new GameManager(phaserGame); + game.override + .moveset([ Moves.SPLASH, Moves.ROAR, Moves.THUNDERBOLT ]) + .startingLevel(100) + .ability(Abilities.HONEY_GATHER) + .passiveAbility(Abilities.RUN_AWAY) + .battleType("single") + .disableCrits() + .enemySpecies(Species.MAGIKARP) + .enemyAbility(Abilities.BALL_FETCH) + .enemyMoveset(Moves.SPLASH); + }); + + it("should give money when winning a battle", async () => { + await game.classicMode.startBattle([ Species.MILOTIC ]); + game.scene.money = 1000; + + game.move.select(Moves.THUNDERBOLT); + await game.toNextWave(); + + expect(game.scene.money).toBeGreaterThan(1000); + }); + + it("should not give money when the enemy pokemon flees", async () => { + await game.classicMode.startBattle([ Species.MILOTIC ]); + game.scene.money = 1000; + + game.move.select(Moves.ROAR); + await game.toNextTurn(); + + expect(game.scene.money).toBe(1000); + expect(game.scene.currentBattle.waveIndex).toBe(2); + }); + + it("should not give money when the player flees", async () => { + await game.classicMode.startBattle([ Species.MILOTIC ]); + game.scene.money = 1000; + + // something weird is going on with the test framework, so this is required to prevent a crash + const enemy = game.scene.getEnemyPokemon()!; + vi.spyOn(enemy, "scene", "get").mockReturnValue(game.scene); + + const commandPhase = game.scene.getCurrentPhase() as CommandPhase; + commandPhase.handleCommand(Command.RUN, 0); + await game.toNextTurn(); + + expect(game.scene.money).toBe(1000); + expect(game.scene.currentBattle.waveIndex).toBe(2); + }); +});