Fixed a couple tests

Currently chipping away at the backlog of "jank and/or stupid tests"
This commit is contained in:
Bertie690 2025-08-24 21:52:16 -04:00
parent 4be227418f
commit 461afb0fde
6 changed files with 44 additions and 75 deletions

View File

@ -34,8 +34,9 @@ describe("Ability Timing", () => {
vi.spyOn(i18next, "t"); vi.spyOn(i18next, "t");
}); });
// TODO: change this to use the `startBattleWithSwitch` util from hotfix branch
it("should trigger after switch check", async () => { it("should trigger after switch check", async () => {
game.settings.battleStyle = BattleStyle.SWITCH; game.settings.battleStyle(BattleStyle.SWITCH);
await game.classicMode.runToSummon([SpeciesId.EEVEE, SpeciesId.FEEBAS]); await game.classicMode.runToSummon([SpeciesId.EEVEE, SpeciesId.FEEBAS]);
game.onNextPrompt( game.onNextPrompt(

View File

@ -1,9 +1,8 @@
import { AbilityId } from "#enums/ability-id"; import { AbilityId } from "#enums/ability-id";
import { ArenaTagSide } from "#enums/arena-tag-side";
import { ArenaTagType } from "#enums/arena-tag-type"; import { ArenaTagType } from "#enums/arena-tag-type";
import { MoveId } from "#enums/move-id";
import { SpeciesId } from "#enums/species-id"; import { SpeciesId } from "#enums/species-id";
import { PostSummonPhase } from "#phases/post-summon-phase"; import { WeatherType } from "#enums/weather-type";
import { TurnEndPhase } from "#phases/turn-end-phase";
import { GameManager } from "#test/test-utils/game-manager"; import { GameManager } from "#test/test-utils/game-manager";
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";
@ -24,57 +23,26 @@ describe("Abilities - Screen Cleaner", () => {
beforeEach(() => { beforeEach(() => {
game = new GameManager(phaserGame); game = new GameManager(phaserGame);
game.override.battleStyle("single").ability(AbilityId.SCREEN_CLEANER).enemySpecies(SpeciesId.SHUCKLE); game.override
.battleStyle("single")
.ability(AbilityId.SCREEN_CLEANER)
.enemySpecies(SpeciesId.SHUCKLE)
.weather(WeatherType.HAIL);
}); });
it("removes Aurora Veil", async () => { // TODO: Screen cleaner doesn't remove both sides' tags if both players have them
game.override.enemyMoveset(MoveId.AURORA_VEIL); it.todo.each([
{ name: "Reflect", tagType: ArenaTagType.REFLECT },
{ name: "Light Screen", tagType: ArenaTagType.LIGHT_SCREEN },
{ name: "Aurora Veil", tagType: ArenaTagType.AURORA_VEIL },
])("should remove $name from both sides of the field on entrance", async ({ tagType }) => {
game.scene.arena.addTag(tagType, 0, 0, 0, ArenaTagSide.PLAYER);
game.scene.arena.addTag(tagType, 0, 0, 0, ArenaTagSide.ENEMY);
expect(game).toHaveArenaTag(tagType);
await game.classicMode.startBattle([SpeciesId.SLOWKING]);
await game.classicMode.startBattle([SpeciesId.MAGIKARP, SpeciesId.MAGIKARP]); const slowking = game.field.getPlayerPokemon();
expect(slowking).toHaveAbilityApplied(AbilityId.SCREEN_CLEANER);
game.move.use(MoveId.HAIL); expect(game).not.toHaveArenaTag(tagType);
await game.phaseInterceptor.to(TurnEndPhase);
expect(game.scene.arena.getTag(ArenaTagType.AURORA_VEIL)).toBeDefined();
await game.toNextTurn();
game.doSwitchPokemon(1);
await game.phaseInterceptor.to(PostSummonPhase);
expect(game.scene.arena.getTag(ArenaTagType.AURORA_VEIL)).toBeUndefined();
});
it("removes Light Screen", async () => {
game.override.enemyMoveset(MoveId.LIGHT_SCREEN);
await game.classicMode.startBattle([SpeciesId.MAGIKARP, SpeciesId.MAGIKARP]);
game.move.use(MoveId.SPLASH);
await game.phaseInterceptor.to(TurnEndPhase);
expect(game.scene.arena.getTag(ArenaTagType.LIGHT_SCREEN)).toBeDefined();
await game.toNextTurn();
game.doSwitchPokemon(1);
await game.phaseInterceptor.to(PostSummonPhase);
expect(game.scene.arena.getTag(ArenaTagType.LIGHT_SCREEN)).toBeUndefined();
});
it("removes Reflect", async () => {
game.override.enemyMoveset(MoveId.REFLECT);
await game.classicMode.startBattle([SpeciesId.MAGIKARP, SpeciesId.MAGIKARP]);
game.move.use(MoveId.SPLASH);
await game.phaseInterceptor.to(TurnEndPhase);
expect(game.scene.arena.getTag(ArenaTagType.REFLECT)).toBeDefined();
await game.toNextTurn();
game.doSwitchPokemon(1);
await game.phaseInterceptor.to(PostSummonPhase);
expect(game.scene.arena.getTag(ArenaTagType.REFLECT)).toBeUndefined();
}); });
}); });

View File

@ -74,14 +74,6 @@ describe("Moves - Baton Pass", () => {
// check buffs are still there // check buffs are still there
expect(game.field.getEnemyPokemon().getStatStage(Stat.SPATK)).toEqual(2); expect(game.field.getEnemyPokemon().getStatStage(Stat.SPATK)).toEqual(2);
// confirm that a switch actually happened. can't use species because I
// can't find a way to override trainer parties with more than 1 pokemon species
expect(game.phaseInterceptor.log.slice(-4)).toEqual([
"MoveEffectPhase",
"SwitchSummonPhase",
"SummonPhase",
"PostSummonPhase",
]);
}); });
it("doesn't transfer effects that aren't transferrable", async () => { it("doesn't transfer effects that aren't transferrable", async () => {

View File

@ -8,7 +8,6 @@ import * as EncounterPhaseUtils from "#mystery-encounters/encounter-phase-utils"
import { LostAtSeaEncounter } from "#mystery-encounters/lost-at-sea-encounter"; import { LostAtSeaEncounter } from "#mystery-encounters/lost-at-sea-encounter";
import * as MysteryEncounters from "#mystery-encounters/mystery-encounters"; import * as MysteryEncounters from "#mystery-encounters/mystery-encounters";
import { MysteryEncounterPhase } from "#phases/mystery-encounter-phases"; import { MysteryEncounterPhase } from "#phases/mystery-encounter-phases";
import { PartyExpPhase } from "#phases/party-exp-phase";
import { import {
runMysteryEncounterToEnd, runMysteryEncounterToEnd,
runSelectMysteryEncounterOption, runSelectMysteryEncounterOption,
@ -119,7 +118,7 @@ describe("Lost at Sea - Mystery Encounter", () => {
const expBefore = blastoise!.exp; const expBefore = blastoise!.exp;
await runMysteryEncounterToEnd(game, 1); await runMysteryEncounterToEnd(game, 1);
await game.phaseInterceptor.to(PartyExpPhase); await game.phaseInterceptor.to("ShowPartyExpBarPhase");
expect(blastoise?.exp).toBe(expBefore + Math.floor((laprasSpecies.baseExp * defaultWave) / 5 + 1)); expect(blastoise?.exp).toBe(expBefore + Math.floor((laprasSpecies.baseExp * defaultWave) / 5 + 1));
}); });
@ -184,7 +183,7 @@ describe("Lost at Sea - Mystery Encounter", () => {
const expBefore = pidgeot!.exp; const expBefore = pidgeot!.exp;
await runMysteryEncounterToEnd(game, 2); await runMysteryEncounterToEnd(game, 2);
await game.phaseInterceptor.to(PartyExpPhase); await game.phaseInterceptor.to("ShowPartyExpBarPhase");
expect(pidgeot!.exp).toBe(expBefore + Math.floor((laprasBaseExp * defaultWave) / 5 + 1)); expect(pidgeot!.exp).toBe(expBefore + Math.floor((laprasBaseExp * defaultWave) / 5 + 1));
}); });

View File

@ -4,6 +4,8 @@ import { ExpNotification } from "#enums/exp-notification";
import { PlayerGender } from "#enums/player-gender"; import { PlayerGender } from "#enums/player-gender";
import type { GameManager } from "#test/test-utils/game-manager"; import type { GameManager } from "#test/test-utils/game-manager";
import { GameManagerHelper } from "#test/test-utils/helpers/game-manager-helper"; import { GameManagerHelper } from "#test/test-utils/helpers/game-manager-helper";
import chalk from "chalk";
import { getEnumStr } from "../string-utils";
/** /**
* Helper to handle settings for tests * Helper to handle settings for tests
@ -31,40 +33,45 @@ export class SettingsHelper extends GameManagerHelper {
/** /**
* Change the battle style to Switch or Set mode (tests default to {@linkcode BattleStyle.SET}) * Change the battle style to Switch or Set mode (tests default to {@linkcode BattleStyle.SET})
* @param mode - The {@linkcode BattleStyle} to set * @param style - The {@linkcode BattleStyle} to set
*/ */
battleStyle(mode: BattleStyle) { battleStyle(style: BattleStyle): this {
this.game.scene.battleStyle = mode; this.game.scene.battleStyle = style;
this.log(`Battle Style set to BattleStyle.${getEnumStr(BattleStyle, style)}!`);
return this;
} }
/** /**
* Disable/Enable type hints settings * Disable/Enable type hints settings
* @param enable true to enabled, false to disabled * @param enable - Whether to enable or disable type hints.
* @returns `this`
*/ */
typeHints(enable: boolean): void { typeHints(enable: boolean): this {
this.game.scene.typeHints = enable; this.game.scene.typeHints = enable;
this.log(`Type Hints ${enable ? "enabled" : "disabled"}`); this.log(`Type Hints ${enable ? "enabled" : "disabled"}!`);
return this;
} }
/** /**
* Change the player gender * Change the player gender
* @param gender the {@linkcode PlayerGender} to set * @param gender - The {@linkcode PlayerGender} to set
*/ */
playerGender(gender: PlayerGender) { playerGender(gender: PlayerGender) {
this.game.scene.gameData.gender = gender; this.game.scene.gameData.gender = gender;
this.log(`Gender set to: ${PlayerGender[gender]} (=${gender})`); this.log(`Gender set to PlayerGender.${getEnumStr(PlayerGender, gender)}!`);
} }
/** /**
* Change the exp gains speed * Change the exp gains speed
* @param speed the {@linkcode ExpGainsSpeed} to set * @param speed - the {@linkcode ExpGainsSpeed} to set
*/ */
expGainsSpeed(speed: ExpGainsSpeed) { expGainsSpeed(speed: ExpGainsSpeed) {
this.game.scene.expGainsSpeed = speed; this.game.scene.expGainsSpeed = speed;
this.log(`Exp Gains Speed set to: ${ExpGainsSpeed[speed]} (=${speed})`); this.log(`Exp Gains Speed set to ExpGainsSpeed.${getEnumStr(ExpGainsSpeed, speed)}!`);
return this;
} }
private log(...params: any[]) { private log(...params: any[]) {
console.log("Settings:", ...params); console.log(chalk.hex("#FFAFFA")(params));
} }
} }

View File

@ -76,6 +76,8 @@ describe("Test Utils - PromptHandler", () => {
}); });
it("should call PhaseInterceptor.checkMode if current phase in `endBySetMode`", async () => { it("should call PhaseInterceptor.checkMode if current phase in `endBySetMode`", async () => {
promptHandler["game"]["scene"]["phaseManager"]["getCurrentPhase"] = () =>
({ phaseName: "CommandPhase" }) as Phase;
promptHandler["game"].scene.ui["setModeInternal"](UiMode.PARTY, false, false, false, []); promptHandler["game"].scene.ui["setModeInternal"](UiMode.PARTY, false, false, false, []);
expect(checkModeCallback).toHaveBeenCalledOnce(); expect(checkModeCallback).toHaveBeenCalledOnce();