pokerogue/test/ui/type-hints.test.ts
Sirz Benjie ec4ddab8be
[Bug] [Refactor] [Move] Add selection prevention and move failures (#6276)
* Add failure conditions and move failures part 1

* Add second and third failure sequences

* Refactor mostly complete, need to recheck tests

* Adjust status checks to respect ignoreStatus useModes

* Adjust restriction for stuff cheeks

* Address bertie's review comments

* Add counterRedirectAttr to other counter-like moves

* Adjust some documentation for new methods

* Make substitute use the move tag

* Adjust counter attr to use array.find

* Adjust move condition check that occurs in the third failure check sequence

* Insert move failure check sequence part 4 into move phase

* Revert type adjustment to getBattlerIndex

* Make charging moves deduct pp on use instead of on release

* Fix first move condition not using 1 based starting wave

* Tweak charge move handling and protean timing

* Adjust fly tests to expect pp reduction properly

* Add missing attribute to counter

* Adjust revival blessing hardcore test to respect new return value of isUsable

* Adjust copycat test to account for how it actually works

* Play sleep animation and message

* Remove BYPASS_SLEEP battler tag in favor of boolean holder

* Finish unfinished docs

* Ensure move restrictions are only checked for players

* Adjust pollen puff condition, fix docs on `isOpponent`

* Fix failAgainstFinalBossCondition

* Fix dig test

* Adjust dive's test

* Fix missing break in applyConditions

* Fix getBattlerIndex for enemyPokemon

* Adjust type hint test to not rely on teleport

* Minor adjustments from code review

Co-authored-by: Bertie690 <136088738+Bertie690@users.noreply.github.com>

* Add tests for teleport

* Minor adjustments from code review

Co-authored-by: Bertie690 <136088738+Bertie690@users.noreply.github.com>

* PR review changes

Fix type hints test name

Update Dig/Dive test name

Separate TSDoc imports in `pokemon-utils.ts`

Add missing `@returns` in `move-phase.ts`

Fix comment typos

Separate TSDoc imports in `move-phase.ts`

Add return hints to `trySelectMove`

Minor formatting

Remove duplicate `.affectedByGravity()` on Telekinesis

Fix docs for `checkRestrictions`

Manually format method definition

Fix comment spacing

Fix variable naming

* Address kev's review comments

Co-authored-by: NightKev <34855794+DayKev@users.noreply.github.com>

* Minor adjustments from code review

Co-authored-by: Bertie690 <136088738+Bertie690@users.noreply.github.com>

* Remove optional chaining

* fix: type for InferKeys

* chore: apply biome

* chore: fix merge conflicts from Biome update

* Remove latent isNullOrUndefined

* Drop readonly on timingModifier

* docs: Add class comment

* Address comments from code review

* Drop readonly from timingModifier

* Cleanup proc chance computation

* Move `cureStatus` into the Pokemon class

* Final touchups

---------

Co-authored-by: Bertie690 <136088738+Bertie690@users.noreply.github.com>
Co-authored-by: NightKev <34855794+DayKev@users.noreply.github.com>
2025-09-29 12:08:42 -05:00

123 lines
4.5 KiB
TypeScript

import { Button } from "#enums/buttons";
import { MoveId } from "#enums/move-id";
import { SpeciesId } from "#enums/species-id";
import { UiMode } from "#enums/ui-mode";
import { GameManager } from "#test/test-utils/game-manager";
import type { MockText } from "#test/test-utils/mocks/mocks-container/mock-text";
import { FightUiHandler } from "#ui/fight-ui-handler";
import i18next from "i18next";
import Phaser from "phaser";
import { afterEach, beforeAll, beforeEach, describe, expect, it } from "vitest";
describe("UI - Type Hints", () => {
let phaserGame: Phaser.Game;
let game: GameManager;
beforeAll(() => {
phaserGame = new Phaser.Game({
type: Phaser.HEADLESS,
});
});
afterEach(() => {
game.phaseInterceptor.restoreOg();
});
beforeEach(async () => {
game = new GameManager(phaserGame);
game.settings.typeHints(true); //activate type hints
game.override.battleStyle("single").startingLevel(100).startingWave(1).enemyMoveset(MoveId.SPLASH);
});
it("check immunity color", async () => {
game.override
.battleStyle("single")
.startingLevel(100)
.startingWave(1)
.enemySpecies(SpeciesId.FLORGES)
.enemyMoveset(MoveId.SPLASH)
.moveset([MoveId.DRAGON_CLAW]);
game.settings.typeHints(true); //activate type hints
await game.classicMode.startBattle([SpeciesId.RAYQUAZA]);
game.onNextPrompt("CommandPhase", UiMode.COMMAND, () => {
const { ui } = game.scene;
const handler = ui.getHandler<FightUiHandler>();
handler.processInput(Button.ACTION); // select "Fight"
});
game.onNextPrompt("CommandPhase", UiMode.FIGHT, () => {
const { ui } = game.scene;
const movesContainer = ui.getByName<Phaser.GameObjects.Container>(FightUiHandler.MOVES_CONTAINER_NAME);
const dragonClawText = movesContainer
.getAll<Phaser.GameObjects.Text>()
.find(text => text.text === i18next.t("move:dragonClaw.name"))! as unknown as MockText;
expect.soft(dragonClawText.color).toBe("#929292");
ui.getHandler().processInput(Button.ACTION);
});
await game.phaseInterceptor.to("CommandPhase");
});
it("check status move color", async () => {
game.override.enemySpecies(SpeciesId.FLORGES).moveset([MoveId.GROWL]);
await game.classicMode.startBattle([SpeciesId.RAYQUAZA]);
game.onNextPrompt("CommandPhase", UiMode.COMMAND, () => {
const { ui } = game.scene;
const handler = ui.getHandler<FightUiHandler>();
handler.processInput(Button.ACTION); // select "Fight"
});
game.onNextPrompt("CommandPhase", UiMode.FIGHT, () => {
const { ui } = game.scene;
const movesContainer = ui.getByName<Phaser.GameObjects.Container>(FightUiHandler.MOVES_CONTAINER_NAME);
const growlText = movesContainer
.getAll<Phaser.GameObjects.Text>()
.find(text => text.text === i18next.t("move:growl.name"))! as unknown as MockText;
expect.soft(growlText.color).toBe(undefined);
ui.getHandler().processInput(Button.ACTION);
});
await game.phaseInterceptor.to("CommandPhase");
});
it("should show the proper hint for a move in doubles after one of the enemy pokemon faints", async () => {
game.override
.enemySpecies(SpeciesId.ABRA)
.moveset([MoveId.SPLASH, MoveId.SHADOW_BALL, MoveId.SOAK])
.enemyMoveset([MoveId.SPLASH, MoveId.MEMENTO])
.battleStyle("double");
await game.classicMode.startBattle([SpeciesId.MAGIKARP, SpeciesId.MAGIKARP]);
game.move.select(MoveId.SPLASH);
// Use soak to change type of remaining abra to water
game.move.select(MoveId.SOAK, 1);
await game.move.selectEnemyMove(MoveId.SPLASH);
await game.move.selectEnemyMove(MoveId.MEMENTO);
await game.toNextTurn();
game.onNextPrompt("CommandPhase", UiMode.COMMAND, () => {
const { ui } = game.scene;
const handler = ui.getHandler<FightUiHandler>();
handler.processInput(Button.ACTION); // select "Fight"
});
game.onNextPrompt("CommandPhase", UiMode.FIGHT, () => {
const { ui } = game.scene;
const movesContainer = ui.getByName<Phaser.GameObjects.Container>(FightUiHandler.MOVES_CONTAINER_NAME);
const shadowBallText = movesContainer
.getAll<Phaser.GameObjects.Text>()
.find(text => text.text === i18next.t("move:shadowBall.name"))! as unknown as MockText;
expect.soft(shadowBallText).toBeDefined();
expect.soft(shadowBallText.color).toBe(undefined);
ui.getHandler().processInput(Button.ACTION);
});
await game.phaseInterceptor.to("CommandPhase");
});
});