pokerogue/src/test/moves/hard_press.test.ts
Adrian T 8d5bfa51e8
[Enhancement] Decouple move power calculation from Pokemon.apply(), Fixes Power Spot & Battery not boosting ally's move (#2984)
* refactor power calc, fix battery & power spot

* fix hard press unit test

* fix hard press

* refactor tests

* use sypOn hp instead

* rename method

* cleanup tests

* improve tests

* use slow vs fast pokemon

* fix steely spirit test

* fix steely spirit for real this time

* remove unnecessary test

* address pr feedback

* add removed code
2024-07-14 00:28:39 -04:00

89 lines
3.2 KiB
TypeScript

import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
import Phaser from "phaser";
import GameManager from "#app/test/utils/gameManager";
import overrides from "#app/overrides";
import { Species } from "#enums/species";
import {
MoveEffectPhase
} from "#app/phases";
import { Moves } from "#enums/moves";
import { getMovePosition } from "#app/test/utils/gameManagerUtils";
import { Abilities } from "#enums/abilities";
import { allMoves } from "#app/data/move.js";
describe("Moves - Hard Press", () => {
let phaserGame: Phaser.Game;
let game: GameManager;
const moveToCheck = allMoves[Moves.HARD_PRESS];
beforeAll(() => {
phaserGame = new Phaser.Game({
type: Phaser.HEADLESS,
});
});
afterEach(() => {
game.phaseInterceptor.restoreOg();
});
beforeEach(() => {
game = new GameManager(phaserGame);
vi.spyOn(overrides, "SINGLE_BATTLE_OVERRIDE", "get").mockReturnValue(true);
vi.spyOn(overrides, "ABILITY_OVERRIDE", "get").mockReturnValue(Abilities.BALL_FETCH);
vi.spyOn(overrides, "OPP_SPECIES_OVERRIDE", "get").mockReturnValue(Species.MUNCHLAX);
vi.spyOn(overrides, "OPP_ABILITY_OVERRIDE", "get").mockReturnValue(Abilities.BALL_FETCH);
vi.spyOn(overrides, "OPP_MOVESET_OVERRIDE", "get").mockReturnValue([Moves.SPLASH, Moves.SPLASH, Moves.SPLASH, Moves.SPLASH]);
vi.spyOn(overrides, "MOVESET_OVERRIDE", "get").mockReturnValue([Moves.HARD_PRESS]);
vi.spyOn(moveToCheck, "calculateBattlePower");
});
it("should return 100 power if target HP ratio is at 100%", async () => {
await game.startBattle([Species.PIKACHU]);
game.doAttack(getMovePosition(game.scene, 0, Moves.HARD_PRESS));
await game.phaseInterceptor.to(MoveEffectPhase);
expect(moveToCheck.calculateBattlePower).toHaveReturnedWith(100);
});
it("should return 50 power if target HP ratio is at 50%", async () => {
await game.startBattle([Species.PIKACHU]);
const targetHpRatio = .5;
const enemy = game.scene.getEnemyPokemon();
vi.spyOn(enemy, "getHpRatio").mockReturnValue(targetHpRatio);
game.doAttack(getMovePosition(game.scene, 0, Moves.HARD_PRESS));
await game.phaseInterceptor.to(MoveEffectPhase);
expect(moveToCheck.calculateBattlePower).toHaveReturnedWith(50);
});
it("should return 1 power if target HP ratio is at 1%", async () => {
await game.startBattle([Species.PIKACHU]);
const targetHpRatio = .01;
const enemy = game.scene.getEnemyPokemon();
vi.spyOn(enemy, "getHpRatio").mockReturnValue(targetHpRatio);
game.doAttack(getMovePosition(game.scene, 0, Moves.HARD_PRESS));
await game.phaseInterceptor.to(MoveEffectPhase);
expect(moveToCheck.calculateBattlePower).toHaveReturnedWith(1);
});
it("should return 1 power if target HP ratio is less than 1%", async () => {
await game.startBattle([Species.PIKACHU]);
const targetHpRatio = .005;
const enemy = game.scene.getEnemyPokemon();
vi.spyOn(enemy, "getHpRatio").mockReturnValue(targetHpRatio);
game.doAttack(getMovePosition(game.scene, 0, Moves.HARD_PRESS));
await game.phaseInterceptor.to(MoveEffectPhase);
expect(moveToCheck.calculateBattlePower).toHaveReturnedWith(1);
});
});