From 9b9962ba7329811d07b510e3f0995ce5130de6b7 Mon Sep 17 00:00:00 2001 From: Sirz Benjie <142067137+SirzBenjie@users.noreply.github.com> Date: Tue, 18 Feb 2025 22:58:13 -0600 Subject: [PATCH] Fix cherry pick migration --- test/battlerTags/substitute.test.ts | 2 +- test/plugins/api/pokerogue-daily-api.test.ts | 2 +- .../pokerogue-session-savedata-api.test.ts | 2 +- test/utils/gameManager.ts | 6 ++- test/utils/helpers/fieldHelper.ts | 39 +++++++++++++++++++ 5 files changed, 46 insertions(+), 5 deletions(-) create mode 100644 test/utils/helpers/fieldHelper.ts diff --git a/test/battlerTags/substitute.test.ts b/test/battlerTags/substitute.test.ts index bfdd3e5df37..22c0df9b6af 100644 --- a/test/battlerTags/substitute.test.ts +++ b/test/battlerTags/substitute.test.ts @@ -9,7 +9,7 @@ import { PokemonAnimType } from "#app/enums/pokemon-anim-type"; import * as messages from "#app/messages"; import { allMoves } from "#app/data/move"; import type { MoveEffectPhase } from "#app/phases/move-effect-phase"; -import { GameManager } from "#test/testUtils/gameManager"; +import GameManager from "#test/utils/gameManager"; describe("BattlerTag - SubstituteTag", () => { let phaserGame: Phaser.Game; diff --git a/test/plugins/api/pokerogue-daily-api.test.ts b/test/plugins/api/pokerogue-daily-api.test.ts index 47823e3e7b2..9662bf598c1 100644 --- a/test/plugins/api/pokerogue-daily-api.test.ts +++ b/test/plugins/api/pokerogue-daily-api.test.ts @@ -4,7 +4,7 @@ import { getApiBaseUrl } from "#test/utils/testUtils"; import { ScoreboardCategory, type RankingEntry } from "#app/ui/daily-run-scoreboard"; import { http, HttpResponse } from "msw"; import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest"; -import { initServerForApiTests } from "#test/testUtils/testFileInitialization"; +import { initServerForApiTests } from "#test/utils/testFileInitialization"; const apiBase = getApiBaseUrl(); const dailyApi = new PokerogueDailyApi(apiBase); diff --git a/test/plugins/api/pokerogue-session-savedata-api.test.ts b/test/plugins/api/pokerogue-session-savedata-api.test.ts index 09731b7347a..a85f0ea2c97 100644 --- a/test/plugins/api/pokerogue-session-savedata-api.test.ts +++ b/test/plugins/api/pokerogue-session-savedata-api.test.ts @@ -11,7 +11,7 @@ import type { SessionSaveData } from "#app/system/game-data"; import { getApiBaseUrl } from "#test/utils/testUtils"; import { http, HttpResponse } from "msw"; import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest"; -import { initServerForApiTests } from "#test/testUtils/testFileInitialization"; +import { initServerForApiTests } from "#test/utils/testFileInitialization"; const apiBase = getApiBaseUrl(); const sessionSavedataApi = new PokerogueSessionSavedataApi(apiBase); diff --git a/test/utils/gameManager.ts b/test/utils/gameManager.ts index fe769f0a866..2d6365b5c89 100644 --- a/test/utils/gameManager.ts +++ b/test/utils/gameManager.ts @@ -41,13 +41,14 @@ import type { MysteryEncounterType } from "#enums/mystery-encounter-type"; import { PlayerGender } from "#enums/player-gender"; import type { Species } from "#enums/species"; import { generateStarter, waitUntil } from "#test/utils/gameManagerUtils"; -import GameWrapper from "#test/utils/gameWrapper"; +import { GameWrapper } from "#test/utils/gameWrapper"; import { ChallengeModeHelper } from "#test/utils/helpers/challengeModeHelper"; import { ClassicModeHelper } from "#test/utils/helpers/classicModeHelper"; import { DailyModeHelper } from "#test/utils/helpers/dailyModeHelper"; import { ModifierHelper } from "#test/utils/helpers/modifiersHelper"; import { MoveHelper } from "#test/utils/helpers/moveHelper"; import { OverridesHelper } from "#test/utils/helpers/overridesHelper"; +import { FieldHelper } from "#test/utils/helpers/fieldHelper"; import { ReloadHelper } from "#test/utils/helpers/reloadHelper"; import { SettingsHelper } from "#test/utils/helpers/settingsHelper"; import PhaseInterceptor from "#test/utils/phaseInterceptor"; @@ -57,7 +58,7 @@ import fs from "fs"; import { expect, vi } from "vitest"; import { globalScene } from "#app/global-scene"; import type StarterSelectUiHandler from "#app/ui/starter-select-ui-handler"; -import { MockFetch } from "#test/testUtils/mocks/mockFetch"; +import { MockFetch } from "#test/utils/mocks/mockFetch"; /** * Class to manage the game state and transitions between phases. @@ -76,6 +77,7 @@ export default class GameManager { public readonly settings: SettingsHelper; public readonly reload: ReloadHelper; public readonly modifiers: ModifierHelper; + public readonly field: FieldHelper; /** * Creates an instance of GameManager. diff --git a/test/utils/helpers/fieldHelper.ts b/test/utils/helpers/fieldHelper.ts new file mode 100644 index 00000000000..83149530271 --- /dev/null +++ b/test/utils/helpers/fieldHelper.ts @@ -0,0 +1,39 @@ +import type { EnemyPokemon, PlayerPokemon } from "#app/field/pokemon"; +import { GameManagerHelper } from "#test/utils/helpers/gameManagerHelper"; +import { expect } from "vitest"; +// tsdoc imports +// eslint-disable-next-line @typescript-eslint/no-unused-vars +import { type globalScene } from "#app/global-scene"; + +/** Helper to manage pokemon */ +export class FieldHelper extends GameManagerHelper { + /** + * Passthrough for {@linkcode globalScene.getPlayerPokemon} that adds an `undefined` check for + * the Pokemon so that the return type for the function doesn't have `undefined`. + * This removes the need to add a `!` like when calling `game.scene.getPlayerPokemon()!`. + * @param includeSwitching Whether a pokemon that is currently switching out is valid, default `true` + * @returns The first {@linkcode PlayerPokemon} that is {@linkcode globalScene.getPlayerField on the field} + * and {@linkcode PlayerPokemon.isActive is active} + * (aka {@linkcode PlayerPokemon.isAllowedInBattle is allowed in battle}). + */ + public getPlayerPokemon(includeSwitching: boolean = true): PlayerPokemon { + const pokemon = this.game.scene.getPlayerPokemon(includeSwitching); + expect(pokemon).toBeDefined(); + return pokemon!; + } + + /** + * Passthrough for {@linkcode globalScene.getEnemyPokemon} that adds an `undefined` check for + * the Pokemon so that the return type for the function doesn't have `undefined`. + * This removes the need to add a `!` like when calling `game.scene.getEnemyPokemon()!`. + * @param includeSwitching Whether a pokemon that is currently switching out is valid, default `true` + * @returns The first {@linkcode EnemyPokemon} that is {@linkcode globalScene.getEnemyField on the field} + * and {@linkcode EnemyPokemon.isActive is active} + * (aka {@linkcode EnemyPokemon.isAllowedInBattle is allowed in battle}). + */ + public getEnemyPokemon(includeSwitching: boolean = true): EnemyPokemon { + const pokemon = this.game.scene.getEnemyPokemon(includeSwitching); + expect(pokemon).toBeDefined(); + return pokemon!; + } +}