From c803cb5cb0dd0d1811231d5c1059bdab149d754c Mon Sep 17 00:00:00 2001 From: innerthunder <168692175+innerthunder@users.noreply.github.com> Date: Thu, 20 Jun 2024 02:11:29 -0700 Subject: [PATCH] [Enhancement] Optimize Unit tests (#2444) * Optimize Unit tests - Battery - Unseen Fist - Rage Powder - Follow Me - Spotlight - Power Spot * Fix Screen Cleaner unit test bug --- src/test/abilities/battery.test.ts | 7 ------- src/test/abilities/power_spot.test.ts | 7 ------- src/test/abilities/screen_cleaner.test.ts | 1 + src/test/abilities/unseen_fist.test.ts | 3 ++- src/test/moves/follow_me.test.ts | 9 +++++---- src/test/moves/rage_powder.test.ts | 5 +++-- src/test/moves/spotlight.test.ts | 5 +++-- 7 files changed, 14 insertions(+), 23 deletions(-) diff --git a/src/test/abilities/battery.test.ts b/src/test/abilities/battery.test.ts index 93bac836f61..4a5cdc47172 100644 --- a/src/test/abilities/battery.test.ts +++ b/src/test/abilities/battery.test.ts @@ -3,7 +3,6 @@ import Phaser from "phaser"; import GameManager from "#app/test/utils/gameManager"; import * as overrides from "#app/overrides"; import { Species } from "#enums/species"; -import { TurnEndPhase, } from "#app/phases"; import { Moves } from "#enums/moves"; import { getMovePosition } from "#app/test/utils/gameManagerUtils"; import Move, { allMoves, MoveCategory } from "#app/data/move.js"; @@ -44,8 +43,6 @@ describe("Abilities - Battery", () => { const multiplier = getAttrPowerMultiplier(game.scene.getPlayerField()[1]); const appliedPower = getAppliedMovePower(game.scene.getEnemyField()[0], game.scene.getPlayerField()[0], allMoves[moveToBeUsed]); - await game.phaseInterceptor.to(TurnEndPhase); - expect(appliedPower).not.toBe(undefined); expect(appliedPower).not.toBe(basePower); expect(appliedPower).toBe(basePower * multiplier); @@ -63,8 +60,6 @@ describe("Abilities - Battery", () => { const multiplier = getAttrPowerMultiplier(game.scene.getPlayerField()[1]); const appliedPower = getAppliedMovePower(game.scene.getEnemyField()[0], game.scene.getPlayerField()[0], allMoves[moveToBeUsed]); - await game.phaseInterceptor.to(TurnEndPhase); - expect(appliedPower).not.toBe(undefined); expect(appliedPower).toBe(basePower); expect(appliedPower).not.toBe(basePower * multiplier); @@ -82,8 +77,6 @@ describe("Abilities - Battery", () => { const multiplier = getAttrPowerMultiplier(game.scene.getPlayerField()[0]); const appliedPower = getAppliedMovePower(game.scene.getEnemyField()[0], game.scene.getPlayerField()[0], allMoves[moveToBeUsed]); - await game.phaseInterceptor.to(TurnEndPhase); - expect(appliedPower).not.toBe(undefined); expect(appliedPower).toBe(basePower); expect(appliedPower).not.toBe(basePower * multiplier); diff --git a/src/test/abilities/power_spot.test.ts b/src/test/abilities/power_spot.test.ts index 5450aee9742..3bf2e7b72d2 100644 --- a/src/test/abilities/power_spot.test.ts +++ b/src/test/abilities/power_spot.test.ts @@ -3,7 +3,6 @@ import Phaser from "phaser"; import GameManager from "#app/test/utils/gameManager"; import * as overrides from "#app/overrides"; import { Species } from "#enums/species"; -import { TurnEndPhase, } from "#app/phases"; import { Moves } from "#enums/moves"; import { getMovePosition } from "#app/test/utils/gameManagerUtils"; import Move, { allMoves, MoveCategory } from "#app/data/move.js"; @@ -44,8 +43,6 @@ describe("Abilities - Power Spot", () => { const multiplier = getAttrPowerMultiplier(game.scene.getPlayerField()[1]); const appliedPower = getAppliedMovePower(game.scene.getEnemyField()[0], game.scene.getPlayerField()[0], allMoves[moveToBeUsed]); - await game.phaseInterceptor.to(TurnEndPhase); - expect(appliedPower).not.toBe(undefined); expect(appliedPower).not.toBe(basePower); expect(appliedPower).toBe(basePower * multiplier); @@ -63,8 +60,6 @@ describe("Abilities - Power Spot", () => { const multiplier = getAttrPowerMultiplier(game.scene.getPlayerField()[1]); const appliedPower = getAppliedMovePower(game.scene.getEnemyField()[0], game.scene.getPlayerField()[0], allMoves[moveToBeUsed]); - await game.phaseInterceptor.to(TurnEndPhase); - expect(appliedPower).not.toBe(undefined); expect(appliedPower).not.toBe(basePower); expect(appliedPower).toBe(basePower * multiplier); @@ -82,8 +77,6 @@ describe("Abilities - Power Spot", () => { const multiplier = getAttrPowerMultiplier(game.scene.getPlayerField()[0]); const appliedPower = getAppliedMovePower(game.scene.getEnemyField()[0], game.scene.getPlayerField()[0], allMoves[moveToBeUsed]); - await game.phaseInterceptor.to(TurnEndPhase); - expect(appliedPower).not.toBe(undefined); expect(appliedPower).toBe(basePower); expect(appliedPower).not.toBe(basePower * multiplier); diff --git a/src/test/abilities/screen_cleaner.test.ts b/src/test/abilities/screen_cleaner.test.ts index 1c9943fbfc8..d790469e952 100644 --- a/src/test/abilities/screen_cleaner.test.ts +++ b/src/test/abilities/screen_cleaner.test.ts @@ -27,6 +27,7 @@ describe("Abilities - Screen Cleaner", () => { game = new GameManager(phaserGame); vi.spyOn(overrides, "SINGLE_BATTLE_OVERRIDE", "get").mockReturnValue(true); vi.spyOn(overrides, "ABILITY_OVERRIDE", "get").mockReturnValue(Abilities.SCREEN_CLEANER); + vi.spyOn(overrides, "OPP_SPECIES_OVERRIDE", "get").mockReturnValue(Species.SHUCKLE); }); it("removes Aurora Veil", async () => { diff --git a/src/test/abilities/unseen_fist.test.ts b/src/test/abilities/unseen_fist.test.ts index a799e203f03..c53be8c82a4 100644 --- a/src/test/abilities/unseen_fist.test.ts +++ b/src/test/abilities/unseen_fist.test.ts @@ -31,6 +31,7 @@ describe("Abilities - Unseen Fist", () => { vi.spyOn(Overrides, "OPP_SPECIES_OVERRIDE", "get").mockReturnValue(Species.SNORLAX); vi.spyOn(Overrides, "OPP_MOVESET_OVERRIDE", "get").mockReturnValue([Moves.PROTECT, Moves.PROTECT, Moves.PROTECT, Moves.PROTECT]); vi.spyOn(Overrides, "STARTING_LEVEL_OVERRIDE", "get").mockReturnValue(100); + vi.spyOn(Overrides, "OPP_LEVEL_OVERRIDE", "get").mockReturnValue(100); }); test( @@ -81,7 +82,7 @@ async function testUnseenFistHitResult(game: GameManager, attackMove: Moves, pro const enemyStartingHp = enemyPokemon.hp; game.doAttack(getMovePosition(game.scene, 0, attackMove)); - await game.phaseInterceptor.to(TurnEndPhase); + await game.phaseInterceptor.to(TurnEndPhase, false); if (shouldSucceed) { expect(enemyPokemon.hp).toBeLessThan(enemyStartingHp); diff --git a/src/test/moves/follow_me.test.ts b/src/test/moves/follow_me.test.ts index 54b972e7cc0..584c7c62dbf 100644 --- a/src/test/moves/follow_me.test.ts +++ b/src/test/moves/follow_me.test.ts @@ -36,6 +36,7 @@ describe("Moves - Follow Me", () => { vi.spyOn(overrides, "STARTER_SPECIES_OVERRIDE", "get").mockReturnValue(Species.AMOONGUSS); vi.spyOn(overrides, "OPP_SPECIES_OVERRIDE", "get").mockReturnValue(Species.SNORLAX); vi.spyOn(overrides, "STARTING_LEVEL_OVERRIDE", "get").mockReturnValue(100); + vi.spyOn(overrides, "OPP_LEVEL_OVERRIDE", "get").mockReturnValue(100); vi.spyOn(overrides, "MOVESET_OVERRIDE", "get").mockReturnValue([ Moves.FOLLOW_ME, Moves.RAGE_POWDER, Moves.SPOTLIGHT, Moves.QUICK_ATTACK ]); vi.spyOn(overrides, "OPP_MOVESET_OVERRIDE", "get").mockReturnValue([Moves.TACKLE,Moves.TACKLE,Moves.TACKLE,Moves.TACKLE]); }); @@ -62,7 +63,7 @@ describe("Moves - Follow Me", () => { await game.phaseInterceptor.to(SelectTargetPhase, false); game.doSelectTarget(BattlerIndex.ENEMY); - await game.phaseInterceptor.to(TurnEndPhase); + await game.phaseInterceptor.to(TurnEndPhase, false); expect(playerPokemon[0].hp).toBeLessThan(200); expect(playerPokemon[1].hp).toBe(200); @@ -88,7 +89,7 @@ describe("Moves - Follow Me", () => { await game.phaseInterceptor.to(CommandPhase); game.doAttack(getMovePosition(game.scene, 1, Moves.FOLLOW_ME)); - await game.phaseInterceptor.to(TurnEndPhase); + await game.phaseInterceptor.to(TurnEndPhase, false); playerPokemon.sort((a, b) => a.getBattleStat(Stat.SPD) - b.getBattleStat(Stat.SPD)); @@ -124,7 +125,7 @@ describe("Moves - Follow Me", () => { game.doAttack(getMovePosition(game.scene, 1, Moves.QUICK_ATTACK)); await game.phaseInterceptor.to(SelectTargetPhase, false); game.doSelectTarget(BattlerIndex.ENEMY_2); - await game.phaseInterceptor.to(TurnEndPhase); + await game.phaseInterceptor.to(TurnEndPhase, false); // If redirection was bypassed, both enemies should be damaged enemyPokemon.forEach(p => expect(p.hp).toBeLessThan(200)); @@ -157,7 +158,7 @@ describe("Moves - Follow Me", () => { game.doAttack(getMovePosition(game.scene, 1, Moves.SNIPE_SHOT)); await game.phaseInterceptor.to(SelectTargetPhase, false); game.doSelectTarget(BattlerIndex.ENEMY_2); - await game.phaseInterceptor.to(TurnEndPhase); + await game.phaseInterceptor.to(TurnEndPhase, false); // If redirection was bypassed, both enemies should be damaged enemyPokemon.forEach(p => expect(p.hp).toBeLessThan(200)); diff --git a/src/test/moves/rage_powder.test.ts b/src/test/moves/rage_powder.test.ts index 6a204877150..35bce54f533 100644 --- a/src/test/moves/rage_powder.test.ts +++ b/src/test/moves/rage_powder.test.ts @@ -35,6 +35,7 @@ describe("Moves - Rage Powder", () => { vi.spyOn(overrides, "STARTER_SPECIES_OVERRIDE", "get").mockReturnValue(Species.AMOONGUSS); vi.spyOn(overrides, "OPP_SPECIES_OVERRIDE", "get").mockReturnValue(Species.SNORLAX); vi.spyOn(overrides, "STARTING_LEVEL_OVERRIDE", "get").mockReturnValue(100); + vi.spyOn(overrides, "OPP_LEVEL_OVERRIDE", "get").mockReturnValue(100); vi.spyOn(overrides, "MOVESET_OVERRIDE", "get").mockReturnValue([ Moves.FOLLOW_ME, Moves.RAGE_POWDER, Moves.SPOTLIGHT, Moves.QUICK_ATTACK ]); vi.spyOn(overrides, "OPP_MOVESET_OVERRIDE", "get").mockReturnValue([Moves.TACKLE,Moves.TACKLE,Moves.TACKLE,Moves.TACKLE]); }); @@ -64,7 +65,7 @@ describe("Moves - Rage Powder", () => { game.doAttack(getMovePosition(game.scene, 1, Moves.QUICK_ATTACK)); await game.phaseInterceptor.to(SelectTargetPhase, false); game.doSelectTarget(BattlerIndex.ENEMY_2); - await game.phaseInterceptor.to(TurnEndPhase); + await game.phaseInterceptor.to(TurnEndPhase, false); // If redirection was bypassed, both enemies should be damaged enemyPokemon.forEach(p => expect(p.hp).toBeLessThan(200)); @@ -98,7 +99,7 @@ describe("Moves - Rage Powder", () => { game.doAttack(getMovePosition(game.scene, 1, Moves.QUICK_ATTACK)); await game.phaseInterceptor.to(SelectTargetPhase, false); game.doSelectTarget(BattlerIndex.ENEMY_2); - await game.phaseInterceptor.to(TurnEndPhase); + await game.phaseInterceptor.to(TurnEndPhase, false); // If redirection was bypassed, both enemies should be damaged enemyPokemon.forEach(p => expect(p.hp).toBeLessThan(200)); diff --git a/src/test/moves/spotlight.test.ts b/src/test/moves/spotlight.test.ts index 188207b713c..7ba01dcfb3a 100644 --- a/src/test/moves/spotlight.test.ts +++ b/src/test/moves/spotlight.test.ts @@ -35,6 +35,7 @@ describe("Moves - Spotlight", () => { vi.spyOn(overrides, "STARTER_SPECIES_OVERRIDE", "get").mockReturnValue(Species.AMOONGUSS); vi.spyOn(overrides, "OPP_SPECIES_OVERRIDE", "get").mockReturnValue(Species.SNORLAX); vi.spyOn(overrides, "STARTING_LEVEL_OVERRIDE", "get").mockReturnValue(100); + vi.spyOn(overrides, "OPP_LEVEL_OVERRIDE", "get").mockReturnValue(100); vi.spyOn(overrides, "MOVESET_OVERRIDE", "get").mockReturnValue([ Moves.FOLLOW_ME, Moves.RAGE_POWDER, Moves.SPOTLIGHT, Moves.QUICK_ATTACK ]); vi.spyOn(overrides, "OPP_MOVESET_OVERRIDE", "get").mockReturnValue([Moves.TACKLE,Moves.TACKLE,Moves.TACKLE,Moves.TACKLE]); }); @@ -62,7 +63,7 @@ describe("Moves - Spotlight", () => { game.doAttack(getMovePosition(game.scene, 1, Moves.QUICK_ATTACK)); await game.phaseInterceptor.to(SelectTargetPhase, false); game.doSelectTarget(BattlerIndex.ENEMY_2); - await game.phaseInterceptor.to(TurnEndPhase); + await game.phaseInterceptor.to(TurnEndPhase, false); expect(enemyPokemon[0].hp).toBeLessThan(200); expect(enemyPokemon[1].hp).toBe(200); @@ -102,7 +103,7 @@ describe("Moves - Spotlight", () => { game.doAttack(getMovePosition(game.scene, 1, Moves.QUICK_ATTACK)); await game.phaseInterceptor.to(SelectTargetPhase, false); game.doSelectTarget(attackTarget); - await game.phaseInterceptor.to(TurnEndPhase); + await game.phaseInterceptor.to(TurnEndPhase, false); expect(enemyPokemon[1].hp).toBeLessThan(200); expect(enemyPokemon[0].hp).toBe(200);