mirror of
https://github.com/pagefaultgames/pokerogue.git
synced 2025-08-10 17:39:31 +02:00
* Partially ported over pkty matchers (WIP) * Cleaned up some more matchers * Fiexd up matchers * Fixed up remaining matchers * Removed the word "matcher" from the pkty matcher functions If we want them back we can always undo this commit and convert the other custom ones * Added wip spite test * Added `toHaveUsedPP` matcher * Fixed up docs and tests * Fixed spite test * Ran biome * Apply Biome * Reverted biome breaking i18next * Update src/typings/i18next.d.ts comment * Fixed log message to not be overly verbose * Added option to check for all PP used in pp matcher + cleaned up grudge tests * Fixed up tests * Fixed tests and such * Fix various TSDocs + missing TSDoc imports
78 lines
2.7 KiB
TypeScript
78 lines
2.7 KiB
TypeScript
// biome-ignore-start lint/correctness/noUnusedImports: TSDoc imports
|
|
import type { Pokemon } from "#field/pokemon";
|
|
// biome-ignore-end lint/correctness/noUnusedImports: TSDoc imports
|
|
|
|
import { getPokemonNameWithAffix } from "#app/messages";
|
|
import Overrides from "#app/overrides";
|
|
import { MoveId } from "#enums/move-id";
|
|
import { getEnumStr } from "#test/test-utils/string-utils";
|
|
import { isPokemonInstance, receivedStr } from "#test/test-utils/test-utils";
|
|
import { coerceArray } from "#utils/common";
|
|
import type { MatcherState, SyncExpectationResult } from "@vitest/expect";
|
|
|
|
/**
|
|
* Matcher to check the amount of PP consumed by a {@linkcode Pokemon}.
|
|
* @param received - The actual value received. Should be a {@linkcode Pokemon}
|
|
* @param expectedValue - The {@linkcode MoveId} that should have consumed PP
|
|
* @param ppUsed - The numerical amount of PP that should have been consumed,
|
|
* or `all` to indicate the move should be _out_ of PP
|
|
* @returns Whether the matcher passed
|
|
* @remarks
|
|
* If the same move appears in the Pokemon's moveset multiple times, this will fail the test!
|
|
*/
|
|
export function toHaveUsedPP(
|
|
this: MatcherState,
|
|
received: unknown,
|
|
expectedMove: MoveId,
|
|
ppUsed: number | "all",
|
|
): SyncExpectationResult {
|
|
if (!isPokemonInstance(received)) {
|
|
return {
|
|
pass: false,
|
|
message: () => `Expected to receive a Pokémon, but got ${receivedStr(received)}!`,
|
|
};
|
|
}
|
|
|
|
const override = received.isPlayer() ? Overrides.MOVESET_OVERRIDE : Overrides.OPP_MOVESET_OVERRIDE;
|
|
if (coerceArray(override).length > 0) {
|
|
return {
|
|
pass: false,
|
|
message: () =>
|
|
`Cannot test for PP consumption with ${received.isPlayer() ? "player" : "enemy"} moveset overrides active!`,
|
|
};
|
|
}
|
|
|
|
const pkmName = getPokemonNameWithAffix(received);
|
|
const moveStr = getEnumStr(MoveId, expectedMove);
|
|
|
|
const movesetMoves = received.getMoveset().filter(pm => pm.moveId === expectedMove);
|
|
if (movesetMoves.length !== 1) {
|
|
return {
|
|
pass: false,
|
|
message: () =>
|
|
`Expected MoveId.${moveStr} to appear in ${pkmName}'s moveset exactly once, but got ${movesetMoves.length} times!`,
|
|
expected: expectedMove,
|
|
actual: received.getMoveset(),
|
|
};
|
|
}
|
|
|
|
const move = movesetMoves[0]; // will be the only move in the array
|
|
|
|
let ppStr: string = ppUsed.toString();
|
|
if (typeof ppUsed === "string") {
|
|
ppStr = "all its";
|
|
ppUsed = move.getMovePp();
|
|
}
|
|
const pass = move.ppUsed === ppUsed;
|
|
|
|
return {
|
|
pass,
|
|
message: () =>
|
|
pass
|
|
? `Expected ${pkmName}'s ${moveStr} to NOT have used ${ppStr} PP, but it did!`
|
|
: `Expected ${pkmName}'s ${moveStr} to have used ${ppStr} PP, but got ${move.ppUsed} instead!`,
|
|
expected: ppUsed,
|
|
actual: move.ppUsed,
|
|
};
|
|
}
|