Skip to content

Commit

Permalink
Fix SelectModifierPhase tests
Browse files Browse the repository at this point in the history
  • Loading branch information
DayKev committed Nov 14, 2024
1 parent c01c623 commit 9395013
Show file tree
Hide file tree
Showing 12 changed files with 97 additions and 115 deletions.
2 changes: 1 addition & 1 deletion src/test/abilities/infiltrator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ describe("Abilities - Infiltrator", () => {
});

// TODO: fix this interaction to pass this test
it.skip("should bypass the target's Mist", async () => {
it.todo("should bypass the target's Mist", async () => {
await game.classicMode.startBattle([ Species.MAGIKARP ]);

const player = game.scene.getPlayerPokemon()!;
Expand Down
1 change: 1 addition & 0 deletions src/test/abilities/libero.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ describe("Abilities - Libero", () => {
},
);

// Test for Gen9+ functionality, we are using previous funcionality
test.skip(
"ability applies only once per switch in",
async () => {
Expand Down
1 change: 1 addition & 0 deletions src/test/abilities/protean.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ describe("Abilities - Protean", () => {
},
);

// Test for Gen9+ functionality, we are using previous funcionality
test.skip(
"ability applies only once per switch in",
async () => {
Expand Down
45 changes: 0 additions & 45 deletions src/test/battle/error-handling.test.ts

This file was deleted.

4 changes: 2 additions & 2 deletions src/test/battlerTags/substitute.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,8 @@ describe("BattlerTag - SubstituteTag", () => {
}
);

/** TODO: Figure out how to mock a MoveEffectPhase correctly for this test */
it.skip(
// TODO: Figure out how to mock a MoveEffectPhase correctly for this test
it.todo(
"HIT lapse triggers on-hit message",
async () => {
const subject = new SubstituteTag(Moves.SUBSTITUTE, mockPokemon.id);
Expand Down
3 changes: 2 additions & 1 deletion src/test/moves/burning_jealousy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ describe("Moves - Burning Jealousy", () => {
expect(enemy.status?.effect).toBeUndefined();
});

it.skip("should ignore weakness policy", async () => { // TODO: Make this test if WP is implemented
// TODO: Make this test if WP is implemented
it.todo("should ignore weakness policy", async () => {
await game.classicMode.startBattle();
});

Expand Down
10 changes: 5 additions & 5 deletions src/test/moves/parting_shot.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ describe("Moves - Parting Shot", () => {
}
);

it.skip( // TODO: fix this bug to pass the test!
it.todo( // TODO: fix this bug to pass the test!
"Parting shot should fail if target is -6/-6 de-buffed",
async () => {
game.override.moveset([ Moves.PARTING_SHOT, Moves.MEMENTO, Moves.SPLASH ]);
Expand Down Expand Up @@ -117,7 +117,7 @@ describe("Moves - Parting Shot", () => {
}
);

it.skip( // TODO: fix this bug to pass the test!
it.todo( // TODO: fix this bug to pass the test!
"Parting shot shouldn't allow switch out when mist is active",
async () => {
game.override
Expand All @@ -138,7 +138,7 @@ describe("Moves - Parting Shot", () => {
}
);

it.skip( // TODO: fix this bug to pass the test!
it.todo( // TODO: fix this bug to pass the test!
"Parting shot shouldn't allow switch out against clear body ability",
async () => {
game.override
Expand All @@ -158,7 +158,7 @@ describe("Moves - Parting Shot", () => {
}
);

it.skip( // TODO: fix this bug to pass the test!
it.todo( // TODO: fix this bug to pass the test!
"Parting shot should de-buff and not fail if no party available to switch - party size 1",
async () => {
await game.startBattle([ Species.MURKROW ]);
Expand All @@ -175,7 +175,7 @@ describe("Moves - Parting Shot", () => {
}
);

it.skip( // TODO: fix this bug to pass the test!
it.todo( // TODO: fix this bug to pass the test!
"Parting shot regularly not fail if no party available to switch - party fainted",
async () => {
await game.startBattle([ Species.MURKROW, Species.MEOWTH ]);
Expand Down
2 changes: 1 addition & 1 deletion src/test/moves/tera_blast.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ describe("Moves - Tera Blast", () => {
});

// Currently abilities are bugged and can't see when a move's category is changed
it.skip("uses the higher stat of the user's Atk and SpAtk for damage calculation", async () => {
it.todo("uses the higher stat of the user's Atk and SpAtk for damage calculation", async () => {
game.override.enemyAbility(Abilities.TOXIC_DEBRIS);
await game.startBattle();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,8 +247,7 @@ describe("Clowning Around - Mystery Encounter", () => {
});
});

// this is the test that's broken due to the event
it.skip("should randomize held items of the Pokemon with the most items, and not the held items of other pokemon", async () => {
it("should randomize held items of the Pokemon with the most items, and not the held items of other pokemon", async () => {
await game.runToMysteryEncounter(MysteryEncounterType.CLOWNING_AROUND, defaultParty);

// Set some moves on party for attack type booster generation
Expand Down
108 changes: 62 additions & 46 deletions src/test/phases/select-modifier-phase.test.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
import Phaser from "phaser";
import GameManager from "#app/test/utils/gameManager";
import { initSceneWithoutEncounterPhase } from "#app/test/utils/gameManagerUtils";
import ModifierSelectUiHandler from "#app/ui/modifier-select-ui-handler";
import type BattleScene from "#app/battle-scene";
import { getPokemonSpecies } from "#app/data/pokemon-species";
import { PlayerPokemon } from "#app/field/pokemon";
import { ModifierTier } from "#app/modifier/modifier-tier";
import * as Utils from "#app/utils";
import { CustomModifierSettings, ModifierTypeOption, modifierTypes } from "#app/modifier/modifier-type";
import BattleScene from "#app/battle-scene";
import { Species } from "#enums/species";
import { Mode } from "#app/ui/ui";
import { PlayerPokemon } from "#app/field/pokemon";
import { getPokemonSpecies } from "#app/data/pokemon-species";
import { SelectModifierPhase } from "#app/phases/select-modifier-phase";
import ModifierSelectUiHandler from "#app/ui/modifier-select-ui-handler";
import { Mode } from "#app/ui/ui";
import { shiftCharCodes } from "#app/utils";
import { Abilities } from "#enums/abilities";
import { Button } from "#enums/buttons";
import { Moves } from "#enums/moves";
import { Species } from "#enums/species";
import GameManager from "#test/utils/gameManager";
import { initSceneWithoutEncounterPhase } from "#test/utils/gameManagerUtils";
import Phaser from "phaser";
import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";

// TODO: why are the `expect(modifierSelectHandler.options.length).toEqual(#)` checks unreliable/failing?
describe.skip("SelectModifierPhase", () => {
describe("SelectModifierPhase", () => {
let phaserGame: Phaser.Game;
let game: GameManager;
let scene: BattleScene;
Expand All @@ -29,7 +32,11 @@ describe.skip("SelectModifierPhase", () => {
game = new GameManager(phaserGame);
scene = game.scene;

initSceneWithoutEncounterPhase(scene, [ Species.ABRA, Species.VOLCARONA ]);
game.override
.moveset([ Moves.FISSURE, Moves.SPLASH ])
.ability(Abilities.NO_GUARD)
.startingLevel(200)
.enemySpecies(Species.MAGIKARP);
});

afterEach(() => {
Expand All @@ -39,6 +46,7 @@ describe.skip("SelectModifierPhase", () => {
});

it("should start a select modifier phase", async () => {
initSceneWithoutEncounterPhase(scene, [ Species.ABRA, Species.VOLCARONA ]);
const selectModifierPhase = new SelectModifierPhase();
scene.pushPhase(selectModifierPhase);
await game.phaseInterceptor.run(SelectModifierPhase);
Expand All @@ -47,17 +55,17 @@ describe.skip("SelectModifierPhase", () => {
});

it("should generate random modifiers", async () => {
const selectModifierPhase = new SelectModifierPhase();
scene.pushPhase(selectModifierPhase);
await game.phaseInterceptor.run(SelectModifierPhase);

await game.classicMode.startBattle([ Species.ABRA, Species.VOLCARONA ]);
game.move.select(Moves.FISSURE);
await game.phaseInterceptor.to("SelectModifierPhase");

expect(scene.ui.getMode()).to.equal(Mode.MODIFIER_SELECT);
const modifierSelectHandler = scene.ui.handlers.find(h => h instanceof ModifierSelectUiHandler) as ModifierSelectUiHandler;
expect(modifierSelectHandler.options.length).toEqual(3);
});

it("should modify reroll cost", async () => {
initSceneWithoutEncounterPhase(scene, [ Species.ABRA, Species.VOLCARONA ]);
const options = [
new ModifierTypeOption(modifierTypes.POTION(), 0, 100),
new ModifierTypeOption(modifierTypes.ETHER(), 0, 400),
Expand All @@ -72,50 +80,48 @@ describe.skip("SelectModifierPhase", () => {
expect(cost2).toEqual(cost1 * 2);
});

it("should generate random modifiers from reroll", async () => {
let selectModifierPhase = new SelectModifierPhase();
scene.pushPhase(selectModifierPhase);
await game.phaseInterceptor.run(SelectModifierPhase);
it.todo("should generate random modifiers from reroll", async () => {
await game.classicMode.startBattle([ Species.ABRA, Species.VOLCARONA ]);
scene.money = 1000000;
scene.shopCursorTarget = 0;

game.move.select(Moves.FISSURE);
await game.phaseInterceptor.to("SelectModifierPhase");

// TODO: nagivate the ui to reroll somehow
//const smphase = scene.getCurrentPhase() as SelectModifierPhase;
expect(scene.ui.getMode()).to.equal(Mode.MODIFIER_SELECT);
const modifierSelectHandler = scene.ui.handlers.find(h => h instanceof ModifierSelectUiHandler) as ModifierSelectUiHandler;
expect(modifierSelectHandler.options.length).toEqual(3);

// Simulate selecting reroll
selectModifierPhase = new SelectModifierPhase(1, [ ModifierTier.COMMON, ModifierTier.COMMON, ModifierTier.COMMON ]);
scene.unshiftPhase(selectModifierPhase);
scene.ui.setMode(Mode.MESSAGE).then(() => game.endPhase());
await game.phaseInterceptor.run(SelectModifierPhase);
modifierSelectHandler.processInput(Button.ACTION);

expect(scene.money).toBe(1000000 - 250);
expect(scene.ui.getMode()).to.equal(Mode.MODIFIER_SELECT);
expect(modifierSelectHandler.options.length).toEqual(3);
});

it("should generate random modifiers of same tier for reroll with reroll lock", async () => {
it.todo("should generate random modifiers of same tier for reroll with reroll lock", async () => {
game.override.startingModifier([{ name: "LOCK_CAPSULE" }]);
await game.classicMode.startBattle([ Species.ABRA, Species.VOLCARONA ]);
scene.money = 1000000;
// Just use fully random seed for this test
vi.spyOn(scene, "resetSeed").mockImplementation(() => {
scene.waveSeed = Utils.shiftCharCodes(scene.seed, 5);
scene.waveSeed = shiftCharCodes(scene.seed, 5);
Phaser.Math.RND.sow([ scene.waveSeed ]);
console.log("Wave Seed:", scene.waveSeed, 5);
scene.rngCounter = 0;
});

let selectModifierPhase = new SelectModifierPhase();
scene.pushPhase(selectModifierPhase);
await game.phaseInterceptor.run(SelectModifierPhase);
game.move.select(Moves.FISSURE);
await game.phaseInterceptor.to("SelectModifierPhase");

expect(scene.ui.getMode()).to.equal(Mode.MODIFIER_SELECT);
const modifierSelectHandler = scene.ui.handlers.find(h => h instanceof ModifierSelectUiHandler) as ModifierSelectUiHandler;
expect(modifierSelectHandler.options.length).toEqual(3);
const firstRollTiers: ModifierTier[] = modifierSelectHandler.options.map(o => o.modifierTypeOption.type.tier);

// Simulate selecting reroll with lock
scene.lockModifierTiers = true;
scene.reroll = true;
selectModifierPhase = new SelectModifierPhase(1, firstRollTiers);
scene.unshiftPhase(selectModifierPhase);
scene.ui.setMode(Mode.MESSAGE).then(() => game.endPhase());
await game.phaseInterceptor.run(SelectModifierPhase);
// TODO: nagivate ui to reroll with lock capsule enabled

expect(scene.ui.getMode()).to.equal(Mode.MODIFIER_SELECT);
expect(modifierSelectHandler.options.length).toEqual(3);
Expand All @@ -126,13 +132,15 @@ describe.skip("SelectModifierPhase", () => {
});

it("should generate custom modifiers", async () => {
await game.classicMode.startBattle([ Species.ABRA, Species.VOLCARONA ]);
scene.money = 1000000;
const customModifiers: CustomModifierSettings = {
guaranteedModifierTypeFuncs: [ modifierTypes.MEMORY_MUSHROOM, modifierTypes.TM_ULTRA, modifierTypes.LEFTOVERS, modifierTypes.AMULET_COIN, modifierTypes.GOLDEN_PUNCH ]
};
const selectModifierPhase = new SelectModifierPhase(0, undefined, customModifiers);
scene.pushPhase(selectModifierPhase);
await game.phaseInterceptor.run(SelectModifierPhase);

scene.unshiftPhase(selectModifierPhase);
game.move.select(Moves.SPLASH);
await game.phaseInterceptor.to("SelectModifierPhase");

expect(scene.ui.getMode()).to.equal(Mode.MODIFIER_SELECT);
const modifierSelectHandler = scene.ui.handlers.find(h => h instanceof ModifierSelectUiHandler) as ModifierSelectUiHandler;
Expand All @@ -145,6 +153,8 @@ describe.skip("SelectModifierPhase", () => {
});

it("should generate custom modifier tiers that can upgrade from luck", async () => {
await game.classicMode.startBattle([ Species.ABRA, Species.VOLCARONA ]);
scene.money = 1000000;
const customModifiers: CustomModifierSettings = {
guaranteedModifierTiers: [ ModifierTier.COMMON, ModifierTier.GREAT, ModifierTier.ULTRA, ModifierTier.ROGUE, ModifierTier.MASTER ]
};
Expand All @@ -157,9 +167,9 @@ describe.skip("SelectModifierPhase", () => {
scene.getPlayerParty().push(pokemon, pokemon, pokemon, pokemon, pokemon, pokemon);

const selectModifierPhase = new SelectModifierPhase(0, undefined, customModifiers);
scene.pushPhase(selectModifierPhase);
await game.phaseInterceptor.run(SelectModifierPhase);

scene.unshiftPhase(selectModifierPhase);
game.move.select(Moves.SPLASH);
await game.phaseInterceptor.to("SelectModifierPhase");

expect(scene.ui.getMode()).to.equal(Mode.MODIFIER_SELECT);
const modifierSelectHandler = scene.ui.handlers.find(h => h instanceof ModifierSelectUiHandler) as ModifierSelectUiHandler;
Expand All @@ -172,12 +182,15 @@ describe.skip("SelectModifierPhase", () => {
});

it("should generate custom modifiers and modifier tiers together", async () => {
await game.classicMode.startBattle([ Species.ABRA, Species.VOLCARONA ]);
scene.money = 1000000;
const customModifiers: CustomModifierSettings = {
guaranteedModifierTypeFuncs: [ modifierTypes.MEMORY_MUSHROOM, modifierTypes.TM_COMMON ],
guaranteedModifierTiers: [ ModifierTier.MASTER, ModifierTier.MASTER ]
};
const selectModifierPhase = new SelectModifierPhase(0, undefined, customModifiers);
scene.pushPhase(selectModifierPhase);
scene.unshiftPhase(selectModifierPhase);
game.move.select(Moves.SPLASH);
await game.phaseInterceptor.run(SelectModifierPhase);


Expand All @@ -191,13 +204,16 @@ describe.skip("SelectModifierPhase", () => {
});

it("should fill remaining modifiers if fillRemaining is true with custom modifiers", async () => {
await game.classicMode.startBattle([ Species.ABRA, Species.VOLCARONA ]);
scene.money = 1000000;
const customModifiers: CustomModifierSettings = {
guaranteedModifierTypeFuncs: [ modifierTypes.MEMORY_MUSHROOM ],
guaranteedModifierTiers: [ ModifierTier.MASTER ],
fillRemaining: true
};
const selectModifierPhase = new SelectModifierPhase(0, undefined, customModifiers);
scene.pushPhase(selectModifierPhase);
scene.unshiftPhase(selectModifierPhase);
game.move.select(Moves.SPLASH);
await game.phaseInterceptor.run(SelectModifierPhase);


Expand Down
Loading

0 comments on commit 9395013

Please sign in to comment.