mirror of
https://github.com/pagefaultgames/pokerogue.git
synced 2025-08-20 06:19:29 +02:00
* [Test] Added `toHaveArenaTagMatcher` + fixed prior matchers * Fixed imports and stuff * Removed accidental test file addition * More improvements and minor fixes * More semantic changes * Shuffled a few funcs around * More fixups to strings * Added `toHavePositionalTag` matcher * Applied reviews and fixed my godawful penmanship * Fix vitest.d.ts * Fix imports in `vitest.d.ts` --------- Co-authored-by: NightKev <34855794+DayKev@users.noreply.github.com> Co-authored-by: Sirz Benjie <142067137+SirzBenjie@users.noreply.github.com>
63 lines
2.2 KiB
TypeScript
63 lines
2.2 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: this.isNot,
|
|
message: () => `Expected to receive a GameManager, but got ${receivedStr(received)}!`,
|
|
};
|
|
}
|
|
|
|
if (!received.scene?.arena) {
|
|
return {
|
|
pass: this.isNot,
|
|
message: () => `Expected GameManager.${received.scene ? "scene.arena" : "scene"} 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 the Arena to NOT have ${expectedStr} active, but it did!`
|
|
: `Expected the 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" });
|
|
}
|