implement new test code

This commit is contained in:
cadi 2024-09-04 18:07:59 +09:00
parent b226cae754
commit 29e9e7906c

View File

@ -1,13 +1,13 @@
import { afterEach, beforeAll, beforeEach, describe, expect, it } from "vitest";
import Phaser from "phaser"; 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 { getMovePosition } from "#app/test/utils/gameManagerUtils";
import { Moves } from "#enums/moves"; import { Moves } from "#enums/moves";
import { Stat } from "#enums/stat";
import { Species } from "#enums/species"; import { Species } from "#enums/species";
import { Stat } from "#app/data/pokemon-stat"; import { TurnEndPhase } from "#app/phases/turn-end-phase";
import { BattlerTagType } from "#enums/battler-tag-type"; import { Abilities } from "#enums/abilities";
import { afterEach, beforeAll, beforeEach, describe, expect, test, vi } from "vitest"; import { SPLASH_ONLY } from "../utils/testUtils";
import { TurnEndPhase } from "#app/phases";
describe("Moves - Power Trick", () => { describe("Moves - Power Trick", () => {
let phaserGame: Phaser.Game; let phaserGame: Phaser.Game;
@ -25,101 +25,48 @@ describe("Moves - Power Trick", () => {
beforeEach(() => { beforeEach(() => {
game = new GameManager(phaserGame); game = new GameManager(phaserGame);
vi.spyOn(overrides, "STARTER_SPECIES_OVERRIDE", "get").mockReturnValue(Species.SHUCKLE); game.override
vi.spyOn(overrides, "OPP_SPECIES_OVERRIDE", "get").mockReturnValue(Species.SHUCKLE); .battleType("single")
vi.spyOn(overrides, "STARTING_LEVEL_OVERRIDE", "get").mockReturnValue(5); .enemyAbility(Abilities.NONE)
vi.spyOn(overrides, "OPP_LEVEL_OVERRIDE", "get").mockReturnValue(6); .enemyMoveset(SPLASH_ONLY)
vi.spyOn(overrides, "MOVESET_OVERRIDE", "get").mockReturnValue([Moves.SWIFT, Moves.POWER_TRICK]); .enemySpecies(Species.MEW)
vi.spyOn(overrides, "OPP_MOVESET_OVERRIDE", "get").mockReturnValue([Moves.NONE, Moves.NONE, Moves.NONE, Moves.NONE]); .ability(Abilities.NONE);
}); });
test( it("swaps users ATK with its DEF stat", async () => {
"switches raw Attack stat with its raw Defense stat", await game.classicMode.startBattle([Species.SHUCKLE]);
async () => {
await game.startBattle([Species.SHUCKLE]);
const playerPokemon = game.scene.getPlayerField()[0]; const player = game.scene.getPlayerPokemon()!;
const initialStats = [...playerPokemon.stats]; const baseATK = player.getStat(Stat.ATK, false);
const baseDEF = player.getStat(Stat.DEF, false);
game.move.select(Moves.POWER_TRICK);
game.doAttack(getMovePosition(game.scene, 0, Moves.POWER_TRICK));
await game.phaseInterceptor.to(TurnEndPhase); await game.phaseInterceptor.to(TurnEndPhase);
expect(playerPokemon.getTag(BattlerTagType.POWER_TRICK)).not.toBe(undefined); expect(player.getStat(Stat.ATK, false)).toBe(baseDEF);
expect(playerPokemon.stats[Stat.ATK]).toBe(initialStats[Stat.DEF]); expect(player.getStat(Stat.DEF, false)).toBe(baseATK);
expect(playerPokemon.stats[Stat.DEF]).toBe(initialStats[Stat.ATK]);
}, },
20000 20000
); );
test( it("using power trick again will reset stat change", async () => {
"using power trick again will reset stat change", await game.classicMode.startBattle([Species.SHUCKLE]);
async () => {
await game.startBattle([Species.SHUCKLE]);
const playerPokemon = game.scene.getPlayerField()[0]; const player = game.scene.getPlayerPokemon()!;
const initialStats = [...playerPokemon.stats]; const baseATK = player.getStat(Stat.ATK, false);
const baseDEF = player.getStat(Stat.DEF, false);
game.doAttack(getMovePosition(game.scene, 0, Moves.POWER_TRICK)); game.move.select(Moves.POWER_TRICK);
await game.toNextTurn();
game.doAttack(getMovePosition(game.scene, 0, Moves.POWER_TRICK));
await game.phaseInterceptor.to(TurnEndPhase); await game.phaseInterceptor.to(TurnEndPhase);
expect(playerPokemon.getTag(BattlerTagType.POWER_TRICK)).toBe(undefined); game.move.select(Moves.POWER_TRICK);
expect(playerPokemon.stats[Stat.ATK]).toBe(initialStats[Stat.ATK]);
expect(playerPokemon.stats[Stat.DEF]).toBe(initialStats[Stat.DEF]);
},
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); await game.phaseInterceptor.to(TurnEndPhase);
expect(playerPokemon.getTag(BattlerTagType.POWER_TRICK)).toBe(undefined); expect(player.getStat(Stat.ATK, false)).toBe(baseATK);
expect(playerPokemon.stats[Stat.ATK]).toBe(initialStats[Stat.ATK]); expect(player.getStat(Stat.DEF, false)).toBe(baseDEF);
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;
enemyPokemon.hp = 1;
game.doAttack(getMovePosition(game.scene, 0, Moves.POWER_TRICK));
await game.toNextTurn();
game.doAttack(getMovePosition(game.scene, 0, Moves.SWIFT));
await game.phaseInterceptor.to(TurnEndPhase);
const expectedStats = [...playerPokemon.stats];
// recalculate stats for getting base Stats to compare
playerPokemon.resetSummonData();
playerPokemon.calculateStats();
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 20000
); );