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 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;
@ -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]);
it("swaps users ATK with its DEF stat", async () => {
await game.classicMode.startBattle([Species.SHUCKLE]);
const playerPokemon = game.scene.getPlayerField()[0];
const initialStats = [...playerPokemon.stats];
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.phaseInterceptor.to(TurnEndPhase);
game.move.select(Moves.POWER_TRICK);
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
await game.phaseInterceptor.to(TurnEndPhase);
expect(player.getStat(Stat.ATK, false)).toBe(baseDEF);
expect(player.getStat(Stat.DEF, false)).toBe(baseATK);
},
20000
);
test(
"using power trick again will reset stat change",
async () => {
await game.startBattle([Species.SHUCKLE]);
it("using power trick again will reset stat change", async () => {
await game.classicMode.startBattle([Species.SHUCKLE]);
const playerPokemon = game.scene.getPlayerField()[0];
const initialStats = [...playerPokemon.stats];
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.POWER_TRICK));
await game.phaseInterceptor.to(TurnEndPhase);
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
);
game.move.select(Moves.POWER_TRICK);
test(
"effect disappears with summoning event",
async () => {
await game.startBattle([Species.SHUCKLE]);
await game.phaseInterceptor.to(TurnEndPhase);
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;
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
expect(player.getStat(Stat.ATK, false)).toBe(baseATK);
expect(player.getStat(Stat.DEF, false)).toBe(baseDEF);
},
20000
);
});