Skip to content

Commit

Permalink
implement new test code
Browse files Browse the repository at this point in the history
  • Loading branch information
ysh4296 committed Sep 4, 2024
1 parent b226cae commit 29e9e79
Showing 1 changed file with 36 additions and 89 deletions.
125 changes: 36 additions & 89 deletions src/test/moves/power_trick.test.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@

import { afterEach, beforeAll, beforeEach, describe, expect, it } from "vitest";
import Phaser from "phaser";
import GameManager from "#app/test/utils/gameManager";
import * as overrides from "#app/overrides";
import { getMovePosition } from "#app/test/utils/gameManagerUtils";
import { Moves } from "#enums/moves";
import { Stat } from "#enums/stat";
import { Species } from "#enums/species";
import { Stat } from "#app/data/pokemon-stat";
import { BattlerTagType } from "#enums/battler-tag-type";
import { afterEach, beforeAll, beforeEach, describe, expect, test, vi } from "vitest";
import { TurnEndPhase } from "#app/phases";
import { TurnEndPhase } from "#app/phases/turn-end-phase";
import { Abilities } from "#enums/abilities";
import { SPLASH_ONLY } from "../utils/testUtils";

describe("Moves - Power Trick", () => {
let phaserGame: Phaser.Game;
Expand All @@ -25,102 +25,49 @@ describe("Moves - Power Trick", () => {

beforeEach(() => {
game = new GameManager(phaserGame);
vi.spyOn(overrides, "STARTER_SPECIES_OVERRIDE", "get").mockReturnValue(Species.SHUCKLE);
vi.spyOn(overrides, "OPP_SPECIES_OVERRIDE", "get").mockReturnValue(Species.SHUCKLE);
vi.spyOn(overrides, "STARTING_LEVEL_OVERRIDE", "get").mockReturnValue(5);
vi.spyOn(overrides, "OPP_LEVEL_OVERRIDE", "get").mockReturnValue(6);
vi.spyOn(overrides, "MOVESET_OVERRIDE", "get").mockReturnValue([Moves.SWIFT, Moves.POWER_TRICK]);
vi.spyOn(overrides, "OPP_MOVESET_OVERRIDE", "get").mockReturnValue([Moves.NONE, Moves.NONE, Moves.NONE, Moves.NONE]);
game.override
.battleType("single")
.enemyAbility(Abilities.NONE)
.enemyMoveset(SPLASH_ONLY)
.enemySpecies(Species.MEW)
.ability(Abilities.NONE);
});

test(
"switches raw Attack stat with its raw Defense stat",
async () => {
await game.startBattle([Species.SHUCKLE]);

const playerPokemon = game.scene.getPlayerField()[0];
const initialStats = [...playerPokemon.stats];
it("swaps users ATK with its DEF stat", async () => {
await game.classicMode.startBattle([Species.SHUCKLE]);

game.doAttack(getMovePosition(game.scene, 0, Moves.POWER_TRICK));
await game.phaseInterceptor.to(TurnEndPhase);

expect(playerPokemon.getTag(BattlerTagType.POWER_TRICK)).not.toBe(undefined);
expect(playerPokemon.stats[Stat.ATK]).toBe(initialStats[Stat.DEF]);
expect(playerPokemon.stats[Stat.DEF]).toBe(initialStats[Stat.ATK]);
},
20000
);
const player = game.scene.getPlayerPokemon()!;
const baseATK = player.getStat(Stat.ATK, false);
const baseDEF = player.getStat(Stat.DEF, false);

test(
"using power trick again will reset stat change",
async () => {
await game.startBattle([Species.SHUCKLE]);
game.move.select(Moves.POWER_TRICK);

const playerPokemon = game.scene.getPlayerField()[0];
const initialStats = [...playerPokemon.stats];
await game.phaseInterceptor.to(TurnEndPhase);

game.doAttack(getMovePosition(game.scene, 0, Moves.POWER_TRICK));
await game.toNextTurn();

game.doAttack(getMovePosition(game.scene, 0, Moves.POWER_TRICK));
await game.phaseInterceptor.to(TurnEndPhase);

expect(playerPokemon.getTag(BattlerTagType.POWER_TRICK)).toBe(undefined);
expect(playerPokemon.stats[Stat.ATK]).toBe(initialStats[Stat.ATK]);
expect(playerPokemon.stats[Stat.DEF]).toBe(initialStats[Stat.DEF]);
},
20000
expect(player.getStat(Stat.ATK, false)).toBe(baseDEF);
expect(player.getStat(Stat.DEF, false)).toBe(baseATK);
},
20000
);

test(
"effect disappears with summoning event",
async () => {
await game.startBattle([Species.SHUCKLE]);

const playerPokemon = game.scene.getPlayerField()[0];
const initialStats = [...playerPokemon.stats];

game.doAttack(getMovePosition(game.scene, 0, Moves.POWER_TRICK));
await game.toNextTurn();

game.doSwitchPokemon(0);
await game.phaseInterceptor.to(TurnEndPhase);

expect(playerPokemon.getTag(BattlerTagType.POWER_TRICK)).toBe(undefined);
expect(playerPokemon.stats[Stat.ATK]).toBe(initialStats[Stat.ATK]);
expect(playerPokemon.stats[Stat.DEF]).toBe(initialStats[Stat.DEF]);
},
20000
);

test(
"effect remains after levelup event",
async () => {
await game.startBattle([Species.SHUCKLE]);

const playerPokemon = game.scene.getPlayerField()[0];
const enemyPokemon = game.scene.getEnemyField()[0];
const initialLevel = playerPokemon.level;
it("using power trick again will reset stat change", async () => {
await game.classicMode.startBattle([Species.SHUCKLE]);

enemyPokemon.hp = 1;
const player = game.scene.getPlayerPokemon()!;
const baseATK = player.getStat(Stat.ATK, false);
const baseDEF = player.getStat(Stat.DEF, false);

game.doAttack(getMovePosition(game.scene, 0, Moves.POWER_TRICK));
await game.toNextTurn();
game.move.select(Moves.POWER_TRICK);

game.doAttack(getMovePosition(game.scene, 0, Moves.SWIFT));
await game.phaseInterceptor.to(TurnEndPhase);
await game.phaseInterceptor.to(TurnEndPhase);

const expectedStats = [...playerPokemon.stats];
game.move.select(Moves.POWER_TRICK);

// recalculate stats for getting base Stats to compare
playerPokemon.resetSummonData();
playerPokemon.calculateStats();
await game.phaseInterceptor.to(TurnEndPhase);

expect(playerPokemon.level).toBeGreaterThan(initialLevel);
expect(playerPokemon.getTag(BattlerTagType.POWER_TRICK)).toBe(undefined);
expect(playerPokemon.stats[Stat.ATK]).toBe(expectedStats[Stat.DEF]);
expect(playerPokemon.stats[Stat.DEF]).toBe(expectedStats[Stat.ATK]);
},
20000
expect(player.getStat(Stat.ATK, false)).toBe(baseATK);
expect(player.getStat(Stat.DEF, false)).toBe(baseDEF);
},
20000
);
});

0 comments on commit 29e9e79

Please sign in to comment.