Skip to content

Commit

Permalink
Modify tests
Browse files Browse the repository at this point in the history
  • Loading branch information
DayKev committed Oct 31, 2024
1 parent 7dc8f24 commit 55d1b14
Show file tree
Hide file tree
Showing 53 changed files with 379 additions and 355 deletions.
30 changes: 12 additions & 18 deletions src/test/abilities/zen_mode.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import { SwitchType } from "#enums/switch-type";
describe("Abilities - ZEN MODE", () => {
let phaserGame: Phaser.Game;
let game: GameManager;
const baseForm = 0;
const zenForm = 1;

beforeAll(() => {
phaserGame = new Phaser.Game({
Expand All @@ -37,30 +39,27 @@ describe("Abilities - ZEN MODE", () => {

beforeEach(() => {
game = new GameManager(phaserGame);
const moveToUse = Moves.SPLASH;
game.override.battleType("single");
game.override.enemySpecies(Species.RATTATA);
game.override.enemyAbility(Abilities.HYDRATION);
game.override.ability(Abilities.ZEN_MODE);
game.override.startingLevel(100);
game.override.moveset([ moveToUse ]);
game.override.enemyMoveset([ Moves.TACKLE, Moves.TACKLE, Moves.TACKLE, Moves.TACKLE ]);
game.override.moveset([ Moves.SPLASH ]);
game.override.enemyMoveset(Moves.TACKLE);
});

test(
"not enough damage to change form",
async () => {
const moveToUse = Moves.SPLASH;
await game.startBattle([ Species.DARMANITAN ]);
await game.classicMode.startBattle([ Species.DARMANITAN ]);
game.scene.getParty()[0].stats[Stat.HP] = 100;
game.scene.getParty()[0].hp = 100;
expect(game.scene.getParty()[0].formIndex).toBe(0);

game.move.select(moveToUse);
game.move.select(Moves.SPLASH);

await game.setTurnOrder([ 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;
damagePhase.updateAmount(40);
await game.phaseInterceptor.runFrom(DamagePhase).to(TurnEndPhase, false);
Expand All @@ -72,13 +71,12 @@ describe("Abilities - ZEN MODE", () => {
test(
"enough damage to change form",
async () => {
const moveToUse = Moves.SPLASH;
await game.startBattle([ Species.DARMANITAN ]);
await game.classicMode.startBattle([ Species.DARMANITAN ]);
game.scene.getParty()[0].stats[Stat.HP] = 1000;
game.scene.getParty()[0].hp = 100;
expect(game.scene.getParty()[0].formIndex).toBe(0);

game.move.select(moveToUse);
game.move.select(Moves.SPLASH);

await game.setTurnOrder([ BattlerIndex.ENEMY, BattlerIndex.PLAYER ]);
await game.phaseInterceptor.to(QuietFormChangePhase);
Expand All @@ -91,17 +89,15 @@ describe("Abilities - ZEN MODE", () => {
test(
"kill pokemon while on zen mode",
async () => {
const moveToUse = Moves.SPLASH;
await game.startBattle([ Species.DARMANITAN, Species.CHARIZARD ]);
await game.classicMode.startBattle([ Species.DARMANITAN, Species.CHARIZARD ]);
game.scene.getParty()[0].stats[Stat.HP] = 1000;
game.scene.getParty()[0].hp = 100;
expect(game.scene.getParty()[0].formIndex).toBe(0);

game.move.select(moveToUse);
game.move.select(Moves.SPLASH);

await game.setTurnOrder([ 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;
damagePhase.updateAmount(80);
await game.phaseInterceptor.runFrom(DamagePhase).to(QuietFormChangePhase);
Expand All @@ -113,7 +109,7 @@ describe("Abilities - ZEN MODE", () => {
await game.phaseInterceptor.run(EnemyCommandPhase);
await game.phaseInterceptor.run(TurnStartPhase);
game.onNextPrompt("SwitchPhase", Mode.PARTY, () => {
game.scene.unshiftPhase(new SwitchSummonPhase(game.scene, SwitchType.SWITCH, 0, 1, false));
game.scene.unshiftPhase(new SwitchSummonPhase(SwitchType.SWITCH, 0, 1, false));
game.scene.ui.setMode(Mode.MESSAGE);
});
game.onNextPrompt("SwitchPhase", Mode.MESSAGE, () => {
Expand All @@ -128,14 +124,12 @@ describe("Abilities - ZEN MODE", () => {
test(
"check if fainted pokemon switches to base form on arena reset",
async () => {
const baseForm = 0,
zenForm = 1;
game.override.startingWave(4);
game.override.starterForms({
[Species.DARMANITAN]: zenForm,
});

await game.startBattle([ Species.MAGIKARP, Species.DARMANITAN ]);
await game.classicMode.startBattle([ Species.MAGIKARP, Species.DARMANITAN ]);

const darmanitan = game.scene.getParty().find((p) => p.species.speciesId === Species.DARMANITAN)!;
expect(darmanitan).not.toBe(undefined);
Expand Down
32 changes: 14 additions & 18 deletions src/test/achievements/achievement.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,11 @@ describe("Achv", () => {
});

it("should validate the achievement based on the condition function", () => {
const conditionFunc = vi.fn((scene: BattleScene, args: any[]) => args[0] === 10);
const conditionFunc = vi.fn((args: any[]) => args[0] === 10);
const achv = new Achv("", "Test Achievement", "Test Description", "test_icon", 10, conditionFunc);

expect(achv.validate(new BattleScene(), [ 5 ])).toBe(false);
expect(achv.validate(new BattleScene(), [ 10 ])).toBe(true);
expect(achv.validate([ 5 ])).toBe(false);
expect(achv.validate([ 10 ])).toBe(true);
expect(conditionFunc).toHaveBeenCalledTimes(2);
});
});
Expand All @@ -79,10 +79,10 @@ describe("MoneyAchv", () => {
const scene = new BattleScene();
scene.money = 5000;

expect(moneyAchv.validate(scene, [])).toBe(false);
expect(moneyAchv.validate([])).toBe(false);

scene.money = 15000;
expect(moneyAchv.validate(scene, [])).toBe(true);
expect(moneyAchv.validate([])).toBe(true);
});
});

Expand Down Expand Up @@ -122,10 +122,10 @@ describe("RibbonAchv", () => {
const ribbonAchv = new RibbonAchv("", "Test Ribbon Achievement", 10, "ribbon_icon", 10);
scene.gameData.gameStats.ribbonsOwned = 5;

expect(ribbonAchv.validate(scene, [])).toBe(false);
expect(ribbonAchv.validate([])).toBe(false);

scene.gameData.gameStats.ribbonsOwned = 15;
expect(ribbonAchv.validate(scene, [])).toBe(true);
expect(ribbonAchv.validate([])).toBe(true);
});
});

Expand All @@ -138,13 +138,12 @@ describe("DamageAchv", () => {

it("should validate the achievement based on the damage amount", () => {
const damageAchv = new DamageAchv("", "Test Damage Achievement", 250, "damage_icon", 10);
const scene = new BattleScene();
const numberHolder = new NumberHolder(200);

expect(damageAchv.validate(scene, [ numberHolder ])).toBe(false);
expect(damageAchv.validate([ numberHolder ])).toBe(false);

numberHolder.value = 300;
expect(damageAchv.validate(scene, [ numberHolder ])).toBe(true);
expect(damageAchv.validate([ numberHolder ])).toBe(true);
});
});

Expand All @@ -157,13 +156,12 @@ describe("HealAchv", () => {

it("should validate the achievement based on the heal amount", () => {
const healAchv = new HealAchv("", "Test Heal Achievement", 250, "heal_icon", 10);
const scene = new BattleScene();
const numberHolder = new NumberHolder(200);

expect(healAchv.validate(scene, [ numberHolder ])).toBe(false);
expect(healAchv.validate([ numberHolder ])).toBe(false);

numberHolder.value = 300;
expect(healAchv.validate(scene, [ numberHolder ])).toBe(true);
expect(healAchv.validate([ numberHolder ])).toBe(true);
});
});

Expand All @@ -176,13 +174,12 @@ describe("LevelAchv", () => {

it("should validate the achievement based on the level", () => {
const levelAchv = new LevelAchv("", "Test Level Achievement", 100, "level_icon", 10);
const scene = new BattleScene();
const integerHolder = new IntegerHolder(50);

expect(levelAchv.validate(scene, [ integerHolder ])).toBe(false);
expect(levelAchv.validate([ integerHolder ])).toBe(false);

integerHolder.value = 150;
expect(levelAchv.validate(scene, [ integerHolder ])).toBe(true);
expect(levelAchv.validate([ integerHolder ])).toBe(true);
});
});

Expand All @@ -195,10 +192,9 @@ describe("ModifierAchv", () => {

it("should validate the achievement based on the modifier function", () => {
const modifierAchv = new ModifierAchv("", "Test Modifier Achievement", "Test Description", "modifier_icon", 10, () => true);
const scene = new BattleScene();
const modifier = new TurnHeldItemTransferModifier(null!, 3, 1);

expect(modifierAchv.validate(scene, [ modifier ])).toBe(true);
expect(modifierAchv.validate([ modifier ])).toBe(true);
});
});

Expand Down
4 changes: 2 additions & 2 deletions src/test/battle/battle.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,8 @@ describe("Test Battle Phase", () => {
game.onNextPrompt("TitlePhase", Mode.TITLE, () => {
game.scene.gameMode = getGameMode(GameModes.CLASSIC);
const starters = generateStarter(game.scene);
const selectStarterPhase = new SelectStarterPhase(game.scene);
game.scene.pushPhase(new EncounterPhase(game.scene, false));
const selectStarterPhase = new SelectStarterPhase();
game.scene.pushPhase(new EncounterPhase(false));
selectStarterPhase.initBattle(starters);
});
await game.phaseInterceptor.runFrom(SelectGenderPhase).to(SummonPhase);
Expand Down
25 changes: 18 additions & 7 deletions src/test/battlerTags/octolock.test.ts
Original file line number Diff line number Diff line change
@@ -1,32 +1,43 @@
import BattleScene from "#app/battle-scene";
import { describe, expect, it, vi } from "vitest";
import { afterEach, beforeAll, describe, expect, it, vi } from "vitest";
import Pokemon from "#app/field/pokemon";
import { BattlerTag, BattlerTagLapseType, OctolockTag, TrappedTag } from "#app/data/battler-tags";
import { StatStageChangePhase } from "#app/phases/stat-stage-change-phase";
import { BattlerTagType } from "#app/enums/battler-tag-type";
import { Stat } from "#enums/stat";

vi.mock("#app/battle-scene.js");
import GameManager from "#test/utils/gameManager";

describe("BattlerTag - OctolockTag", () => {
describe("lapse behavior", () => {
let phaserGame: Phaser.Game;
let game: GameManager;

beforeAll(() => {
phaserGame = new Phaser.Game({
type: Phaser.HEADLESS,
});
game = new GameManager(phaserGame);
});

afterEach(() => {
game.phaseInterceptor.restoreOg();
});

it("unshifts a StatStageChangePhase with expected stat stage changes", async () => {
const mockPokemon = {
scene: new BattleScene(),
getBattlerIndex: () => 0,
} as Pokemon;

const subject = new OctolockTag(1);

vi.spyOn(mockPokemon.scene, "unshiftPhase").mockImplementation(phase => {
vi.spyOn(game.scene, "unshiftPhase").mockImplementation(phase => {
expect(phase).toBeInstanceOf(StatStageChangePhase);
expect((phase as StatStageChangePhase)["stages"]).toEqual(-1);
expect((phase as StatStageChangePhase)["stats"]).toEqual([ Stat.DEF, Stat.SPDEF ]);
});

subject.lapse(mockPokemon, BattlerTagLapseType.TURN_END);

expect(mockPokemon.scene.unshiftPhase).toBeCalledTimes(1);
expect(game.scene.unshiftPhase).toBeCalledTimes(1);
});
});

Expand Down
Loading

0 comments on commit 55d1b14

Please sign in to comment.