From 9ff86857526c431d264973c7f3af8afe327af63f Mon Sep 17 00:00:00 2001 From: "Adrian T." <68144167+torranx@users.noreply.github.com> Date: Thu, 8 Aug 2024 11:15:45 +0800 Subject: [PATCH] [Dev] Update changeTurnOrder name to mockTurnOrder (naming convention) (#3422) * change changeTurnOrder to mockTurnOrder * update docs --- src/test/abilities/serene_grace.test.ts | 6 +++--- src/test/abilities/sheer_force.test.ts | 10 +++++----- src/test/abilities/shield_dust.test.ts | 4 ++-- src/test/abilities/zen_mode.test.ts | 8 ++++---- src/test/items/leek.test.ts | 4 ++-- src/test/items/scope_lens.test.ts | 4 ++-- src/test/moves/fusion_flare_bolt.test.ts | 16 ++++++++-------- src/test/moves/gastro_acid.test.ts | 4 ++-- src/test/utils/testUtils.ts | 11 ++++++----- 9 files changed, 34 insertions(+), 33 deletions(-) diff --git a/src/test/abilities/serene_grace.test.ts b/src/test/abilities/serene_grace.test.ts index c486604e4f9..59e9ff723da 100644 --- a/src/test/abilities/serene_grace.test.ts +++ b/src/test/abilities/serene_grace.test.ts @@ -11,7 +11,7 @@ import { Moves } from "#enums/moves"; import { Species } from "#enums/species"; import Phaser from "phaser"; import { afterEach, beforeAll, beforeEach, describe, expect, it } from "vitest"; -import { changeTurnOrder } from "../utils/testUtils"; +import { mockTurnOrder } from "../utils/testUtils"; import { BattlerIndex } from "#app/battle.js"; @@ -57,7 +57,7 @@ describe("Abilities - Serene Grace", () => { (game.scene.getCurrentPhase() as CommandPhase).handleCommand(Command.FIGHT, movePosition, false); }); - await changeTurnOrder(game, [BattlerIndex.PLAYER, BattlerIndex.ENEMY]); + await mockTurnOrder(game, [BattlerIndex.PLAYER, BattlerIndex.ENEMY]); await game.phaseInterceptor.to(MoveEffectPhase, false); // Check chance of Air Slash without Serene Grace @@ -90,7 +90,7 @@ describe("Abilities - Serene Grace", () => { (game.scene.getCurrentPhase() as CommandPhase).handleCommand(Command.FIGHT, movePosition, false); }); - await changeTurnOrder(game, [BattlerIndex.PLAYER, BattlerIndex.ENEMY]); + await mockTurnOrder(game, [BattlerIndex.PLAYER, BattlerIndex.ENEMY]); await game.phaseInterceptor.to(MoveEffectPhase, false); // Check chance of Air Slash with Serene Grace diff --git a/src/test/abilities/sheer_force.test.ts b/src/test/abilities/sheer_force.test.ts index 3f1bcadd43f..35353bc7000 100644 --- a/src/test/abilities/sheer_force.test.ts +++ b/src/test/abilities/sheer_force.test.ts @@ -11,7 +11,7 @@ import { Moves } from "#enums/moves"; import { Species } from "#enums/species"; import Phaser from "phaser"; import { afterEach, beforeAll, beforeEach, describe, expect, it } from "vitest"; -import { changeTurnOrder } from "../utils/testUtils"; +import { mockTurnOrder } from "../utils/testUtils"; import { BattlerIndex } from "#app/battle.js"; @@ -58,7 +58,7 @@ describe("Abilities - Sheer Force", () => { (game.scene.getCurrentPhase() as CommandPhase).handleCommand(Command.FIGHT, movePosition, false); }); - await changeTurnOrder(game, [BattlerIndex.PLAYER, BattlerIndex.ENEMY]); + await mockTurnOrder(game, [BattlerIndex.PLAYER, BattlerIndex.ENEMY]); await game.phaseInterceptor.to(MoveEffectPhase, false); const phase = game.scene.getCurrentPhase() as MoveEffectPhase; @@ -97,7 +97,7 @@ describe("Abilities - Sheer Force", () => { (game.scene.getCurrentPhase() as CommandPhase).handleCommand(Command.FIGHT, movePosition, false); }); - await changeTurnOrder(game, [BattlerIndex.PLAYER, BattlerIndex.ENEMY]); + await mockTurnOrder(game, [BattlerIndex.PLAYER, BattlerIndex.ENEMY]); await game.phaseInterceptor.to(MoveEffectPhase, false); const phase = game.scene.getCurrentPhase() as MoveEffectPhase; @@ -136,7 +136,7 @@ describe("Abilities - Sheer Force", () => { (game.scene.getCurrentPhase() as CommandPhase).handleCommand(Command.FIGHT, movePosition, false); }); - await changeTurnOrder(game, [BattlerIndex.PLAYER, BattlerIndex.ENEMY]); + await mockTurnOrder(game, [BattlerIndex.PLAYER, BattlerIndex.ENEMY]); await game.phaseInterceptor.to(MoveEffectPhase, false); const phase = game.scene.getCurrentPhase() as MoveEffectPhase; @@ -177,7 +177,7 @@ describe("Abilities - Sheer Force", () => { (game.scene.getCurrentPhase() as CommandPhase).handleCommand(Command.FIGHT, movePosition, false); }); - await changeTurnOrder(game, [BattlerIndex.PLAYER, BattlerIndex.ENEMY]); + await mockTurnOrder(game, [BattlerIndex.PLAYER, BattlerIndex.ENEMY]); await game.phaseInterceptor.to(MoveEffectPhase, false); const phase = game.scene.getCurrentPhase() as MoveEffectPhase; diff --git a/src/test/abilities/shield_dust.test.ts b/src/test/abilities/shield_dust.test.ts index c7e62b333d7..ded70eccb36 100644 --- a/src/test/abilities/shield_dust.test.ts +++ b/src/test/abilities/shield_dust.test.ts @@ -12,7 +12,7 @@ import { Species } from "#enums/species"; import Phaser from "phaser"; import { afterEach, beforeAll, beforeEach, describe, expect, it } from "vitest"; import { BattlerIndex } from "#app/battle.js"; -import { changeTurnOrder } from "../utils/testUtils"; +import { mockTurnOrder } from "../utils/testUtils"; describe("Abilities - Shield Dust", () => { @@ -58,7 +58,7 @@ describe("Abilities - Shield Dust", () => { (game.scene.getCurrentPhase() as CommandPhase).handleCommand(Command.FIGHT, movePosition, false); }); - await changeTurnOrder(game, [BattlerIndex.PLAYER, BattlerIndex.ENEMY]); + await mockTurnOrder(game, [BattlerIndex.PLAYER, BattlerIndex.ENEMY]); await game.phaseInterceptor.to(MoveEffectPhase, false); // Shield Dust negates secondary effect diff --git a/src/test/abilities/zen_mode.test.ts b/src/test/abilities/zen_mode.test.ts index 63c6a3d4acf..fc0bf282078 100644 --- a/src/test/abilities/zen_mode.test.ts +++ b/src/test/abilities/zen_mode.test.ts @@ -12,7 +12,7 @@ import { Species } from "#enums/species"; import Phaser from "phaser"; import { afterEach, beforeAll, beforeEach, describe, expect, test } from "vitest"; import { BattlerIndex } from "#app/battle.js"; -import { changeTurnOrder } from "../utils/testUtils"; +import { mockTurnOrder } from "../utils/testUtils"; const TIMEOUT = 20 * 1000; @@ -58,7 +58,7 @@ describe("Abilities - ZEN MODE", () => { const movePosition = getMovePosition(game.scene, 0, moveToUse); (game.scene.getCurrentPhase() as CommandPhase).handleCommand(Command.FIGHT, movePosition, false); }); - await changeTurnOrder(game, [BattlerIndex.ENEMY, BattlerIndex.PLAYER]); + await mockTurnOrder(game, [BattlerIndex.ENEMY, BattlerIndex.PLAYER]); await game.phaseInterceptor.to(DamagePhase, false); // await game.phaseInterceptor.runFrom(DamagePhase).to(DamagePhase, false); const damagePhase = game.scene.getCurrentPhase() as DamagePhase; @@ -86,7 +86,7 @@ describe("Abilities - ZEN MODE", () => { const movePosition = getMovePosition(game.scene, 0, moveToUse); (game.scene.getCurrentPhase() as CommandPhase).handleCommand(Command.FIGHT, movePosition, false); }); - await changeTurnOrder(game, [BattlerIndex.ENEMY, BattlerIndex.PLAYER]); + await mockTurnOrder(game, [BattlerIndex.ENEMY, BattlerIndex.PLAYER]); await game.phaseInterceptor.to(QuietFormChangePhase); await game.phaseInterceptor.to(TurnInitPhase, false); expect(game.scene.getParty()[0].hp).not.toBe(100); @@ -111,7 +111,7 @@ describe("Abilities - ZEN MODE", () => { const movePosition = getMovePosition(game.scene, 0, moveToUse); (game.scene.getCurrentPhase() as CommandPhase).handleCommand(Command.FIGHT, movePosition, false); }); - await changeTurnOrder(game, [BattlerIndex.ENEMY, BattlerIndex.PLAYER]); + await mockTurnOrder(game, [BattlerIndex.ENEMY, BattlerIndex.PLAYER]); await game.phaseInterceptor.to(DamagePhase, false); // await game.phaseInterceptor.runFrom(DamagePhase).to(DamagePhase, false); const damagePhase = game.scene.getCurrentPhase() as DamagePhase; diff --git a/src/test/items/leek.test.ts b/src/test/items/leek.test.ts index 2cfd4d8dc64..7ac453f797a 100644 --- a/src/test/items/leek.test.ts +++ b/src/test/items/leek.test.ts @@ -8,7 +8,7 @@ import { Moves } from "#enums/moves"; import { Species } from "#enums/species"; import Phase from "phaser"; import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest"; -import { changeTurnOrder } from "#test/utils/testUtils"; +import { mockTurnOrder } from "#test/utils/testUtils"; describe("Items - Leek", () => { let phaserGame: Phaser.Game; @@ -44,7 +44,7 @@ describe("Items - Leek", () => { game.doAttack(0); - await changeTurnOrder(game, [BattlerIndex.PLAYER, BattlerIndex.ENEMY]); + await mockTurnOrder(game, [BattlerIndex.PLAYER, BattlerIndex.ENEMY]); await game.phaseInterceptor.to(MoveEffectPhase); diff --git a/src/test/items/scope_lens.test.ts b/src/test/items/scope_lens.test.ts index 60f7aec171b..7e5c57c1364 100644 --- a/src/test/items/scope_lens.test.ts +++ b/src/test/items/scope_lens.test.ts @@ -8,7 +8,7 @@ import { Moves } from "#enums/moves"; import { Species } from "#enums/species"; import Phase from "phaser"; import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest"; -import { changeTurnOrder } from "#test/utils/testUtils"; +import { mockTurnOrder } from "#test/utils/testUtils"; describe("Items - Scope Lens", () => { let phaserGame: Phaser.Game; @@ -43,7 +43,7 @@ describe("Items - Scope Lens", () => { ]); game.doAttack(0); - await changeTurnOrder(game, [ BattlerIndex.PLAYER, BattlerIndex.ENEMY ]); + await mockTurnOrder(game, [ BattlerIndex.PLAYER, BattlerIndex.ENEMY ]); await game.phaseInterceptor.to(MoveEffectPhase); diff --git a/src/test/moves/fusion_flare_bolt.test.ts b/src/test/moves/fusion_flare_bolt.test.ts index b0c374c1cd3..95090214962 100644 --- a/src/test/moves/fusion_flare_bolt.test.ts +++ b/src/test/moves/fusion_flare_bolt.test.ts @@ -8,7 +8,7 @@ import { allMoves } from "#app/data/move"; import { BattlerIndex } from "#app/battle"; import { Species } from "#enums/species"; import { Moves } from "#enums/moves"; -import { changeTurnOrder } from "#test/utils/testUtils"; +import { mockTurnOrder } from "#test/utils/testUtils"; describe("Moves - Fusion Flare and Fusion Bolt", () => { let phaserGame: Phaser.Game; @@ -56,7 +56,7 @@ describe("Moves - Fusion Flare and Fusion Bolt", () => { game.doSelectTarget(BattlerIndex.ENEMY); // Force user party to act before enemy party - await changeTurnOrder(game, [ BattlerIndex.PLAYER, BattlerIndex.PLAYER_2, BattlerIndex.ENEMY, BattlerIndex.ENEMY_2 ]); + await mockTurnOrder(game, [ BattlerIndex.PLAYER, BattlerIndex.PLAYER_2, BattlerIndex.ENEMY, BattlerIndex.ENEMY_2 ]); await game.phaseInterceptor.to(MoveEffectPhase, false); expect((game.scene.getCurrentPhase() as MoveEffectPhase).move.moveId).toBe(fusionFlare.id); @@ -82,7 +82,7 @@ describe("Moves - Fusion Flare and Fusion Bolt", () => { game.doSelectTarget(BattlerIndex.ENEMY); // Force user party to act before enemy party - await changeTurnOrder(game, [ BattlerIndex.PLAYER, BattlerIndex.PLAYER_2, BattlerIndex.ENEMY, BattlerIndex.ENEMY_2 ]); + await mockTurnOrder(game, [ BattlerIndex.PLAYER, BattlerIndex.PLAYER_2, BattlerIndex.ENEMY, BattlerIndex.ENEMY_2 ]); await game.phaseInterceptor.to(MoveEffectPhase, false); expect((game.scene.getCurrentPhase() as MoveEffectPhase).move.moveId).toBe(fusionBolt.id); @@ -108,7 +108,7 @@ describe("Moves - Fusion Flare and Fusion Bolt", () => { game.doSelectTarget(0); // Force first enemy to act (and fail) in between party - await changeTurnOrder(game, [ BattlerIndex.PLAYER, BattlerIndex.ENEMY_2, BattlerIndex.PLAYER_2, BattlerIndex.ENEMY ]); + await mockTurnOrder(game, [ BattlerIndex.PLAYER, BattlerIndex.ENEMY_2, BattlerIndex.PLAYER_2, BattlerIndex.ENEMY ]); await game.phaseInterceptor.to(MoveEffectPhase, false); expect((game.scene.getCurrentPhase() as MoveEffectPhase).move.moveId).toBe(fusionFlare.id); @@ -140,7 +140,7 @@ describe("Moves - Fusion Flare and Fusion Bolt", () => { game.doSelectTarget(BattlerIndex.ENEMY); // Force first enemy to act in between party - await changeTurnOrder(game, [ BattlerIndex.PLAYER, BattlerIndex.ENEMY_2, BattlerIndex.PLAYER_2, BattlerIndex.ENEMY ]); + await mockTurnOrder(game, [ BattlerIndex.PLAYER, BattlerIndex.ENEMY_2, BattlerIndex.PLAYER_2, BattlerIndex.ENEMY ]); await game.phaseInterceptor.to(MoveEffectPhase, false); expect((game.scene.getCurrentPhase() as MoveEffectPhase).move.moveId).toBe(fusionFlare.id); @@ -170,7 +170,7 @@ describe("Moves - Fusion Flare and Fusion Bolt", () => { game.doSelectTarget(BattlerIndex.PLAYER); // Force user party to act before enemy party - await changeTurnOrder(game, [ BattlerIndex.PLAYER, BattlerIndex.PLAYER_2, BattlerIndex.ENEMY, BattlerIndex.ENEMY_2 ]); + await mockTurnOrder(game, [ BattlerIndex.PLAYER, BattlerIndex.PLAYER_2, BattlerIndex.ENEMY, BattlerIndex.ENEMY_2 ]); await game.phaseInterceptor.to(MoveEffectPhase, false); expect((game.scene.getCurrentPhase() as MoveEffectPhase).move.moveId).toBe(fusionBolt.id); @@ -222,7 +222,7 @@ describe("Moves - Fusion Flare and Fusion Bolt", () => { game.doSelectTarget(BattlerIndex.ENEMY); // Force first enemy to act in between party - await changeTurnOrder(game, [ BattlerIndex.PLAYER, BattlerIndex.ENEMY_2, BattlerIndex.PLAYER_2, BattlerIndex.ENEMY ]); + await mockTurnOrder(game, [ BattlerIndex.PLAYER, BattlerIndex.ENEMY_2, BattlerIndex.PLAYER_2, BattlerIndex.ENEMY ]); await game.phaseInterceptor.to(MoveEffectPhase, false); expect((game.scene.getCurrentPhase() as MoveEffectPhase).move.moveId).toBe(fusionBolt.id); @@ -284,7 +284,7 @@ describe("Moves - Fusion Flare and Fusion Bolt", () => { game.doSelectTarget(BattlerIndex.PLAYER); // Force first enemy to act in between party - await changeTurnOrder(game, [ BattlerIndex.PLAYER, BattlerIndex.ENEMY_2, BattlerIndex.PLAYER_2, BattlerIndex.ENEMY ]); + await mockTurnOrder(game, [ BattlerIndex.PLAYER, BattlerIndex.ENEMY_2, BattlerIndex.PLAYER_2, BattlerIndex.ENEMY ]); await game.phaseInterceptor.to(MoveEffectPhase, false); expect((game.scene.getCurrentPhase() as MoveEffectPhase).move.moveId).toBe(fusionBolt.id); diff --git a/src/test/moves/gastro_acid.test.ts b/src/test/moves/gastro_acid.test.ts index 77cf35f39e2..8c5f5f14eac 100644 --- a/src/test/moves/gastro_acid.test.ts +++ b/src/test/moves/gastro_acid.test.ts @@ -6,7 +6,7 @@ import { MoveResult } from "#app/field/pokemon.js"; import { afterEach, beforeAll, beforeEach, describe, expect, it } from "vitest"; import GameManager from "#test/utils/gameManager"; import { getMovePosition } from "#test/utils/gameManagerUtils"; -import { changeTurnOrder, SPLASH_ONLY } from "#test/utils/testUtils"; +import { mockTurnOrder, SPLASH_ONLY } from "#test/utils/testUtils"; const TIMEOUT = 20 * 1000; @@ -75,7 +75,7 @@ describe("Moves - Gastro Acid", () => { game.doAttack(getMovePosition(game.scene, 0, Moves.CORE_ENFORCER)); // Force player to be slower to enable Core Enforcer to proc its suppression effect - await changeTurnOrder(game, [BattlerIndex.ENEMY, BattlerIndex.PLAYER]); + await mockTurnOrder(game, [BattlerIndex.ENEMY, BattlerIndex.PLAYER]); await game.phaseInterceptor.to("TurnInitPhase"); diff --git a/src/test/utils/testUtils.ts b/src/test/utils/testUtils.ts index 6ba46e6fc16..f1ed2bcdd07 100644 --- a/src/test/utils/testUtils.ts +++ b/src/test/utils/testUtils.ts @@ -40,15 +40,16 @@ export function removeEnemyHeldItems(game: GameManager): void { } /** - * Used to modify the turn order. Will advance the turn to {@link TurnStartPhase} - * @param game The {@link GameManager} instance - * @param order The turn order to set + * Intercepts `TurnStartPhase` and mocks the getOrder's return value {@linkcode TurnStartPhase.getOrder} + * Used to modify the turn order. + * @param {GameManager} game The GameManager instance + * @param {BattlerIndex[]} order The turn order to set * @example * ```ts - * await changeTurnOrder(game, [BattlerIndex.PLAYER, BattlerIndex.ENEMY, BattlerIndex.ENEMY_2, BattlerIndex.PLAYER_2]); + * await mockTurnOrder(game, [BattlerIndex.PLAYER, BattlerIndex.ENEMY, BattlerIndex.ENEMY_2, BattlerIndex.PLAYER_2]); * ``` */ -export async function changeTurnOrder(game: GameManager, order: BattlerIndex[]): Promise { +export async function mockTurnOrder(game: GameManager, order: BattlerIndex[]): Promise { await game.phaseInterceptor.to(TurnStartPhase, false); vi.spyOn(game.scene.getCurrentPhase() as TurnStartPhase, "getOrder").mockReturnValue(order);