Skip to content

Commit

Permalink
[Test] Adjust Unit Tests for Dynamax Cannon
Browse files Browse the repository at this point in the history
  • Loading branch information
xsn34kzx committed Jul 11, 2024
1 parent 1bdb29e commit 67f3b0d
Showing 1 changed file with 68 additions and 58 deletions.
126 changes: 68 additions & 58 deletions src/test/moves/dynamax_cannon.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,38 @@ import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vite
import Phaser from "phaser";
import GameManager from "#app/test/utils/gameManager";
import * as overrides from "#app/overrides";
import { Species } from "#enums/species";
import { MoveEffectPhase } from "#app/phases";
import { Moves } from "#enums/moves";
import { getMovePosition } from "#app/test/utils/gameManagerUtils";
import { Stat } from "#app/data/pokemon-stat";
import { applyMoveAttrs, VariablePowerAttr } from "#app/data/move";
import * as Utils from "#app/utils";
import { Moves } from "#enums/moves";
import { Species } from "#enums/species";

describe("Moves - Dynamax Cannon", () => {
let phaserGame: Phaser.Game;
let game: GameManager;

/**
* Checks the base power of the {@linkcode intendedMove} before and after any
* {@linkcode VariablePowerAttr}s have been applied.
* @param phase current {@linkcode MoveEffectPhase}
* @param intendedMove Expected move during this {@linkcode phase}
* @param before Expected base power before any base power changes
* @param after Expected base power after any base power changes
*/
const checkBasePowerChanges = (phase: MoveEffectPhase, intendedMove: Moves, before: number, after: number) => {
// Double check if the intended move was used and verify its initial base power
const move = phase.move.getMove();
expect(move.id).toBe(intendedMove);
expect(move.power).toBe(before);

/** Mocking application of {@linkcode VariablePowerAttr} */
const power = new Utils.IntegerHolder(move.power);
applyMoveAttrs(VariablePowerAttr, phase.getUserPokemon(), phase.getTarget(), move, power);
expect(power.value).toBe(after);
};

beforeAll(() => {
phaserGame = new Phaser.Game({
type: Phaser.HEADLESS,
Expand Down Expand Up @@ -49,16 +69,7 @@ describe("Moves - Dynamax Cannon", () => {

await game.phaseInterceptor.to(MoveEffectPhase, false);

// Check initial base power of Dynamax Cannon
const phase = game.scene.getCurrentPhase() as MoveEffectPhase;
const move = phase.move.getMove();
expect(move.id).toBe(moveToUse);
expect(move.power).toBe(100);

// Check base power of Dynamax Cannon in context
const power = new Utils.IntegerHolder(move.power);
applyMoveAttrs(VariablePowerAttr, phase.getUserPokemon(), phase.getTarget(), move, power);
expect(power.value).toBe(100);
checkBasePowerChanges(game.scene.getCurrentPhase() as MoveEffectPhase, moveToUse, 100, 100);
}, 20000);

it("DYNAMAX CANNON against enemy exactly at level cap", async() => {
Expand All @@ -72,19 +83,10 @@ describe("Moves - Dynamax Cannon", () => {

await game.phaseInterceptor.to(MoveEffectPhase, false);

// Check initial base power of Dynamax Cannon
const phase = game.scene.getCurrentPhase() as MoveEffectPhase;
const move = phase.move.getMove();
expect(move.id).toBe(moveToUse);
expect(move.power).toBe(100);

// Check base power of Dynamax Cannon in context
const power = new Utils.IntegerHolder(move.power);
applyMoveAttrs(VariablePowerAttr, phase.getUserPokemon(), phase.getTarget(), move, power);
expect(power.value).toBe(100);
checkBasePowerChanges(game.scene.getCurrentPhase() as MoveEffectPhase, moveToUse, 100, 100);
}, 20000);

it("DYNAMAX CANNON against enemy at 1% above level cap", async() => {
it("DYNAMAX CANNON against enemy exactly at 1% above level cap", async() => {
vi.spyOn(overrides, "OPP_LEVEL_OVERRIDE", "get").mockReturnValue(101);
const moveToUse = Moves.DYNAMAX_CANNON;
await game.startBattle([
Expand All @@ -95,23 +97,16 @@ describe("Moves - Dynamax Cannon", () => {

await game.phaseInterceptor.to(MoveEffectPhase, false);

// Check initial base power of Dynamax Cannon
const phase = game.scene.getCurrentPhase() as MoveEffectPhase;
const move = phase.move.getMove();
expect(move.id).toBe(moveToUse);
expect(move.power).toBe(100);

const target = phase.getTarget();
// Force level cap to be 100; that is, level cap is no longer 10
target.scene.getMaxExpLevel = vi.fn().mockReturnValue(100);

// Check base power of Dynamax Cannon in context
const power = new Utils.IntegerHolder(move.power);
applyMoveAttrs(VariablePowerAttr, phase.getUserPokemon(), target, move, power);
expect(power.value).toBe(120);
checkBasePowerChanges(phase, moveToUse, 100, 120);
}, 20000);

it("DYNAMAX CANNON against enemy at 2% above level cap", async() => {
it("DYNAMAX CANNON against enemy exactly at 2% above level cap", async() => {
vi.spyOn(overrides, "OPP_LEVEL_OVERRIDE", "get").mockReturnValue(102);
const moveToUse = Moves.DYNAMAX_CANNON;
await game.startBattle([
Expand All @@ -122,19 +117,50 @@ describe("Moves - Dynamax Cannon", () => {

await game.phaseInterceptor.to(MoveEffectPhase, false);

// Check initial base power of Dynamax Cannon
const phase = game.scene.getCurrentPhase() as MoveEffectPhase;
const move = phase.move.getMove();
expect(move.id).toBe(moveToUse);
expect(move.power).toBe(100);

const target = phase.getTarget();
target.scene.getMaxExpLevel = vi.fn().mockReturnValue(100);

// Check base power of Dynamax Cannon in context
const power = new Utils.IntegerHolder(move.power);
applyMoveAttrs(VariablePowerAttr, phase.getUserPokemon(), target, move, power);
expect(power.value).toBe(140);
checkBasePowerChanges(phase, moveToUse, 100, 140);
}, 20000);

it("DYNAMAX CANNON against enemy exactly at 3% above level cap", async() => {
vi.spyOn(overrides, "OPP_LEVEL_OVERRIDE", "get").mockReturnValue(103);
const moveToUse = Moves.DYNAMAX_CANNON;
await game.startBattle([
Species.ETERNATUS,
]);

game.doAttack(getMovePosition(game.scene, 0, moveToUse));

await game.phaseInterceptor.to(MoveEffectPhase, false);

const phase = game.scene.getCurrentPhase() as MoveEffectPhase;

const target = phase.getTarget();
target.scene.getMaxExpLevel = vi.fn().mockReturnValue(100);

checkBasePowerChanges(phase, moveToUse, 100, 160);
}, 20000);

it("DYNAMAX CANNON against enemy exactly at 4% above level cap", async() => {
vi.spyOn(overrides, "OPP_LEVEL_OVERRIDE", "get").mockReturnValue(104);
const moveToUse = Moves.DYNAMAX_CANNON;
await game.startBattle([
Species.ETERNATUS,
]);

game.doAttack(getMovePosition(game.scene, 0, moveToUse));

await game.phaseInterceptor.to(MoveEffectPhase, false);

const phase = game.scene.getCurrentPhase() as MoveEffectPhase;

const target = phase.getTarget();
target.scene.getMaxExpLevel = vi.fn().mockReturnValue(100);

checkBasePowerChanges(phase, moveToUse, 100, 180);
}, 20000);

it("DYNAMAX CANNON against enemy exactly at 5% above level cap", async() => {
Expand All @@ -148,19 +174,12 @@ describe("Moves - Dynamax Cannon", () => {

await game.phaseInterceptor.to(MoveEffectPhase, false);

// Check initial base power of Dynamax Cannon
const phase = game.scene.getCurrentPhase() as MoveEffectPhase;
const move = phase.move.getMove();
expect(move.id).toBe(moveToUse);
expect(move.power).toBe(100);

const target = phase.getTarget();
target.scene.getMaxExpLevel = vi.fn().mockReturnValue(100);

// Check base power of Dynamax Cannon in context
const power = new Utils.IntegerHolder(move.power);
applyMoveAttrs(VariablePowerAttr, phase.getUserPokemon(), target, move, power);
expect(power.value).toBe(200);
checkBasePowerChanges(phase, moveToUse, 100, 200);
}, 20000);

it("DYNAMAX CANNON against enemy way above level cap", async() => {
Expand All @@ -177,15 +196,6 @@ describe("Moves - Dynamax Cannon", () => {

await game.phaseInterceptor.to(MoveEffectPhase, false);

// Check initial base power of Dynamax Cannon
const phase = game.scene.getCurrentPhase() as MoveEffectPhase;
const move = phase.move.getMove();
expect(move.id).toBe(moveToUse);
expect(move.power).toBe(100);

// Check base power of Dynamax Cannon in context
const power = new Utils.IntegerHolder(move.power);
applyMoveAttrs(VariablePowerAttr, phase.getUserPokemon(), phase.getTarget(), move, power);
expect(power.value).toBe(200);
checkBasePowerChanges(game.scene.getCurrentPhase() as MoveEffectPhase, moveToUse, 100, 200);
}, 20000);
});

0 comments on commit 67f3b0d

Please sign in to comment.