From 1cfbecff368840c6ee4c9ce3b023d00a0607a7f6 Mon Sep 17 00:00:00 2001 From: Zach Day Date: Mon, 12 Aug 2024 22:41:57 -0400 Subject: [PATCH] Rework tests --- src/test/abilities/aftermath.test.ts | 44 +++++++++++------------- src/test/abilities/damp.test.ts | 51 ++++++++++++++-------------- 2 files changed, 44 insertions(+), 51 deletions(-) diff --git a/src/test/abilities/aftermath.test.ts b/src/test/abilities/aftermath.test.ts index db857e87c95..888f7b8b3ee 100644 --- a/src/test/abilities/aftermath.test.ts +++ b/src/test/abilities/aftermath.test.ts @@ -1,11 +1,11 @@ -import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest"; +import { afterEach, beforeAll, beforeEach, describe, expect, it } from "vitest"; import GameManager from "#test/utils/gameManager"; import { getMovePosition } from "#test/utils/gameManagerUtils"; -import * as overrides from "#app/overrides"; import { Moves } from "#enums/moves"; import { Abilities } from "#enums/abilities"; import { Species } from "#enums/species"; import { TurnEndPhase } from "#app/phases.js"; +import { SPLASH_ONLY } from "../utils/testUtils"; const TIMEOUT = 20 * 1000; @@ -25,26 +25,23 @@ describe("Abilities - Aftermath", () => { beforeEach(() => { game = new GameManager(phaserGame); - const moveToUse = Moves.SPLASH; - vi.spyOn(overrides, "SINGLE_BATTLE_OVERRIDE", "get").mockReturnValue(true); - vi.spyOn(overrides, "ABILITY_OVERRIDE", "get").mockReturnValue(Abilities.BATTLE_BOND); - vi.spyOn(overrides, "MOVESET_OVERRIDE", "get").mockReturnValue([moveToUse]); - vi.spyOn(overrides, "OPP_MOVESET_OVERRIDE", "get").mockReturnValue([Moves.TACKLE, Moves.TACKLE, Moves.TACKLE, Moves.TACKLE]); + game.override.battleType("single"); + game.override.ability(Abilities.NONE); + game.override.enemyAbility(Abilities.AFTERMATH); + game.override.enemyMoveset(SPLASH_ONLY); + game.override.enemySpecies(Species.BIDOOF); }); it("deals 25% of attacker's HP as damage to attacker when defeated by contact move", async () => { const moveToUse = Moves.TACKLE; - const enemyAbility = Abilities.AFTERMATH; - - vi.spyOn(overrides, "ABILITY_OVERRIDE", "get").mockReturnValue(Abilities.NONE); - vi.spyOn(overrides, "MOVESET_OVERRIDE", "get").mockReturnValue([moveToUse]); - vi.spyOn(overrides, "OPP_MOVESET_OVERRIDE", "get").mockReturnValue([Moves.SPLASH, Moves.NONE, Moves.NONE, Moves.NONE]); - vi.spyOn(overrides, "OPP_SPECIES_OVERRIDE", "get").mockReturnValue(Species.BIDOOF); - vi.spyOn(overrides, "OPP_ABILITY_OVERRIDE", "get").mockReturnValue(enemyAbility); + game.override.moveset(Array(4).fill(moveToUse)); await game.startBattle(); - game.scene.getEnemyParty()[0].hp = 1; + const player = game.scene.getPlayerPokemon()!; + const enemy = game.scene.getEnemyPokemon()!; + + enemy.hp = 1; game.doAttack(getMovePosition(game.scene, 0, moveToUse)); @@ -52,22 +49,19 @@ describe("Abilities - Aftermath", () => { expect(game.phaseInterceptor.log).toContain("FaintPhase"); expect(game.phaseInterceptor.log).toContain("ShowAbilityPhase"); - expect(game.scene.getParty()[0].hp).toBeCloseTo(Math.floor(game.scene.getParty()[0].getMaxHp() * 0.75)); + expect(player.hp).toBeCloseTo(Math.floor(player.getMaxHp() * 0.75)); }, TIMEOUT); it("does not activate on non-contact moves", async () => { const moveToUse = Moves.WATER_GUN; - const enemyAbility = Abilities.AFTERMATH; - - vi.spyOn(overrides, "ABILITY_OVERRIDE", "get").mockReturnValue(Abilities.NONE); - vi.spyOn(overrides, "MOVESET_OVERRIDE", "get").mockReturnValue([moveToUse]); - vi.spyOn(overrides, "OPP_MOVESET_OVERRIDE", "get").mockReturnValue([Moves.SPLASH, Moves.NONE, Moves.NONE, Moves.NONE]); - vi.spyOn(overrides, "OPP_SPECIES_OVERRIDE", "get").mockReturnValue(Species.BIDOOF); - vi.spyOn(overrides, "OPP_ABILITY_OVERRIDE", "get").mockReturnValue(enemyAbility); + game.override.moveset(Array(4).fill(moveToUse)); await game.startBattle(); - game.scene.getEnemyParty()[0].hp = 1; + const player = game.scene.getPlayerPokemon()!; + const enemy = game.scene.getEnemyPokemon()!; + + enemy.hp = 1; game.doAttack(getMovePosition(game.scene, 0, moveToUse)); @@ -75,6 +69,6 @@ describe("Abilities - Aftermath", () => { expect(game.phaseInterceptor.log).toContain("FaintPhase"); expect(game.phaseInterceptor.log).not.toContain("ShowAbilityPhase"); - expect(game.scene.getParty()[0].getHpRatio()).toBeCloseTo(1); + expect(player.getHpRatio()).toBeCloseTo(1); }, TIMEOUT); }); diff --git a/src/test/abilities/damp.test.ts b/src/test/abilities/damp.test.ts index 075f7d9b5d8..c78cfb40393 100644 --- a/src/test/abilities/damp.test.ts +++ b/src/test/abilities/damp.test.ts @@ -1,12 +1,12 @@ import { Abilities } from "#app/enums/abilities.js"; import { Moves } from "#app/enums/moves"; import { Species } from "#app/enums/species"; -import * as overrides from "#app/overrides"; -import { TurnEndPhase, TurnStartPhase } from "#app/phases"; +import { TurnEndPhase } from "#app/phases"; import GameManager from "#app/test/utils/gameManager"; import { getMovePosition } from "#app/test/utils/gameManagerUtils"; import Phaser from "phaser"; -import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest"; +import { afterEach, beforeAll, beforeEach, describe, expect, it } from "vitest"; +import { SPLASH_ONLY } from "../utils/testUtils"; const TIMEOUT = 20 * 1000; @@ -26,19 +26,19 @@ describe("Abilities - Damp", () => { beforeEach(() => { game = new GameManager(phaserGame); - vi.spyOn(overrides, "SINGLE_BATTLE_OVERRIDE", "get").mockReturnValue(true); - vi.spyOn(overrides, "NEVER_CRIT_OVERRIDE", "get").mockReturnValue(true); + game.override.battleType("single"); + game.override.disableCrits(); + game.override.enemySpecies(Species.BIDOOF); }); it("prevents explosive attacks used by others", async() => { const moveToUse = Moves.EXPLOSION; const enemyAbility = Abilities.DAMP; - vi.spyOn(overrides, "ABILITY_OVERRIDE", "get").mockReturnValue(Abilities.NONE); - vi.spyOn(overrides, "MOVESET_OVERRIDE", "get").mockReturnValue([moveToUse]); - vi.spyOn(overrides, "OPP_MOVESET_OVERRIDE", "get").mockReturnValue([Moves.SPLASH, Moves.NONE, Moves.NONE, Moves.NONE]); - vi.spyOn(overrides, "OPP_SPECIES_OVERRIDE", "get").mockReturnValue(Species.BIDOOF); - vi.spyOn(overrides, "OPP_ABILITY_OVERRIDE", "get").mockReturnValue(enemyAbility); + game.override.ability(Abilities.NONE); + game.override.moveset(Array(4).fill(moveToUse)); + game.override.enemyMoveset(SPLASH_ONLY); + game.override.enemyAbility(enemyAbility); await game.startBattle(); @@ -54,11 +54,11 @@ describe("Abilities - Damp", () => { const moveToUse = Moves.EXPLOSION; const playerAbility = Abilities.DAMP; - vi.spyOn(overrides, "ABILITY_OVERRIDE", "get").mockReturnValue(playerAbility); - vi.spyOn(overrides, "MOVESET_OVERRIDE", "get").mockReturnValue([moveToUse]); - vi.spyOn(overrides, "OPP_MOVESET_OVERRIDE", "get").mockReturnValue([Moves.SPLASH, Moves.NONE, Moves.NONE, Moves.NONE]); - vi.spyOn(overrides, "OPP_SPECIES_OVERRIDE", "get").mockReturnValue(Species.BIDOOF); - vi.spyOn(overrides, "OPP_ABILITY_OVERRIDE", "get").mockReturnValue(Abilities.NONE); + game.override.ability(playerAbility); + game.override.moveset(Array(4).fill(moveToUse)); + game.override.enemyMoveset(SPLASH_ONLY); + game.override.enemySpecies(Species.BIDOOF); + game.override.enemyAbility(Abilities.NONE); await game.startBattle(); @@ -76,11 +76,11 @@ describe("Abilities - Damp", () => { const playerAbility = Abilities.DAMP; const enemyAbility = Abilities.AFTERMATH; - vi.spyOn(overrides, "ABILITY_OVERRIDE", "get").mockReturnValue(playerAbility); - vi.spyOn(overrides, "MOVESET_OVERRIDE", "get").mockReturnValue([moveToUse]); - vi.spyOn(overrides, "OPP_MOVESET_OVERRIDE", "get").mockReturnValue([Moves.SPLASH, Moves.NONE, Moves.NONE, Moves.NONE]); - vi.spyOn(overrides, "OPP_SPECIES_OVERRIDE", "get").mockReturnValue(Species.BIDOOF); - vi.spyOn(overrides, "OPP_ABILITY_OVERRIDE", "get").mockReturnValue(enemyAbility); + game.override.ability(playerAbility); + game.override.moveset(Array(4).fill(moveToUse)); + game.override.enemyAbility(enemyAbility); + game.override.enemyMoveset(SPLASH_ONLY); + game.override.enemySpecies(Species.BIDOOF); await game.startBattle(); @@ -101,17 +101,16 @@ describe("Abilities - Damp", () => { const moveToUse = Moves.SPLASH; const playerAbility = Abilities.DAMP; - vi.spyOn(overrides, "ABILITY_OVERRIDE", "get").mockReturnValue(playerAbility); - vi.spyOn(overrides, "MOVESET_OVERRIDE", "get").mockReturnValue([moveToUse]); - vi.spyOn(overrides, "OPP_MOVESET_OVERRIDE", "get").mockReturnValue([Moves.EXPLOSION, Moves.SELF_DESTRUCT, Moves.MIND_BLOWN, Moves.MISTY_EXPLOSION]); - vi.spyOn(overrides, "OPP_SPECIES_OVERRIDE", "get").mockReturnValue(Species.BIDOOF); - vi.spyOn(overrides, "OPP_ABILITY_OVERRIDE", "get").mockReturnValue(Abilities.NONE); + game.override.ability(playerAbility); + game.override.moveset(Array(4).fill(moveToUse)); + game.override.enemyAbility(Abilities.NONE); + game.override.enemyMoveset([Moves.EXPLOSION, Moves.SELF_DESTRUCT, Moves.MIND_BLOWN, Moves.MISTY_EXPLOSION]); await game.startBattle(); game.doAttack(getMovePosition(game.scene, 0, moveToUse)); - await game.phaseInterceptor.to(TurnStartPhase); + await game.phaseInterceptor.to(TurnEndPhase); expect(game.phaseInterceptor.log).not.toContain("ShowAbilityPhase"); }, TIMEOUT);