Fix tests

This commit is contained in:
NightKev 2024-09-05 22:22:49 -07:00
parent d9738372c1
commit d4e4938760
2 changed files with 44 additions and 55 deletions

View File

@ -1,5 +1,4 @@
import { Species } from "#app/enums/species"; import { Species } from "#app/enums/species";
import { TurnEndPhase } from "#app/phases/turn-end-phase";
import { Abilities } from "#enums/abilities"; import { Abilities } from "#enums/abilities";
import { Moves } from "#enums/moves"; import { Moves } from "#enums/moves";
import GameManager from "#test/utils/gameManager"; import GameManager from "#test/utils/gameManager";
@ -23,63 +22,56 @@ describe("Abilities - Dry Skin", () => {
beforeEach(() => { beforeEach(() => {
game = new GameManager(phaserGame); game = new GameManager(phaserGame);
game.override.battleType("single"); game.override
game.override.disableCrits(); .battleType("single")
game.override.enemyAbility(Abilities.DRY_SKIN); .disableCrits()
game.override.enemyMoveset(SPLASH_ONLY); .enemyAbility(Abilities.DRY_SKIN)
game.override.enemySpecies(Species.CHARMANDER); .enemyMoveset(SPLASH_ONLY)
game.override.ability(Abilities.UNNERVE); .enemySpecies(Species.CHARMANDER)
game.override.starterSpecies(Species.CHANDELURE); .ability(Abilities.BALL_FETCH)
.moveset([Moves.SUNNY_DAY, Moves.RAIN_DANCE, Moves.SPLASH, Moves.WATER_GUN])
.starterSpecies(Species.CHANDELURE);
}); });
it("during sunlight, lose 1/8 of maximum health at the end of each turn", async () => { it("during sunlight, lose 1/8 of maximum health at the end of each turn", async () => {
game.override.moveset([Moves.SUNNY_DAY, Moves.SPLASH]); await game.classicMode.startBattle();
await game.startBattle();
const enemy = game.scene.getEnemyPokemon()!; const enemy = game.scene.getEnemyPokemon()!;
expect(enemy).not.toBe(undefined);
// first turn // first turn
let previousEnemyHp = enemy.hp;
game.move.select(Moves.SUNNY_DAY); game.move.select(Moves.SUNNY_DAY);
await game.phaseInterceptor.to(TurnEndPhase); await game.phaseInterceptor.to("TurnEndPhase");
expect(enemy.hp).toBeLessThan(previousEnemyHp); expect(enemy.hp).toBeLessThan(enemy.getMaxHp());
// second turn // second turn
previousEnemyHp = enemy.hp; enemy.hp = enemy.getMaxHp();
game.move.select(Moves.SPLASH); game.move.select(Moves.SPLASH);
await game.phaseInterceptor.to(TurnEndPhase); await game.phaseInterceptor.to("TurnEndPhase");
expect(enemy.hp).toBeLessThan(previousEnemyHp); expect(enemy.hp).toBeLessThan(enemy.getMaxHp());
}); });
it("during rain, gain 1/8 of maximum health at the end of each turn", async () => { it("during rain, gain 1/8 of maximum health at the end of each turn", async () => {
game.override.moveset([Moves.RAIN_DANCE, Moves.SPLASH]); await game.classicMode.startBattle();
await game.startBattle();
const enemy = game.scene.getEnemyPokemon()!; const enemy = game.scene.getEnemyPokemon()!;
expect(enemy).not.toBe(undefined);
enemy.hp = 1; enemy.hp = 1;
// first turn // first turn
let previousEnemyHp = enemy.hp;
game.move.select(Moves.RAIN_DANCE); game.move.select(Moves.RAIN_DANCE);
await game.phaseInterceptor.to(TurnEndPhase); await game.phaseInterceptor.to("TurnEndPhase");
expect(enemy.hp).toBeGreaterThan(previousEnemyHp); expect(enemy.hp).toBeGreaterThan(1);
// second turn // second turn
previousEnemyHp = enemy.hp; enemy.hp = 1;
game.move.select(Moves.SPLASH); game.move.select(Moves.SPLASH);
await game.phaseInterceptor.to(TurnEndPhase); await game.phaseInterceptor.to("TurnEndPhase");
expect(enemy.hp).toBeGreaterThan(previousEnemyHp); expect(enemy.hp).toBeGreaterThan(1);
}); });
it("opposing fire attacks do 25% more damage", async () => { it("opposing fire attacks do 25% more damage", async () => {
game.override.moveset([Moves.FLAMETHROWER]); game.override.moveset([Moves.FLAMETHROWER]);
await game.classicMode.startBattle();
await game.startBattle();
const enemy = game.scene.getEnemyPokemon()!; const enemy = game.scene.getEnemyPokemon()!;
const initialHP = 1000; const initialHP = 1000;
@ -87,72 +79,65 @@ describe("Abilities - Dry Skin", () => {
// first turn // first turn
game.move.select(Moves.FLAMETHROWER); game.move.select(Moves.FLAMETHROWER);
await game.phaseInterceptor.to(TurnEndPhase); await game.phaseInterceptor.to("TurnEndPhase");
const fireDamageTakenWithDrySkin = initialHP - enemy.hp; const fireDamageTakenWithDrySkin = initialHP - enemy.hp;
expect(enemy.hp > 0);
enemy.hp = initialHP; enemy.hp = initialHP;
game.override.enemyAbility(Abilities.NONE); game.override.enemyAbility(Abilities.NONE);
// second turn // second turn
game.move.select(Moves.FLAMETHROWER); game.move.select(Moves.FLAMETHROWER);
await game.phaseInterceptor.to(TurnEndPhase); await game.phaseInterceptor.to("TurnEndPhase");
const fireDamageTakenWithoutDrySkin = initialHP - enemy.hp; const fireDamageTakenWithoutDrySkin = initialHP - enemy.hp;
expect(fireDamageTakenWithDrySkin).toBeGreaterThan(fireDamageTakenWithoutDrySkin); expect(fireDamageTakenWithDrySkin).toBeGreaterThan(fireDamageTakenWithoutDrySkin);
}); });
it("opposing water attacks heal 1/4 of maximum health and deal no damage", async () => { it("opposing water attacks heal 1/4 of maximum health and deal no damage", async () => {
game.override.moveset([Moves.WATER_GUN]); await game.classicMode.startBattle();
await game.startBattle();
const enemy = game.scene.getEnemyPokemon()!; const enemy = game.scene.getEnemyPokemon()!;
expect(enemy).not.toBe(undefined);
enemy.hp = 1; enemy.hp = 1;
game.move.select(Moves.WATER_GUN); game.move.select(Moves.WATER_GUN);
await game.phaseInterceptor.to(TurnEndPhase); await game.phaseInterceptor.to("TurnEndPhase");
expect(enemy.hp).toBeGreaterThan(1); expect(enemy.hp).toBeGreaterThan(1);
}); });
it("opposing water attacks do not heal if they were protected from", async () => { it("opposing water attacks do not heal if they were protected from", async () => {
game.override.moveset([Moves.WATER_GUN]); game.override.enemyMoveset([Moves.PROTECT]);
await game.startBattle(); await game.classicMode.startBattle();
const enemy = game.scene.getEnemyPokemon()!; const enemy = game.scene.getEnemyPokemon()!;
expect(enemy).not.toBe(undefined);
enemy.hp = 1; enemy.hp = 1;
game.override.enemyMoveset([Moves.PROTECT, Moves.PROTECT, Moves.PROTECT, Moves.PROTECT]);
game.move.select(Moves.WATER_GUN); game.move.select(Moves.WATER_GUN);
await game.phaseInterceptor.to(TurnEndPhase); await game.phaseInterceptor.to("TurnEndPhase");
expect(enemy.hp).toBe(1); expect(enemy.hp).toBe(1);
}); });
it("multi-strike water attacks only heal once", async () => { it("multi-strike water attacks only heal once", async () => {
game.override.moveset([Moves.WATER_GUN, Moves.WATER_SHURIKEN]); game.override.moveset([Moves.WATER_GUN, Moves.WATER_SHURIKEN]);
await game.startBattle(); await game.classicMode.startBattle();
const enemy = game.scene.getEnemyPokemon()!; const enemy = game.scene.getEnemyPokemon()!;
expect(enemy).not.toBe(undefined);
enemy.hp = 1; enemy.hp = 1;
// first turn // first turn
game.move.select(Moves.WATER_SHURIKEN); game.move.select(Moves.WATER_SHURIKEN);
await game.phaseInterceptor.to(TurnEndPhase); await game.phaseInterceptor.to("TurnEndPhase");
const healthGainedFromWaterShuriken = enemy.hp - 1; const healthGainedFromWaterShuriken = enemy.hp - 1;
enemy.hp = 1; enemy.hp = 1;
// second turn // second turn
game.move.select(Moves.WATER_GUN); game.move.select(Moves.WATER_GUN);
await game.phaseInterceptor.to(TurnEndPhase); await game.phaseInterceptor.to("TurnEndPhase");
const healthGainedFromWaterGun = enemy.hp - 1; const healthGainedFromWaterGun = enemy.hp - 1;
expect(healthGainedFromWaterShuriken).toBe(healthGainedFromWaterGun); expect(healthGainedFromWaterShuriken).toBe(healthGainedFromWaterGun);

View File

@ -38,7 +38,7 @@ describe("Moves - Safeguard", () => {
}); });
it("protects from damaging moves with additional effects", async () => { it("protects from damaging moves with additional effects", async () => {
await game.startBattle(); await game.classicMode.startBattle();
const enemy = game.scene.getEnemyPokemon()!; const enemy = game.scene.getEnemyPokemon()!;
game.move.select(Moves.NUZZLE); game.move.select(Moves.NUZZLE);
@ -49,7 +49,7 @@ describe("Moves - Safeguard", () => {
}, TIMEOUT); }, TIMEOUT);
it("protects from status moves", async () => { it("protects from status moves", async () => {
await game.startBattle(); await game.classicMode.startBattle();
const enemyPokemon = game.scene.getEnemyPokemon()!; const enemyPokemon = game.scene.getEnemyPokemon()!;
game.move.select(Moves.SPORE); game.move.select(Moves.SPORE);
@ -61,7 +61,7 @@ describe("Moves - Safeguard", () => {
it("protects from confusion", async () => { it("protects from confusion", async () => {
game.override.moveset([Moves.CONFUSE_RAY]); game.override.moveset([Moves.CONFUSE_RAY]);
await game.startBattle(); await game.classicMode.startBattle();
const enemyPokemon = game.scene.getEnemyPokemon()!; const enemyPokemon = game.scene.getEnemyPokemon()!;
game.move.select(Moves.CONFUSE_RAY); game.move.select(Moves.CONFUSE_RAY);
@ -74,7 +74,7 @@ describe("Moves - Safeguard", () => {
it("protects ally from status", async () => { it("protects ally from status", async () => {
game.override.battleType("double"); game.override.battleType("double");
await game.startBattle(); await game.classicMode.startBattle();
game.move.select(Moves.SPORE, 0, BattlerIndex.ENEMY_2); game.move.select(Moves.SPORE, 0, BattlerIndex.ENEMY_2);
game.move.select(Moves.NUZZLE, 1, BattlerIndex.ENEMY_2); game.move.select(Moves.NUZZLE, 1, BattlerIndex.ENEMY_2);
@ -90,7 +90,7 @@ describe("Moves - Safeguard", () => {
}, TIMEOUT); }, TIMEOUT);
it("protects from Yawn", async () => { it("protects from Yawn", async () => {
await game.startBattle(); await game.classicMode.startBattle();
const enemyPokemon = game.scene.getEnemyPokemon()!; const enemyPokemon = game.scene.getEnemyPokemon()!;
game.move.select(Moves.YAWN); game.move.select(Moves.YAWN);
@ -101,7 +101,7 @@ describe("Moves - Safeguard", () => {
}, TIMEOUT); }, TIMEOUT);
it("doesn't protect from already existing Yawn", async () => { it("doesn't protect from already existing Yawn", async () => {
await game.startBattle(); await game.classicMode.startBattle();
const enemyPokemon = game.scene.getEnemyPokemon()!; const enemyPokemon = game.scene.getEnemyPokemon()!;
game.move.select(Moves.YAWN); game.move.select(Moves.YAWN);
@ -116,7 +116,7 @@ describe("Moves - Safeguard", () => {
it("doesn't protect from self-inflicted via Rest or Flame Orb", async () => { it("doesn't protect from self-inflicted via Rest or Flame Orb", async () => {
game.override.enemyHeldItems([{name: "FLAME_ORB"}]); game.override.enemyHeldItems([{name: "FLAME_ORB"}]);
await game.startBattle(); await game.classicMode.startBattle();
const enemyPokemon = game.scene.getEnemyPokemon()!; const enemyPokemon = game.scene.getEnemyPokemon()!;
game.move.select(Moves.SPLASH); game.move.select(Moves.SPLASH);
@ -126,7 +126,11 @@ describe("Moves - Safeguard", () => {
expect(enemyPokemon.status?.effect).toEqual(StatusEffect.BURN); expect(enemyPokemon.status?.effect).toEqual(StatusEffect.BURN);
game.override.enemyMoveset([Moves.REST]); game.override.enemyMoveset([Moves.REST]);
// Force the moveset to update mid-battle
// TODO: Remove after enemy AI rework is in
enemyPokemon.getMoveset();
game.move.select(Moves.SPLASH); game.move.select(Moves.SPLASH);
enemyPokemon.damageAndUpdate(1);
await game.toNextTurn(); await game.toNextTurn();
expect(enemyPokemon.status?.effect).toEqual(StatusEffect.SLEEP); expect(enemyPokemon.status?.effect).toEqual(StatusEffect.SLEEP);
@ -135,7 +139,7 @@ describe("Moves - Safeguard", () => {
it("protects from ability-inflicted status", async () => { it("protects from ability-inflicted status", async () => {
game.override.ability(Abilities.STATIC); game.override.ability(Abilities.STATIC);
vi.spyOn(allAbilities[Abilities.STATIC].getAttrs(PostDefendContactApplyStatusEffectAbAttr)[0], "chance", "get").mockReturnValue(100); vi.spyOn(allAbilities[Abilities.STATIC].getAttrs(PostDefendContactApplyStatusEffectAbAttr)[0], "chance", "get").mockReturnValue(100);
await game.startBattle(); await game.classicMode.startBattle();
const enemyPokemon = game.scene.getEnemyPokemon()!; const enemyPokemon = game.scene.getEnemyPokemon()!;
game.move.select(Moves.SPLASH); game.move.select(Moves.SPLASH);