Update tests

This commit is contained in:
NightKev 2024-09-08 18:27:19 -07:00
parent b11c17d1f6
commit 9ec78c47a7
1 changed files with 40 additions and 189 deletions

View File

@ -1,16 +1,10 @@
import {afterEach, beforeAll, beforeEach, describe, expect, it, vi} from "vitest"; import { StatusEffect } from "#app/data/status-effect";
import Phaser from "phaser";
import GameManager from "#app/test/utils/gameManager"; import GameManager from "#app/test/utils/gameManager";
import * as overrides from "#app/overrides";
import {
MoveEffectPhase,
TurnEndPhase,
} from "#app/phases";
import {getMovePosition} from "#app/test/utils/gameManagerUtils";
import { Abilities } from "#enums/abilities"; import { Abilities } from "#enums/abilities";
import { Moves } from "#enums/moves"; import { Moves } from "#enums/moves";
import { Species } from "#enums/species"; import { Species } from "#enums/species";
import { StatusEffect } from "#app/data/status-effect.js"; import Phaser from "phaser";
import { afterEach, beforeAll, beforeEach, describe, expect, it } from "vitest";
describe("Abilities - Synchronize", () => { describe("Abilities - Synchronize", () => {
let phaserGame: Phaser.Game; let phaserGame: Phaser.Game;
@ -28,230 +22,87 @@ describe("Abilities - Synchronize", () => {
beforeEach(() => { beforeEach(() => {
game = new GameManager(phaserGame); game = new GameManager(phaserGame);
vi.spyOn(overrides, "SINGLE_BATTLE_OVERRIDE", "get").mockReturnValue(true);
vi.spyOn(overrides, "STARTING_LEVEL_OVERRIDE", "get").mockReturnValue(100); game.override
vi.spyOn(overrides, "STATUS_OVERRIDE", "get").mockReturnValue(StatusEffect.NONE); .battleType("single")
vi.spyOn(overrides, "OPP_STATUS_OVERRIDE", "get").mockReturnValue(StatusEffect.NONE); .startingLevel(100)
// Opponent mocks .enemySpecies(Species.MAGIKARP)
vi.spyOn(overrides, "OPP_SPECIES_OVERRIDE", "get").mockReturnValue(Species.ALAKAZAM); .enemyAbility(Abilities.SYNCHRONIZE)
vi.spyOn(overrides, "OPP_MOVESET_OVERRIDE", "get").mockReturnValue([Moves.PSYCHIC, Moves.CALM_MIND, Moves.FOCUS_BLAST, Moves.RECOVER]); .moveset([Moves.SPLASH, Moves.THUNDER_WAVE, Moves.SPORE, Moves.PSYCHO_SHIFT])
vi.spyOn(overrides, "OPP_ABILITY_OVERRIDE", "get").mockReturnValue(Abilities.SYNCHRONIZE); .ability(Abilities.NO_GUARD);
}, 20000); }, 20000);
it("does not trigger when no status is applied by opponent Pokemon", async () => { it("does not trigger when no status is applied by opponent Pokemon", async () => {
// Arrange await game.classicMode.startBattle([Species.FEEBAS]);
const moveToUse = Moves.HEADBUTT;
// Starter mocks game.move.select(Moves.SPLASH);
vi.spyOn(overrides, "STARTER_SPECIES_OVERRIDE", "get").mockReturnValue(Species.ZIGZAGOON); await game.phaseInterceptor.to("BerryPhase");
vi.spyOn(overrides, "MOVESET_OVERRIDE", "get").mockReturnValue([moveToUse]);
vi.spyOn(overrides, "ABILITY_OVERRIDE", "get").mockReturnValue(Abilities.PICKUP);
// Act expect(game.scene.getParty()[0].status).toBeUndefined();
await game.startBattle();
game.doAttack(getMovePosition(game.scene, 0, moveToUse));
await game.phaseInterceptor.to(TurnEndPhase);
// Assert
expect(game.scene.getParty()[0].status).toBe(undefined);
expect(game.phaseInterceptor.log).not.toContain("ShowAbilityPhase"); expect(game.phaseInterceptor.log).not.toContain("ShowAbilityPhase");
}, 20000); }, 20000);
it("sets the status of the source pokemon to Paralysis when paralyzed by it", async () => { it("sets the status of the source pokemon to Paralysis when paralyzed by it", async () => {
// Arrange await game.classicMode.startBattle([Species.FEEBAS]);
const moveToUse = Moves.THUNDER_WAVE;
// Starter mocks game.move.select(Moves.THUNDER_WAVE);
vi.spyOn(overrides, "STARTER_SPECIES_OVERRIDE", "get").mockReturnValue(Species.TOGEKISS); await game.phaseInterceptor.to("BerryPhase");
vi.spyOn(overrides, "MOVESET_OVERRIDE", "get").mockReturnValue([moveToUse]);
vi.spyOn(overrides, "ABILITY_OVERRIDE", "get").mockReturnValue(Abilities.SERENE_GRACE);
// Act
await game.startBattle();
game.doAttack(getMovePosition(game.scene, 0, moveToUse));
await game.phaseInterceptor.to(MoveEffectPhase, false);
vi.spyOn(game.scene.getCurrentPhase() as MoveEffectPhase, "hitCheck").mockReturnValue(true);
await game.phaseInterceptor.to(TurnEndPhase);
// Assert
expect(game.scene.getParty()[0].status?.effect).toBe(StatusEffect.PARALYSIS); expect(game.scene.getParty()[0].status?.effect).toBe(StatusEffect.PARALYSIS);
expect(game.scene.getEnemyParty()[0].status?.effect).toBe(StatusEffect.PARALYSIS); expect(game.scene.getEnemyParty()[0].status?.effect).toBe(StatusEffect.PARALYSIS);
expect(game.phaseInterceptor.log).toContain("ShowAbilityPhase"); expect(game.phaseInterceptor.log).toContain("ShowAbilityPhase");
}, 20000); }, 20000);
it("sets the status of the source pokemon to Burned when burn is applied by it", async () => { it("does not trigger on Sleep", async () => {
// Arrange await game.classicMode.startBattle();
const moveToUse = Moves.WILL_O_WISP;
// Starter mocks game.move.select(Moves.SPORE);
vi.spyOn(overrides, "STARTER_SPECIES_OVERRIDE", "get").mockReturnValue(Species.EEVEE);
vi.spyOn(overrides, "MOVESET_OVERRIDE", "get").mockReturnValue([moveToUse]);
vi.spyOn(overrides, "ABILITY_OVERRIDE", "get").mockReturnValue(Abilities.GUTS);
// Act await game.phaseInterceptor.to("BerryPhase");
await game.startBattle();
game.doAttack(getMovePosition(game.scene, 0, moveToUse));
await game.phaseInterceptor.to(MoveEffectPhase, false); expect(game.scene.getParty()[0].status?.effect).toBeUndefined();
vi.spyOn(game.scene.getCurrentPhase() as MoveEffectPhase, "hitCheck").mockReturnValue(true);
await game.phaseInterceptor.to(TurnEndPhase);
// Assert
expect(game.scene.getParty()[0].status?.effect).toBe(StatusEffect.BURN);
expect(game.scene.getEnemyParty()[0].status?.effect).toBe(StatusEffect.BURN);
expect(game.phaseInterceptor.log).toContain("ShowAbilityPhase");
}, 20000);
it("sets the status of the source pokemon to Poisoned when poison is applied by it", async () => {
// Arrange
const moveToUse = Moves.POISON_POWDER;
// Starter mocks
vi.spyOn(overrides, "STARTER_SPECIES_OVERRIDE", "get").mockReturnValue(Species.BRELOOM);
vi.spyOn(overrides, "MOVESET_OVERRIDE", "get").mockReturnValue([moveToUse]);
vi.spyOn(overrides, "ABILITY_OVERRIDE", "get").mockReturnValue(Abilities.TECHNICIAN);
// Act
await game.startBattle();
game.doAttack(getMovePosition(game.scene, 0, moveToUse));
await game.phaseInterceptor.to(MoveEffectPhase, false);
vi.spyOn(game.scene.getCurrentPhase() as MoveEffectPhase, "hitCheck").mockReturnValue(true);
await game.phaseInterceptor.to(TurnEndPhase);
// Assert
expect(game.scene.getParty()[0].status?.effect).toBe(StatusEffect.POISON);
expect(game.scene.getEnemyParty()[0].status?.effect).toBe(StatusEffect.POISON);
expect(game.phaseInterceptor.log).toContain("ShowAbilityPhase");
}, 20000);
it("sets the status of the source pokemon to Toxic when toxic is applied by it", async () => {
// Arrange
const moveToUse = Moves.TOXIC;
// Starter mocks
vi.spyOn(overrides, "STARTER_SPECIES_OVERRIDE", "get").mockReturnValue(Species.QUAGSIRE);
vi.spyOn(overrides, "MOVESET_OVERRIDE", "get").mockReturnValue([moveToUse]);
vi.spyOn(overrides, "ABILITY_OVERRIDE", "get").mockReturnValue(Abilities.DAMP);
// Act
await game.startBattle();
game.doAttack(getMovePosition(game.scene, 0, moveToUse));
await game.phaseInterceptor.to(MoveEffectPhase, false);
vi.spyOn(game.scene.getCurrentPhase() as MoveEffectPhase, "hitCheck").mockReturnValue(true);
await game.phaseInterceptor.to(TurnEndPhase);
// Assert
expect(game.scene.getParty()[0].status?.effect).toBe(StatusEffect.TOXIC);
expect(game.scene.getEnemyParty()[0].status?.effect).toBe(StatusEffect.TOXIC);
expect(game.phaseInterceptor.log).toContain("ShowAbilityPhase");
}, 20000);
it("does not trigger when Pokemon is statused to non Burn, Paralysis, Poison, or Toxic", async () => {
// Arrange
const moveToUse = Moves.SPORE;
// Starter mocks
vi.spyOn(overrides, "STARTER_SPECIES_OVERRIDE", "get").mockReturnValue(Species.BRELOOM);
vi.spyOn(overrides, "MOVESET_OVERRIDE", "get").mockReturnValue([moveToUse]);
vi.spyOn(overrides, "ABILITY_OVERRIDE", "get").mockReturnValue(Abilities.POISON_HEAL);
// Act
await game.startBattle();
game.doAttack(getMovePosition(game.scene, 0, moveToUse));
await game.phaseInterceptor.to(MoveEffectPhase, false);
vi.spyOn(game.scene.getCurrentPhase() as MoveEffectPhase, "hitCheck").mockReturnValue(true);
await game.phaseInterceptor.to(TurnEndPhase);
// Assert
expect(game.scene.getParty()[0].status?.effect).toBe(undefined);
expect(game.scene.getEnemyParty()[0].status?.effect).toBe(StatusEffect.SLEEP); expect(game.scene.getEnemyParty()[0].status?.effect).toBe(StatusEffect.SLEEP);
expect(game.phaseInterceptor.log).not.toContain("ShowAbilityPhase"); expect(game.phaseInterceptor.log).not.toContain("ShowAbilityPhase");
}, 20000); }, 20000);
it("does not trigger when Pokemon is statused by Toxic Spikes", async () => { it("does not trigger when Pokemon is statused by Toxic Spikes", async () => {
// Arrange game.override
const moveToUse = Moves.SPLASH; .ability(Abilities.SYNCHRONIZE)
.enemyAbility(Abilities.BALL_FETCH)
.enemyMoveset(Array(4).fill(Moves.TOXIC_SPIKES));
// Starter mocks await game.classicMode.startBattle([Species.FEEBAS, Species.MILOTIC]);
vi.spyOn(overrides, "MOVESET_OVERRIDE", "get").mockReturnValue([moveToUse]);
vi.spyOn(overrides, "ABILITY_OVERRIDE", "get").mockReturnValue(Abilities.SYNCHRONIZE);
vi.spyOn(overrides, "OPP_SPECIES_OVERRIDE", "get").mockReturnValue(Species.BRELOOM);
vi.spyOn(overrides, "OPP_MOVESET_OVERRIDE", "get").mockReturnValue([Moves.TOXIC_SPIKES]);
vi.spyOn(overrides, "OPP_ABILITY_OVERRIDE", "get").mockReturnValue(Abilities.TECHNICIAN);
// Act
// Turn 1 - Opponent uses spikes, trainer uses splash
// Turn 2 - Opponent uses splash, trainer sends out Alakazam. Alakazam is toxic-ed but Synchronize should not proc
await game.startBattle([Species.MAGIKARP, Species.ALAKAZAM]);
const leadPokemon = game.scene.getPlayerPokemon();
expect(leadPokemon).not.toBe(undefined);
game.doAttack(getMovePosition(game.scene, 0, Moves.SPLASH)); // use splash
game.move.select(Moves.SPLASH);
await game.toNextTurn(); await game.toNextTurn();
game.doSwitchPokemon(1);
game.doAttack(0);
await game.phaseInterceptor.to(TurnEndPhase); game.doSwitchPokemon(1);
await game.phaseInterceptor.to("BerryPhase");
// Assert // Assert
expect(game.scene.getParty()[0].status?.effect).toBe(StatusEffect.POISON); expect(game.scene.getParty()[0].status?.effect).toBe(StatusEffect.POISON);
expect(game.scene.getEnemyParty()[0].status?.effect).toBe(undefined); expect(game.scene.getEnemyParty()[0].status?.effect).toBeUndefined();
expect(game.phaseInterceptor.log).not.toContain("ShowAbilityPhase"); expect(game.phaseInterceptor.log).not.toContain("ShowAbilityPhase");
}, 20000); }, 20000);
it("shows ability even if it fails to set the status of the opponent Pokemon", async () => { it("shows ability even if it fails to set the status of the opponent Pokemon", async () => {
// Arrange await game.classicMode.startBattle([Species.PIKACHU]);
const moveToUse = Moves.THUNDER_WAVE;
// Starter mocks game.move.select(Moves.THUNDER_WAVE);
vi.spyOn(overrides, "STARTER_SPECIES_OVERRIDE", "get").mockReturnValue(Species.PIKACHU); await game.phaseInterceptor.to("BerryPhase");
vi.spyOn(overrides, "MOVESET_OVERRIDE", "get").mockReturnValue([moveToUse]);
vi.spyOn(overrides, "ABILITY_OVERRIDE", "get").mockReturnValue(Abilities.STATIC);
// Act
await game.startBattle();
game.doAttack(getMovePosition(game.scene, 0, moveToUse));
await game.phaseInterceptor.to(MoveEffectPhase, false);
vi.spyOn(game.scene.getCurrentPhase() as MoveEffectPhase, "hitCheck").mockReturnValue(true);
await game.phaseInterceptor.to(TurnEndPhase);
// Assert // Assert
expect(game.scene.getParty()[0].status?.effect).toBe(undefined); expect(game.scene.getParty()[0].status?.effect).toBeUndefined();
expect(game.scene.getEnemyParty()[0].status?.effect).toBe(StatusEffect.PARALYSIS); expect(game.scene.getEnemyParty()[0].status?.effect).toBe(StatusEffect.PARALYSIS);
expect(game.phaseInterceptor.log).toContain("ShowAbilityPhase"); expect(game.phaseInterceptor.log).toContain("ShowAbilityPhase");
}, 20000); }, 20000);
it("should activate with Psycho Shift after the move clears the status", async () => { it("should activate with Psycho Shift after the move clears the status", async () => {
// Arrange game.override.statusEffect(StatusEffect.PARALYSIS);
const moveToUse = Moves.PSYCHO_SHIFT; await game.classicMode.startBattle();
// Starter mocks game.move.select(Moves.PSYCHO_SHIFT);
vi.spyOn(overrides, "STARTER_SPECIES_OVERRIDE", "get").mockReturnValue(Species.HOOTHOOT); await game.phaseInterceptor.to("BerryPhase");
vi.spyOn(overrides, "MOVESET_OVERRIDE", "get").mockReturnValue([moveToUse]);
vi.spyOn(overrides, "ABILITY_OVERRIDE", "get").mockReturnValue(Abilities.KEEN_EYE);
vi.spyOn(overrides, "STATUS_OVERRIDE", "get").mockReturnValue(StatusEffect.PARALYSIS);
// Act
await game.startBattle();
game.doAttack(getMovePosition(game.scene, 0, moveToUse));
await game.phaseInterceptor.to(MoveEffectPhase, false);
vi.spyOn(game.scene.getCurrentPhase() as MoveEffectPhase, "hitCheck").mockReturnValue(true);
await game.phaseInterceptor.to(TurnEndPhase);
// Assert // Assert
expect(game.scene.getParty()[0].status?.effect).toBe(StatusEffect.PARALYSIS); // keeping old gen < V impl for now since it's buggy otherwise expect(game.scene.getParty()[0].status?.effect).toBe(StatusEffect.PARALYSIS); // keeping old gen < V impl for now since it's buggy otherwise