Update tests

This commit is contained in:
NightKev 2024-09-05 18:22:58 -07:00
parent 93d488f0a5
commit c4ecd12faa
2 changed files with 45 additions and 76 deletions

View File

@ -1,11 +1,9 @@
import { afterEach, beforeAll, beforeEach, describe, expect, it } from "vitest";
import GameManager from "#test/utils/gameManager";
import { getMovePosition } from "#test/utils/gameManagerUtils";
import { Moves } from "#enums/moves";
import { Abilities } from "#enums/abilities"; import { Abilities } from "#enums/abilities";
import { Moves } from "#enums/moves";
import { Species } from "#enums/species"; import { Species } from "#enums/species";
import { TurnEndPhase } from "#app/phases.js"; import GameManager from "#test/utils/gameManager";
import { SPLASH_ONLY } from "../utils/testUtils"; import { SPLASH_ONLY } from "#test/utils/testUtils";
import { afterEach, beforeAll, beforeEach, describe, expect, it } from "vitest";
const TIMEOUT = 20 * 1000; const TIMEOUT = 20 * 1000;
@ -25,27 +23,26 @@ describe("Abilities - Aftermath", () => {
beforeEach(() => { beforeEach(() => {
game = new GameManager(phaserGame); game = new GameManager(phaserGame);
game.override.battleType("single"); game.override
game.override.ability(Abilities.NONE); .battleType("single")
game.override.enemyAbility(Abilities.AFTERMATH); .ability(Abilities.BALL_FETCH)
game.override.enemyMoveset(SPLASH_ONLY); .moveset([Moves.TACKLE, Moves.WATER_GUN])
game.override.enemySpecies(Species.BIDOOF); .enemyAbility(Abilities.AFTERMATH)
.enemyMoveset(SPLASH_ONLY)
.enemySpecies(Species.BIDOOF);
}); });
it("deals 25% of attacker's HP as damage to attacker when defeated by contact move", async () => { it("deals 25% of attacker's HP as damage to attacker when defeated by contact move", async () => {
const moveToUse = Moves.TACKLE; await game.classicMode.startBattle();
game.override.moveset(Array(4).fill(moveToUse));
await game.startBattle();
const player = game.scene.getPlayerPokemon()!; const player = game.scene.getPlayerPokemon()!;
const enemy = game.scene.getEnemyPokemon()!; const enemy = game.scene.getEnemyPokemon()!;
enemy.hp = 1; enemy.hp = 1;
game.doAttack(getMovePosition(game.scene, 0, moveToUse)); game.move.select(Moves.TACKLE);
await game.phaseInterceptor.to(TurnEndPhase); await game.phaseInterceptor.to("TurnEndPhase");
expect(game.phaseInterceptor.log).toContain("FaintPhase"); expect(game.phaseInterceptor.log).toContain("FaintPhase");
expect(game.phaseInterceptor.log).toContain("ShowAbilityPhase"); expect(game.phaseInterceptor.log).toContain("ShowAbilityPhase");
@ -53,22 +50,19 @@ describe("Abilities - Aftermath", () => {
}, TIMEOUT); }, TIMEOUT);
it("does not activate on non-contact moves", async () => { it("does not activate on non-contact moves", async () => {
const moveToUse = Moves.WATER_GUN; await game.classicMode.startBattle();
game.override.moveset(Array(4).fill(moveToUse));
await game.startBattle();
const player = game.scene.getPlayerPokemon()!; const player = game.scene.getPlayerPokemon()!;
const enemy = game.scene.getEnemyPokemon()!; const enemy = game.scene.getEnemyPokemon()!;
enemy.hp = 1; enemy.hp = 1;
game.doAttack(getMovePosition(game.scene, 0, moveToUse)); game.move.select(Moves.WATER_GUN);
await game.phaseInterceptor.to(TurnEndPhase); await game.phaseInterceptor.to("TurnEndPhase");
expect(game.phaseInterceptor.log).toContain("FaintPhase"); expect(game.phaseInterceptor.log).toContain("FaintPhase");
expect(game.phaseInterceptor.log).not.toContain("ShowAbilityPhase"); expect(game.phaseInterceptor.log).not.toContain("ShowAbilityPhase");
expect(player.getHpRatio()).toBeCloseTo(1); expect(player.isFullHp()).toBe(true);
}, TIMEOUT); }, TIMEOUT);
}); });

View File

