From 6a793641ea26ae169b1a84fa699a6fb038311253 Mon Sep 17 00:00:00 2001 From: cadi Date: Fri, 28 Jun 2024 19:36:19 +0900 Subject: [PATCH] add tests for summoning & levelup event --- src/test/moves/power_trick.test.ts | 98 ++++++++++++++++++++---------- 1 file changed, 67 insertions(+), 31 deletions(-) diff --git a/src/test/moves/power_trick.test.ts b/src/test/moves/power_trick.test.ts index 0f3849a3c8b..b7ed1b408fb 100644 --- a/src/test/moves/power_trick.test.ts +++ b/src/test/moves/power_trick.test.ts @@ -1,4 +1,3 @@ -import { beforeAll, afterEach, beforeEach, describe, vi, it, expect } from "vitest"; import Phaser from "phaser"; import GameManager from "#app/test/utils/gameManager"; import * as overrides from "#app/overrides"; @@ -7,8 +6,8 @@ import { Moves } from "#enums/moves"; import { Species } from "#enums/species"; import { Stat } from "#app/data/pokemon-stat"; import { BattlerTagType } from "#enums/battler-tag-type"; - -const TIMEOUT = 20 * 1000; +import { afterEach, beforeAll, beforeEach, describe, expect, test, vi } from "vitest"; +import { TurnEndPhase } from "#app/phases"; describe("Moves - Power Trick", () => { let phaserGame: Phaser.Game; @@ -26,29 +25,15 @@ 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, "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.POWER_TRICK, - Moves.POWER_TRICK, - Moves.POWER_TRICK, - Moves.POWER_TRICK, - ]); - vi.spyOn(overrides, "OPP_MOVESET_OVERRIDE", "get").mockReturnValue([ - Moves.NONE, - Moves.NONE, - Moves.NONE, - Moves.NONE, - ]); + 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]); }); - it( + test( "switches raw Attack stat with its raw Defense stat", async () => { await game.startBattle([Species.SHUCKLE]); @@ -57,16 +42,16 @@ describe("Moves - Power Trick", () => { const initialStats = [...playerPokemon.stats]; game.doAttack(getMovePosition(game.scene, 0, Moves.POWER_TRICK)); - await game.toNextTurn(); + await game.phaseInterceptor.to(TurnEndPhase); expect(playerPokemon.getTag(BattlerTagType.POWER_TRICK)).not.toBe(undefined); - expect(playerPokemon.getStat(Stat.ATK)).toBe(initialStats[Stat.DEF]); - expect(playerPokemon.getStat(Stat.DEF)).toBe(initialStats[Stat.ATK]); + expect(playerPokemon.stats[Stat.ATK]).toBe(initialStats[Stat.DEF]); + expect(playerPokemon.stats[Stat.DEF]).toBe(initialStats[Stat.ATK]); }, - TIMEOUT + 20000 ); - it( + test( "using power trick again will reset stat change", async () => { await game.startBattle([Species.SHUCKLE]); @@ -78,12 +63,63 @@ describe("Moves - Power Trick", () => { await game.toNextTurn(); game.doAttack(getMovePosition(game.scene, 0, Moves.POWER_TRICK)); - await game.toNextTurn(); + await game.phaseInterceptor.to(TurnEndPhase); expect(playerPokemon.getTag(BattlerTagType.POWER_TRICK)).toBe(undefined); - expect(playerPokemon.getStat(Stat.ATK)).toBe(initialStats[Stat.ATK]); - expect(playerPokemon.getStat(Stat.DEF)).toBe(initialStats[Stat.DEF]); + expect(playerPokemon.stats[Stat.ATK]).toBe(initialStats[Stat.ATK]); + expect(playerPokemon.stats[Stat.DEF]).toBe(initialStats[Stat.DEF]); }, - TIMEOUT + 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; + + 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.calculateStats(); + + expect(playerPokemon.level).toBeGreaterThan(initialLevel); + expect(playerPokemon.getTag(BattlerTagType.POWER_TRICK)).not.toBe(undefined); + expect(playerPokemon.stats[Stat.ATK]).toBe(expectedStats[Stat.DEF]); + expect(playerPokemon.stats[Stat.DEF]).toBe(expectedStats[Stat.ATK]); + }, + 20000 ); });