mirror of
https://github.com/pagefaultgames/pokerogue.git
synced 2025-08-11 01:49:29 +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
63 lines
2.1 KiB
TypeScript
63 lines
2.1 KiB
TypeScript
/** biome-ignore-start lint/correctness/noUnusedImports: TSDoc imports */
|
|
import type { GameManager } from "#test/test-utils/game-manager";
|
|
/** biome-ignore-end lint/correctness/noUnusedImports: TSDoc imports */
|
|
|
|
import { TerrainType } from "#app/data/terrain";
|
|
import { getEnumStr } from "#test/test-utils/string-utils";
|
|
import { isGameManagerInstance, receivedStr } from "#test/test-utils/test-utils";
|
|
import type { MatcherState, SyncExpectationResult } from "@vitest/expect";
|
|
|
|
/**
|
|
* Matcher that checks if the {@linkcode TerrainType} is as expected
|
|
* @param received - The object to check. Should be an instance of {@linkcode GameManager}.
|
|
* @param expectedTerrainType - The expected {@linkcode TerrainType}, or {@linkcode TerrainType.NONE} if no terrain should be active
|
|
* @returns Whether the matcher passed
|
|
*/
|
|
export function toHaveTerrain(
|
|
this: MatcherState,
|
|
received: unknown,
|
|
expectedTerrainType: TerrainType,
|
|
): SyncExpectationResult {
|
|
if (!isGameManagerInstance(received)) {
|
|
return {
|
|
pass: false,
|
|
message: () => `Expected GameManager, but got ${receivedStr(received)}!`,
|
|
};
|
|
}
|
|
|
|
if (!received.scene?.arena) {
|
|
return {
|
|
pass: false,
|
|
message: () => `Expected GameManager.${received.scene ? "scene" : "scene.arena"} to be defined!`,
|
|
};
|
|
}
|
|
|
|
const actual = received.scene.arena.getTerrainType();
|
|
const pass = actual === expectedTerrainType;
|
|
const actualStr = toTerrainStr(actual);
|
|
const expectedStr = toTerrainStr(expectedTerrainType);
|
|
|
|
return {
|
|
pass,
|
|
message: () =>
|
|
pass
|
|
? `Expected Arena to NOT have ${expectedStr} active, but it did!`
|
|
: `Expected Arena to have ${expectedStr} active, but got ${actualStr} instead!`,
|
|
expected: expectedTerrainType,
|
|
actual,
|
|
};
|
|
}
|
|
|
|
/**
|
|
* Get a human readable string of the current {@linkcode TerrainType}.
|
|
* @param terrainType - The {@linkcode TerrainType} to transform
|
|
* @returns A human readable string
|
|
*/
|
|
function toTerrainStr(terrainType: TerrainType) {
|
|
if (terrainType === TerrainType.NONE) {
|
|
return "no terrain";
|
|
}
|
|
// "Electric Terrain (=2)"
|
|
return getEnumStr(TerrainType, terrainType, { casing: "Title", suffix: " Terrain" });
|
|
}
|