Skip to content

Commit

Permalink
Add Unit Tests for Both Moves
Browse files Browse the repository at this point in the history
  • Loading branch information
xsn34kzx committed Jul 9, 2024
1 parent fe4a84b commit cb26999
Show file tree
Hide file tree
Showing 3 changed files with 426 additions and 0 deletions.
62 changes: 62 additions & 0 deletions src/test/moves/fusion_bolt.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
import Phaser from "phaser";
import GameManager from "#app/test/utils/gameManager";
import * as overrides from "#app/overrides";
import { Species } from "#app/data/enums/species";
import { CommandPhase, EnemyCommandPhase, TurnEndPhase } from "#app/phases";
import { Mode } from "#app/ui/ui";
import { Moves } from "#app/data/enums/moves";
import { getMovePosition } from "#app/test/utils/gameManagerUtils";
import { Command } from "#app/ui/command-ui-handler";
import { Abilities } from "#app/data/enums/abilities";

describe("Moves - Fusion Bolt", () => {
let phaserGame: Phaser.Game;
let game: GameManager;

beforeAll(() => {
phaserGame = new Phaser.Game({
type: Phaser.HEADLESS,
});
});

afterEach(() => {
game.phaseInterceptor.restoreOg();
});

beforeEach(() => {
game = new GameManager(phaserGame);
const movesToUse = Moves.FUSION_BOLT;
vi.spyOn(overrides, "MOVESET_OVERRIDE", "get").mockReturnValue([movesToUse]);
vi.spyOn(overrides, "STARTING_LEVEL_OVERRIDE", "get").mockReturnValue(1);

vi.spyOn(overrides, "OPP_SPECIES_OVERRIDE", "get").mockReturnValue(Species.RESHIRAM);
vi.spyOn(overrides, "OPP_ABILITY_OVERRIDE", "get").mockReturnValue(Abilities.ROUGH_SKIN);
vi.spyOn(overrides, "OPP_MOVESET_OVERRIDE", "get").mockReturnValue([Moves.SPLASH, Moves.SPLASH, Moves.SPLASH, Moves.SPLASH]);

vi.spyOn(overrides, "SINGLE_BATTLE_OVERRIDE", "get").mockReturnValue(true);
vi.spyOn(overrides, "STARTING_WAVE_OVERRIDE", "get").mockReturnValue(97);
vi.spyOn(overrides, "NEVER_CRIT_OVERRIDE", "get").mockReturnValue(true);
});

it("FUSION_BOLT does not make contact", async() => {
const moveToUse = Moves.FUSION_BOLT;
await game.startBattle([
Species.ZEKROM,
]);
const hpUser = game.scene.getParty()[0].hp;

game.onNextPrompt("CommandPhase", Mode.COMMAND, () => {
game.scene.ui.setMode(Mode.FIGHT, (game.scene.getCurrentPhase() as CommandPhase).getFieldIndex());
});
game.onNextPrompt("CommandPhase", Mode.FIGHT, () => {
const movePosition = getMovePosition(game.scene, 0, moveToUse);
(game.scene.getCurrentPhase() as CommandPhase).handleCommand(Command.FIGHT, movePosition, false);
});

await game.phaseInterceptor.runFrom(EnemyCommandPhase).to(TurnEndPhase);

const hpLost = hpUser - game.scene.getParty()[0].hp;
expect(hpLost).toBe(0);
}, 20000);
});
66 changes: 66 additions & 0 deletions src/test/moves/fusion_flare.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
import Phaser from "phaser";
import GameManager from "#app/test/utils/gameManager";
import * as overrides from "#app/overrides";
import { Species } from "#app/data/enums/species";
import { CommandPhase, TurnEndPhase, EnemyCommandPhase, TurnStartPhase } from "#app/phases";
import { Mode } from "#app/ui/ui";
import { Moves } from "#app/data/enums/moves";
import { getMovePosition } from "#app/test/utils/gameManagerUtils";
import { Command } from "#app/ui/command-ui-handler";
import { StatusEffect } from "#app/data/status-effect";

describe("Moves - Fusion Flare", () => {
let phaserGame: Phaser.Game;
let game: GameManager;

beforeAll(() => {
phaserGame = new Phaser.Game({
type: Phaser.HEADLESS,
});
});

afterEach(() => {
game.phaseInterceptor.restoreOg();
});

beforeEach(() => {
game = new GameManager(phaserGame);
const movesToUse = Moves.FUSION_FLARE;
vi.spyOn(overrides, "MOVESET_OVERRIDE", "get").mockReturnValue([movesToUse]);
vi.spyOn(overrides, "STARTING_LEVEL_OVERRIDE", "get").mockReturnValue(1);

vi.spyOn(overrides, "OPP_SPECIES_OVERRIDE", "get").mockReturnValue(Species.RESHIRAM);
vi.spyOn(overrides, "OPP_MOVESET_OVERRIDE", "get").mockReturnValue([Moves.REST, Moves.REST, Moves.REST, Moves.REST]);

vi.spyOn(overrides, "SINGLE_BATTLE_OVERRIDE", "get").mockReturnValue(true);
vi.spyOn(overrides, "STARTING_WAVE_OVERRIDE", "get").mockReturnValue(97);
vi.spyOn(overrides, "NEVER_CRIT_OVERRIDE", "get").mockReturnValue(true);
});

it("FUSION_FLARE thaws freeze", async() => {
const moveToUse = Moves.FUSION_FLARE;
await game.startBattle([
Species.RESHIRAM,
]);

game.onNextPrompt("CommandPhase", Mode.COMMAND, () => {
game.scene.ui.setMode(Mode.FIGHT, (game.scene.getCurrentPhase() as CommandPhase).getFieldIndex());
});
game.onNextPrompt("CommandPhase", Mode.FIGHT, () => {
const movePosition = getMovePosition(game.scene, 0, moveToUse);
(game.scene.getCurrentPhase() as CommandPhase).handleCommand(Command.FIGHT, movePosition, false);
});

await game.phaseInterceptor.runFrom(EnemyCommandPhase).to(TurnStartPhase, false);

// Inflict freeze quietly and check if it was properly inflicted
game.scene.getParty()[0].trySetStatus(StatusEffect.FREEZE, false);
expect(game.scene.getParty()[0].status.effect).toBe(StatusEffect.FREEZE);

await game.phaseInterceptor.runFrom(TurnStartPhase).to(TurnEndPhase);

// Check if FUSION_FLARE thawed freeze
expect(game.scene.getParty()[0].status).toBeUndefined();
});
});
Loading

0 comments on commit cb26999

Please sign in to comment.