From 29e9e7906cd41e5270312eaea433c85cc87b2bc7 Mon Sep 17 00:00:00 2001 From: cadi Date: Wed, 4 Sep 2024 18:07:59 +0900 Subject: [PATCH] implement new test code --- src/test/moves/power_trick.test.ts | 125 +++++++++-------------------- 1 file changed, 36 insertions(+), 89 deletions(-) diff --git a/src/test/moves/power_trick.test.ts b/src/test/moves/power_trick.test.ts index a7b17e808c38..aff9154b087b 100644 --- a/src/test/moves/power_trick.test.ts +++ b/src/test/moves/power_trick.test.ts @@ -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]); - - 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 ); });