[Refactor] unit tests cleanup (#2533)

This commit is contained in:
Adrian T 2024-06-24 00:38:40 +08:00 committed by GitHub
parent 111cfd686d
commit 7f15efcd34
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 59 additions and 52 deletions

View File

@ -15,6 +15,7 @@ import { NumberHolder } from "#app/utils.js";
describe("Abilities - Aura Break", () => {
let phaserGame: Phaser.Game;
let game: GameManager;
const multiplier = 9 / 16;
beforeAll(() => {
phaserGame = new Phaser.Game({
@ -37,7 +38,6 @@ describe("Abilities - Aura Break", () => {
it("reverses the effect of fairy aura", async () => {
vi.spyOn(overrides, "ABILITY_OVERRIDE", "get").mockReturnValue(Abilities.FAIRY_AURA);
const basePower = allMoves[Moves.MOONBLAST].power;
const multiplier = 9 / 16;
await game.startBattle([Species.MAGIKARP]);
game.doAttack(getMovePosition(game.scene, 0, Moves.MOONBLAST));
@ -51,10 +51,10 @@ describe("Abilities - Aura Break", () => {
expect(appliedPower).toBe(basePower * multiplier);
});
it("reverses the effect of dark aura", async () => {
vi.spyOn(overrides, "ABILITY_OVERRIDE", "get").mockReturnValue(Abilities.DARK_AURA);
const basePower = allMoves[Moves.DARK_PULSE].power;
const multiplier = 9 / 16;
await game.startBattle([Species.MAGIKARP]);
game.doAttack(getMovePosition(game.scene, 0, Moves.DARK_PULSE));

View File

@ -41,11 +41,11 @@ describe("Abilities - Battery", () => {
game.doAttack(getMovePosition(game.scene, 1, Moves.SPLASH));
const multiplier = getAttrPowerMultiplier(game.scene.getPlayerField()[1]);
const appliedPower = getAppliedMovePower(game.scene.getEnemyField()[0], game.scene.getPlayerField()[0], allMoves[moveToBeUsed]);
const mockedPower = getMockedMovePower(game.scene.getEnemyField()[0], game.scene.getPlayerField()[0], allMoves[moveToBeUsed]);
expect(appliedPower).not.toBe(undefined);
expect(appliedPower).not.toBe(basePower);
expect(appliedPower).toBe(basePower * multiplier);
expect(mockedPower).not.toBe(undefined);
expect(mockedPower).not.toBe(basePower);
expect(mockedPower).toBe(basePower * multiplier);
});
it("does not raise the power of allies' non-special moves", async () => {
@ -58,11 +58,11 @@ describe("Abilities - Battery", () => {
game.doAttack(getMovePosition(game.scene, 1, Moves.SPLASH));
const multiplier = getAttrPowerMultiplier(game.scene.getPlayerField()[1]);
const appliedPower = getAppliedMovePower(game.scene.getEnemyField()[0], game.scene.getPlayerField()[0], allMoves[moveToBeUsed]);
const mockedPower = getMockedMovePower(game.scene.getEnemyField()[0], game.scene.getPlayerField()[0], allMoves[moveToBeUsed]);
expect(appliedPower).not.toBe(undefined);
expect(appliedPower).toBe(basePower);
expect(appliedPower).not.toBe(basePower * multiplier);
expect(mockedPower).not.toBe(undefined);
expect(mockedPower).toBe(basePower);
expect(mockedPower).not.toBe(basePower * multiplier);
});
it("does not raise the power of the ability owner's special moves", async () => {
@ -75,23 +75,25 @@ describe("Abilities - Battery", () => {
game.doAttack(getMovePosition(game.scene, 1, Moves.SPLASH));
const multiplier = getAttrPowerMultiplier(game.scene.getPlayerField()[0]);
const appliedPower = getAppliedMovePower(game.scene.getEnemyField()[0], game.scene.getPlayerField()[0], allMoves[moveToBeUsed]);
const mockedPower = getMockedMovePower(game.scene.getEnemyField()[0], game.scene.getPlayerField()[0], allMoves[moveToBeUsed]);
expect(appliedPower).not.toBe(undefined);
expect(appliedPower).toBe(basePower);
expect(appliedPower).not.toBe(basePower * multiplier);
expect(mockedPower).not.toBe(undefined);
expect(mockedPower).toBe(basePower);
expect(mockedPower).not.toBe(basePower * multiplier);
});
});
/**
* Calculates the adjusted applied power of a move.
* Calculates the mocked power of a move.
* Note this does not consider other damage calculations
* except the power multiplier from Battery.
*
* @param defender - The defending Pokémon.
* @param attacker - The attacking Pokémon.
* @param move - The move being used by the attacker.
* @returns The adjusted power of the move.
*/
const getAppliedMovePower = (defender: Pokemon, attacker: Pokemon, move: Move) => {
const getMockedMovePower = (defender: Pokemon, attacker: Pokemon, move: Move) => {
const powerHolder = new NumberHolder(move.power);
/**

View File

@ -41,11 +41,11 @@ describe("Abilities - Power Spot", () => {
game.doAttack(getMovePosition(game.scene, 1, Moves.SPLASH));
const multiplier = getAttrPowerMultiplier(game.scene.getPlayerField()[1]);
const appliedPower = getAppliedMovePower(game.scene.getEnemyField()[0], game.scene.getPlayerField()[0], allMoves[moveToBeUsed]);
const mockedPower = getMockedMovePower(game.scene.getEnemyField()[0], game.scene.getPlayerField()[0], allMoves[moveToBeUsed]);
expect(appliedPower).not.toBe(undefined);
expect(appliedPower).not.toBe(basePower);
expect(appliedPower).toBe(basePower * multiplier);
expect(mockedPower).not.toBe(undefined);
expect(mockedPower).not.toBe(basePower);
expect(mockedPower).toBe(basePower * multiplier);
});
it("raises the power of allies' physical moves by 30%", async () => {
@ -58,11 +58,11 @@ describe("Abilities - Power Spot", () => {
game.doAttack(getMovePosition(game.scene, 1, Moves.SPLASH));
const multiplier = getAttrPowerMultiplier(game.scene.getPlayerField()[1]);
const appliedPower = getAppliedMovePower(game.scene.getEnemyField()[0], game.scene.getPlayerField()[0], allMoves[moveToBeUsed]);
const mockedPower = getMockedMovePower(game.scene.getEnemyField()[0], game.scene.getPlayerField()[0], allMoves[moveToBeUsed]);
expect(appliedPower).not.toBe(undefined);
expect(appliedPower).not.toBe(basePower);
expect(appliedPower).toBe(basePower * multiplier);
expect(mockedPower).not.toBe(undefined);
expect(mockedPower).not.toBe(basePower);
expect(mockedPower).toBe(basePower * multiplier);
});
it("does not raise the power of the ability owner's moves", async () => {
@ -75,23 +75,25 @@ describe("Abilities - Power Spot", () => {
game.doAttack(getMovePosition(game.scene, 1, Moves.SPLASH));
const multiplier = getAttrPowerMultiplier(game.scene.getPlayerField()[0]);
const appliedPower = getAppliedMovePower(game.scene.getEnemyField()[0], game.scene.getPlayerField()[0], allMoves[moveToBeUsed]);
const mockedPower = getMockedMovePower(game.scene.getEnemyField()[0], game.scene.getPlayerField()[0], allMoves[moveToBeUsed]);
expect(appliedPower).not.toBe(undefined);
expect(appliedPower).toBe(basePower);
expect(appliedPower).not.toBe(basePower * multiplier);
expect(mockedPower).not.toBe(undefined);
expect(mockedPower).toBe(basePower);
expect(mockedPower).not.toBe(basePower * multiplier);
});
});
/**
* Calculates the adjusted applied power of a move.
* Calculates the mocked power of a move.
* Note this does not consider other damage calculations
* except the power multiplier from Power Spot.
*
* @param defender - The defending Pokémon.
* @param attacker - The attacking Pokémon.
* @param move - The move being used by the attacker.
* @returns The adjusted power of the move.
*/
const getAppliedMovePower = (defender: Pokemon, attacker: Pokemon, move: Move) => {
const getMockedMovePower = (defender: Pokemon, attacker: Pokemon, move: Move) => {
const powerHolder = new NumberHolder(move.power);
/**

View File

@ -39,13 +39,13 @@ describe("Abilities - Wonder Skin", () => {
game.doAttack(getMovePosition(game.scene, 0, Moves.CHARM));
const appliedAccuracy = getAppliedMoveAccuracy(game.scene.getEnemyPokemon(), game.scene.getPlayerPokemon(), allMoves[Moves.CHARM]);
const mockedAccuracy = getMockedMoveAccuracy(game.scene.getEnemyPokemon(), game.scene.getPlayerPokemon(), allMoves[Moves.CHARM]);
await game.phaseInterceptor.to(TurnEndPhase);
expect(appliedAccuracy).not.toBe(undefined);
expect(appliedAccuracy).not.toBe(100);
expect(appliedAccuracy).toBe(50);
expect(mockedAccuracy).not.toBe(undefined);
expect(mockedAccuracy).not.toBe(100);
expect(mockedAccuracy).toBe(50);
});
it("does not lower accuracy of non-status moves", async () => {
@ -53,13 +53,13 @@ describe("Abilities - Wonder Skin", () => {
game.doAttack(getMovePosition(game.scene, 0, Moves.TACKLE));
const appliedAccuracy = getAppliedMoveAccuracy(game.scene.getEnemyPokemon(), game.scene.getPlayerPokemon(), allMoves[Moves.TACKLE]);
const mockedAccuracy = getMockedMoveAccuracy(game.scene.getEnemyPokemon(), game.scene.getPlayerPokemon(), allMoves[Moves.TACKLE]);
await game.phaseInterceptor.to(TurnEndPhase);
expect(appliedAccuracy).not.toBe(undefined);
expect(appliedAccuracy).toBe(100);
expect(appliedAccuracy).not.toBe(50);
expect(mockedAccuracy).not.toBe(undefined);
expect(mockedAccuracy).toBe(100);
expect(mockedAccuracy).not.toBe(50);
});
it("does not affect pokemon with Mold Breaker", async () => {
@ -69,13 +69,13 @@ describe("Abilities - Wonder Skin", () => {
game.doAttack(getMovePosition(game.scene, 0, Moves.CHARM));
const appliedAccuracy = getAppliedMoveAccuracy(game.scene.getEnemyPokemon(), game.scene.getPlayerPokemon(), allMoves[Moves.CHARM]);
const mockedAccuracy = getMockedMoveAccuracy(game.scene.getEnemyPokemon(), game.scene.getPlayerPokemon(), allMoves[Moves.CHARM]);
await game.phaseInterceptor.to(TurnEndPhase);
expect(appliedAccuracy).not.toBe(undefined);
expect(appliedAccuracy).toBe(100);
expect(appliedAccuracy).not.toBe(50);
expect(mockedAccuracy).not.toBe(undefined);
expect(mockedAccuracy).toBe(100);
expect(mockedAccuracy).not.toBe(50);
});
it("does not affect pokemon with Teravolt", async () => {
@ -85,13 +85,13 @@ describe("Abilities - Wonder Skin", () => {
game.doAttack(getMovePosition(game.scene, 0, Moves.CHARM));
const appliedAccuracy = getAppliedMoveAccuracy(game.scene.getEnemyPokemon(), game.scene.getPlayerPokemon(), allMoves[Moves.CHARM]);
const mockedAccuracy = getMockedMoveAccuracy(game.scene.getEnemyPokemon(), game.scene.getPlayerPokemon(), allMoves[Moves.CHARM]);
await game.phaseInterceptor.to(TurnEndPhase);
expect(appliedAccuracy).not.toBe(undefined);
expect(appliedAccuracy).toBe(100);
expect(appliedAccuracy).not.toBe(50);
expect(mockedAccuracy).not.toBe(undefined);
expect(mockedAccuracy).toBe(100);
expect(mockedAccuracy).not.toBe(50);
});
it("does not affect pokemon with Turboblaze", async () => {
@ -101,25 +101,28 @@ describe("Abilities - Wonder Skin", () => {
game.doAttack(getMovePosition(game.scene, 0, Moves.CHARM));
const appliedAccuracy = getAppliedMoveAccuracy(game.scene.getEnemyPokemon(), game.scene.getPlayerPokemon(), allMoves[Moves.CHARM]);
const mockedAccuracy = getMockedMoveAccuracy(game.scene.getEnemyPokemon(), game.scene.getPlayerPokemon(), allMoves[Moves.CHARM]);
await game.phaseInterceptor.to(TurnEndPhase);
expect(appliedAccuracy).not.toBe(undefined);
expect(appliedAccuracy).toBe(100);
expect(appliedAccuracy).not.toBe(50);
expect(mockedAccuracy).not.toBe(undefined);
expect(mockedAccuracy).toBe(100);
expect(mockedAccuracy).not.toBe(50);
});
});
/**
* Calculates the adjusted applied accuracy of a move.
* Calculates the mocked accuracy of a move.
* Note this does not consider other accuracy calculations
* except the power multiplier from Wonder Skin.
* Bypassed by MoveAbilityBypassAbAttr {@linkcode MoveAbilityBypassAbAttr}
*
* @param defender - The defending Pokémon.
* @param attacker - The attacking Pokémon.
* @param move - The move being used by the attacker.
* @returns The adjusted accuracy of the move.
*/
const getAppliedMoveAccuracy = (defender: Pokemon, attacker: Pokemon, move: Move) => {
const getMockedMoveAccuracy = (defender: Pokemon, attacker: Pokemon, move: Move) => {
const accuracyHolder = new NumberHolder(move.accuracy);
/**