@ -1,12 +1,10 @@
import { Abilities } from "#app/enums/abilities.js"; import { Abilities } from "#app/enums/abilities";
import { Moves } from "#app/enums/moves"; import { Moves } from "#app/enums/moves";
import { Species } from "#app/enums/species"; import { Species } from "#app/enums/species";
import { TurnEndPhase } from "#app/phases";
import GameManager from "#app/test/utils/gameManager"; import GameManager from "#app/test/utils/gameManager";
import { getMovePosition } from "#app/test/utils/gameManagerUtils"; import { SPLASH_ONLY } from "#test/utils/testUtils";
import Phaser from "phaser"; import Phaser from "phaser";
import { afterEach, beforeAll, beforeEach, describe, expect, it } from "vitest"; import { afterEach, beforeAll, beforeEach, describe, expect, it } from "vitest";
import { SPLASH_ONLY } from "../utils/testUtils";
const TIMEOUT = 20 * 1000; const TIMEOUT = 20 * 1000;
@ -26,45 +24,37 @@ describe("Abilities - Damp", () => {
beforeEach(() => { beforeEach(() => {
game = new GameManager(phaserGame); game = new GameManager(phaserGame);
game.override.battleType("single"); game.override
game.override.disableCrits(); .battleType("single")
game.override.enemySpecies(Species.BIDOOF); .disableCrits()
.enemySpecies(Species.BIDOOF)
.enemyMoveset(SPLASH_ONLY)
.enemyAbility(Abilities.BALL_FETCH)
.ability(Abilities.DAMP)
.moveset([Moves.EXPLOSION, Moves.TACKLE, Moves.SPLASH]);
}); });
it("prevents explosive attacks used by others", async() => { it("prevents explosive attacks used by others", async() => {
const moveToUse = Moves.EXPLOSION; game.override
const enemyAbility = Abilities.DAMP; .ability(Abilities.BALL_FETCH)
.enemyAbility(Abilities.DAMP);
game.override.ability(Abilities.NONE); await game.classicMode.startBattle();
game.override.moveset(Array(4).fill(moveToUse));
game.override.enemyMoveset(SPLASH_ONLY);
game.override.enemyAbility(enemyAbility);
await game.startBattle(); game.move.select(Moves.EXPLOSION);
game.doAttack(getMovePosition(game.scene, 0, moveToUse)); await game.phaseInterceptor.to("TurnEndPhase");
await game.phaseInterceptor.to(TurnEndPhase);
expect(game.phaseInterceptor.log).toContain("ShowAbilityPhase"); expect(game.phaseInterceptor.log).toContain("ShowAbilityPhase");
expect(game.phaseInterceptor.log).not.toContain("FaintPhase"); expect(game.phaseInterceptor.log).not.toContain("FaintPhase");
}, TIMEOUT); }, TIMEOUT);
it("prevents explosive attacks used by the battler with Damp", async() => { it("prevents explosive attacks used by the battler with Damp", async() => {
const moveToUse = Moves.EXPLOSION; await game.classicMode.startBattle();
const playerAbility = Abilities.DAMP;
game.override.ability(playerAbility); game.move.select(Moves.EXPLOSION);
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(); await game.phaseInterceptor.to("TurnEndPhase");
game.doAttack(getMovePosition(game.scene, 0, moveToUse));
await game.phaseInterceptor.to(TurnEndPhase);
expect(game.phaseInterceptor.log).toContain("ShowAbilityPhase"); expect(game.phaseInterceptor.log).toContain("ShowAbilityPhase");
expect(game.phaseInterceptor.log).not.toContain("FaintPhase"); expect(game.phaseInterceptor.log).not.toContain("FaintPhase");
@ -72,45 +62,30 @@ describe("Abilities - Damp", () => {
// Invalid if aftermath.test.ts has a failure. // Invalid if aftermath.test.ts has a failure.
it("silently prevents Aftermath from triggering", async() => { it("silently prevents Aftermath from triggering", async() => {
const moveToUse = Moves.TACKLE; game.override.enemyAbility(Abilities.AFTERMATH);
const playerAbility = Abilities.DAMP;
const enemyAbility = Abilities.AFTERMATH;
game.override.ability(playerAbility); await game.classicMode.startBattle();
game.override.moveset(Array(4).fill(moveToUse));
game.override.enemyAbility(enemyAbility);
game.override.enemyMoveset(SPLASH_ONLY);
game.override.enemySpecies(Species.BIDOOF);
await game.startBattle();
game.scene.getEnemyParty()[0].hp = 1; game.scene.getEnemyParty()[0].hp = 1;
game.doAttack(getMovePosition(game.scene, 0, moveToUse)); game.move.select(Moves.TACKLE);
await game.phaseInterceptor.to(TurnEndPhase); await game.phaseInterceptor.to("TurnEndPhase");
expect(game.phaseInterceptor.log).toContain("FaintPhase"); expect(game.phaseInterceptor.log).toContain("FaintPhase");
expect(game.phaseInterceptor.log).not.toContain("ShowAbilityPhase"); expect(game.phaseInterceptor.log).not.toContain("ShowAbilityPhase");
expect(game.scene.getParty()[0].getHpRatio()).toBe(1); expect(game.scene.getParty()[0].isFullHp()).toBe(true);
}, TIMEOUT); }, TIMEOUT);
// Ensures fix of #1476. // Ensures fix of #1476.
it("does not show ability popup during AI calculations", async() => { it("does not show ability popup during AI calculations", async() => {
const moveToUse = Moves.SPLASH;
const playerAbility = Abilities.DAMP;
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]); game.override.enemyMoveset([Moves.EXPLOSION, Moves.SELF_DESTRUCT, Moves.MIND_BLOWN, Moves.MISTY_EXPLOSION]);
await game.startBattle(); await game.classicMode.startBattle();
game.doAttack(getMovePosition(game.scene, 0, moveToUse)); game.move.select(Moves.SPLASH);
await game.phaseInterceptor.to(TurnEndPhase); await game.phaseInterceptor.to("TurnEndPhase");
expect(game.phaseInterceptor.log).not.toContain("ShowAbilityPhase"); expect(game.phaseInterceptor.log).not.toContain("ShowAbilityPhase");
}, TIMEOUT); }, TIMEOUT);