[Enhancement] Optimize Unit tests (#2444)

* Optimize Unit tests

- Battery
- Unseen Fist
- Rage Powder
- Follow Me
- Spotlight
- Power Spot

* Fix Screen Cleaner unit test bug
This commit is contained in:
innerthunder 2024-06-20 02:11:29 -07:00 committed by GitHub
parent 07b9f5476a
commit c803cb5cb0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 14 additions and 23 deletions

View File

@ -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);

View File

@ -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);

View File

@ -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 () => {

View File

@ -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);

View File

@ -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));

View File

@ -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));

View File

@ -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);