[Qol] Load i18n en locales during tests (#4553)
* add: i18n backend support the backend is being supported by using msw which will import the correct file from the local locales folder * fix: tests to no longer rely on static i18n keys * Update src/test/mystery-encounter/encounters/teleporting-hijinks-encounter.test.ts Co-authored-by: NightKev <34855794+DayKev@users.noreply.github.com> * Update src/test/mystery-encounter/encounters/teleporting-hijinks-encounter.test.ts Co-authored-by: NightKev <34855794+DayKev@users.noreply.github.com> * Update src/test/ui/type-hints.test.ts Co-authored-by: NightKev <34855794+DayKev@users.noreply.github.com> * Update src/test/mystery-encounter/encounters/a-trainers-test-encounter.test.ts Co-authored-by: MokaStitcher <54149968+MokaStitcher@users.noreply.github.com> * Fix typos Co-authored-by: Adrian T. <68144167+torranx@users.noreply.github.com> * Fix linting * update locales submodule update reference to `56eeb809eb5a2de40cfc5bc6128a78bef14deea9` (from `3ccef8472dd7cc7c362538489954cb8fdad27e5f`) --------- Co-authored-by: NightKev <34855794+DayKev@users.noreply.github.com> Co-authored-by: MokaStitcher <54149968+MokaStitcher@users.noreply.github.com> Co-authored-by: Adrian T. <68144167+torranx@users.noreply.github.com>
This commit is contained in:
parent
ffe941d235
commit
f180b6070e
|
@ -0,0 +1,14 @@
|
|||
import type { SetupServerApi } from "msw/node";
|
||||
|
||||
export {};
|
||||
|
||||
declare global {
|
||||
/**
|
||||
* Only used in testing.
|
||||
* Can technically be undefined/null but for ease of use we are going to assume it is always defined.
|
||||
* Used to load i18n files exclusively.
|
||||
*
|
||||
* To set up your own server in a test see `game_data.test.ts`
|
||||
*/
|
||||
var i18nServer: SetupServerApi;
|
||||
}
|
|
@ -1,13 +1,13 @@
|
|||
import { BattleStyle } from "#app/enums/battle-style";
|
||||
import { CommandPhase } from "#app/phases/command-phase";
|
||||
import { TurnInitPhase } from "#app/phases/turn-init-phase";
|
||||
import i18next, { initI18n } from "#app/plugins/i18n";
|
||||
import i18next from "#app/plugins/i18n";
|
||||
import { Mode } from "#app/ui/ui";
|
||||
import { Abilities } from "#enums/abilities";
|
||||
import { Species } from "#enums/species";
|
||||
import GameManager from "#test/utils/gameManager";
|
||||
import Phaser from "phaser";
|
||||
import { afterEach, beforeAll, beforeEach, describe, expect, it } from "vitest";
|
||||
import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
|
||||
describe("Ability Timing", () => {
|
||||
|
@ -32,11 +32,10 @@ describe("Ability Timing", () => {
|
|||
.enemySpecies(Species.MAGIKARP)
|
||||
.enemyAbility(Abilities.INTIMIDATE)
|
||||
.ability(Abilities.BALL_FETCH);
|
||||
vi.spyOn(i18next, "t");
|
||||
});
|
||||
|
||||
it("should trigger after switch check", async () => {
|
||||
initI18n();
|
||||
i18next.changeLanguage("en");
|
||||
game.settings.battleStyle = BattleStyle.SWITCH;
|
||||
await game.classicMode.runToSummon([ Species.EEVEE, Species.FEEBAS ]);
|
||||
|
||||
|
@ -46,7 +45,6 @@ describe("Ability Timing", () => {
|
|||
}, () => game.isCurrentPhase(CommandPhase) || game.isCurrentPhase(TurnInitPhase));
|
||||
|
||||
await game.phaseInterceptor.to("MessagePhase");
|
||||
const message = game.textInterceptor.getLatestMessage();
|
||||
expect(message).toContain("battle:statFell");
|
||||
expect(i18next.t).toHaveBeenCalledWith("battle:statFell", expect.objectContaining({ count: 1 }));
|
||||
}, 5000);
|
||||
});
|
||||
|
|
|
@ -2,13 +2,13 @@ import { StatusEffect } from "#app/data/status-effect";
|
|||
import { EnemyCommandPhase } from "#app/phases/enemy-command-phase";
|
||||
import { MessagePhase } from "#app/phases/message-phase";
|
||||
import { TurnEndPhase } from "#app/phases/turn-end-phase";
|
||||
import i18next, { initI18n } from "#app/plugins/i18n";
|
||||
import i18next from "#app/plugins/i18n";
|
||||
import { Abilities } from "#enums/abilities";
|
||||
import { Moves } from "#enums/moves";
|
||||
import { Species } from "#enums/species";
|
||||
import GameManager from "#test/utils/gameManager";
|
||||
import Phaser from "phaser";
|
||||
import { afterEach, beforeAll, beforeEach, describe, expect, it } from "vitest";
|
||||
import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
|
||||
describe("Items - Toxic orb", () => {
|
||||
|
@ -39,11 +39,11 @@ describe("Items - Toxic orb", () => {
|
|||
game.override.startingHeldItems([{
|
||||
name: "TOXIC_ORB",
|
||||
}]);
|
||||
|
||||
vi.spyOn(i18next, "t");
|
||||
});
|
||||
|
||||
it("TOXIC ORB", async () => {
|
||||
initI18n();
|
||||
i18next.changeLanguage("en");
|
||||
const moveToUse = Moves.GROWTH;
|
||||
await game.startBattle([
|
||||
Species.MIGHTYENA,
|
||||
|
@ -57,11 +57,10 @@ describe("Items - Toxic orb", () => {
|
|||
await game.phaseInterceptor.runFrom(EnemyCommandPhase).to(TurnEndPhase);
|
||||
// Toxic orb should trigger here
|
||||
await game.phaseInterceptor.run(MessagePhase);
|
||||
const message = game.textInterceptor.getLatestMessage();
|
||||
expect(message).toContain("statusEffect:toxic.obtainSource");
|
||||
expect(i18next.t).toHaveBeenCalledWith("statusEffect:toxic.obtainSource", expect.anything());
|
||||
|
||||
await game.phaseInterceptor.run(MessagePhase);
|
||||
const message2 = game.textInterceptor.getLatestMessage();
|
||||
expect(message2).toBe("statusEffect:toxic.activation");
|
||||
expect(i18next.t).toHaveBeenCalledWith("statusEffect:toxic.activation", expect.anything());
|
||||
expect(game.scene.getParty()[0].status!.effect).toBe(StatusEffect.TOXIC);
|
||||
}, 20000);
|
||||
});
|
||||
|
|
|
@ -16,6 +16,7 @@ import { EggTier } from "#enums/egg-type";
|
|||
import { CommandPhase } from "#app/phases/command-phase";
|
||||
import { SelectModifierPhase } from "#app/phases/select-modifier-phase";
|
||||
import { PartyHealPhase } from "#app/phases/party-heal-phase";
|
||||
import i18next from "i18next";
|
||||
|
||||
const namespace = "mysteryEncounters/aTrainersTest";
|
||||
const defaultParty = [ Species.LAPRAS, Species.GENGAR, Species.ABRA ];
|
||||
|
@ -106,7 +107,8 @@ describe("A Trainer's Test - Mystery Encounter", () => {
|
|||
expect(scene.getCurrentPhase()?.constructor.name).toBe(CommandPhase.name);
|
||||
expect(enemyField.length).toBe(1);
|
||||
expect(scene.currentBattle.trainer).toBeDefined();
|
||||
expect([ "trainerNames:buck", "trainerNames:cheryl", "trainerNames:marley", "trainerNames:mira", "trainerNames:riley" ].includes(scene.currentBattle.trainer!.config.name)).toBeTruthy();
|
||||
expect([ i18next.t("trainerNames:buck"), i18next.t("trainerNames:cheryl"), i18next.t("trainerNames:marley"), i18next.t("trainerNames:mira"), i18next.t("trainerNames:riley") ]
|
||||
.map(name => name.toLowerCase()).includes(scene.currentBattle.trainer!.config.name)).toBeTruthy();
|
||||
expect(enemyField[0]).toBeDefined();
|
||||
});
|
||||
|
||||
|
|
|
@ -16,6 +16,7 @@ import { Moves } from "#enums/moves";
|
|||
import { CommandPhase } from "#app/phases/command-phase";
|
||||
import { MovePhase } from "#app/phases/move-phase";
|
||||
import { SelectModifierPhase } from "#app/phases/select-modifier-phase";
|
||||
import i18next from "i18next";
|
||||
|
||||
const namespace = "mysteryEncounters/absoluteAvarice";
|
||||
const defaultParty = [ Species.LAPRAS, Species.GENGAR, Species.ABRA ];
|
||||
|
@ -146,7 +147,7 @@ describe("Absolute Avarice - Mystery Encounter", () => {
|
|||
const pokemonId = partyPokemon.id;
|
||||
const pokemonItems = scene.findModifiers(m => m instanceof PokemonHeldItemModifier
|
||||
&& (m as PokemonHeldItemModifier).pokemonId === pokemonId, true) as PokemonHeldItemModifier[];
|
||||
const revSeed = pokemonItems.find(i => i.type.name === "modifierType:ModifierType.REVIVER_SEED.name");
|
||||
const revSeed = pokemonItems.find(i => i.type.name === i18next.t("modifierType:ModifierType.REVIVER_SEED.name"));
|
||||
expect(revSeed).toBeDefined;
|
||||
expect(revSeed?.stackCount).toBe(1);
|
||||
}
|
||||
|
|
|
@ -17,6 +17,7 @@ import { getPokemonSpecies } from "#app/data/pokemon-species";
|
|||
import { Moves } from "#enums/moves";
|
||||
import { ShinyRateBoosterModifier } from "#app/modifier/modifier";
|
||||
import { SelectModifierPhase } from "#app/phases/select-modifier-phase";
|
||||
import i18next from "i18next";
|
||||
|
||||
const namespace = "mysteryEncounters/anOfferYouCantRefuse";
|
||||
/** Gyarados for Indimidate */
|
||||
|
@ -93,8 +94,8 @@ describe("An Offer You Can't Refuse - Mystery Encounter", () => {
|
|||
|
||||
expect(AnOfferYouCantRefuseEncounter.dialogueTokens?.strongestPokemon).toBeDefined();
|
||||
expect(AnOfferYouCantRefuseEncounter.dialogueTokens?.price).toBeDefined();
|
||||
expect(AnOfferYouCantRefuseEncounter.dialogueTokens?.option2PrimaryAbility).toBe("ability:intimidate.name");
|
||||
expect(AnOfferYouCantRefuseEncounter.dialogueTokens?.moveOrAbility).toBe("ability:intimidate.name");
|
||||
expect(AnOfferYouCantRefuseEncounter.dialogueTokens?.option2PrimaryAbility).toBe(i18next.t("ability:intimidate.name"));
|
||||
expect(AnOfferYouCantRefuseEncounter.dialogueTokens?.moveOrAbility).toBe(i18next.t("ability:intimidate.name"));
|
||||
expect(AnOfferYouCantRefuseEncounter.misc.pokemon instanceof PlayerPokemon).toBeTruthy();
|
||||
expect(AnOfferYouCantRefuseEncounter.misc?.price?.toString()).toBe(AnOfferYouCantRefuseEncounter.dialogueTokens?.price);
|
||||
expect(onInitResult).toBe(true);
|
||||
|
|
|
@ -103,11 +103,11 @@ describe("Field Trip - Mystery Encounter", () => {
|
|||
expect(scene.ui.getMode()).to.equal(Mode.MODIFIER_SELECT);
|
||||
const modifierSelectHandler = scene.ui.handlers.find(h => h instanceof ModifierSelectUiHandler) as ModifierSelectUiHandler;
|
||||
expect(modifierSelectHandler.options.length).toEqual(5);
|
||||
expect(modifierSelectHandler.options[0].modifierTypeOption.type.name).toBe("modifierType:TempStatStageBoosterItem.x_attack");
|
||||
expect(modifierSelectHandler.options[1].modifierTypeOption.type.name).toBe("modifierType:TempStatStageBoosterItem.x_defense");
|
||||
expect(modifierSelectHandler.options[2].modifierTypeOption.type.name).toBe("modifierType:TempStatStageBoosterItem.x_speed");
|
||||
expect(modifierSelectHandler.options[3].modifierTypeOption.type.name).toBe("modifierType:ModifierType.DIRE_HIT.name");
|
||||
expect(modifierSelectHandler.options[4].modifierTypeOption.type.name).toBe("modifierType:ModifierType.RARER_CANDY.name");
|
||||
expect(modifierSelectHandler.options[0].modifierTypeOption.type.name).toBe(i18next.t("modifierType:TempStatStageBoosterItem.x_attack"));
|
||||
expect(modifierSelectHandler.options[1].modifierTypeOption.type.name).toBe(i18next.t("modifierType:TempStatStageBoosterItem.x_defense"));
|
||||
expect(modifierSelectHandler.options[2].modifierTypeOption.type.name).toBe(i18next.t("modifierType:TempStatStageBoosterItem.x_speed"));
|
||||
expect(modifierSelectHandler.options[3].modifierTypeOption.type.name).toBe(i18next.t("modifierType:ModifierType.DIRE_HIT.name"));
|
||||
expect(modifierSelectHandler.options[4].modifierTypeOption.type.name).toBe(i18next.t("modifierType:ModifierType.RARER_CANDY.name"));
|
||||
});
|
||||
|
||||
it("should leave encounter without battle", async () => {
|
||||
|
@ -150,11 +150,11 @@ describe("Field Trip - Mystery Encounter", () => {
|
|||
expect(scene.ui.getMode()).to.equal(Mode.MODIFIER_SELECT);
|
||||
const modifierSelectHandler = scene.ui.handlers.find(h => h instanceof ModifierSelectUiHandler) as ModifierSelectUiHandler;
|
||||
expect(modifierSelectHandler.options.length).toEqual(5);
|
||||
expect(modifierSelectHandler.options[0].modifierTypeOption.type.name).toBe("modifierType:TempStatStageBoosterItem.x_sp_atk");
|
||||
expect(modifierSelectHandler.options[1].modifierTypeOption.type.name).toBe("modifierType:TempStatStageBoosterItem.x_sp_def");
|
||||
expect(modifierSelectHandler.options[2].modifierTypeOption.type.name).toBe("modifierType:TempStatStageBoosterItem.x_speed");
|
||||
expect(modifierSelectHandler.options[3].modifierTypeOption.type.name).toBe("modifierType:ModifierType.DIRE_HIT.name");
|
||||
expect(modifierSelectHandler.options[4].modifierTypeOption.type.name).toBe("modifierType:ModifierType.RARER_CANDY.name");
|
||||
expect(modifierSelectHandler.options[0].modifierTypeOption.type.name).toBe(i18next.t("modifierType:TempStatStageBoosterItem.x_sp_atk"));
|
||||
expect(modifierSelectHandler.options[1].modifierTypeOption.type.name).toBe(i18next.t("modifierType:TempStatStageBoosterItem.x_sp_def"));
|
||||
expect(modifierSelectHandler.options[2].modifierTypeOption.type.name).toBe(i18next.t("modifierType:TempStatStageBoosterItem.x_speed"));
|
||||
expect(modifierSelectHandler.options[3].modifierTypeOption.type.name).toBe(i18next.t("modifierType:ModifierType.DIRE_HIT.name"));
|
||||
expect(modifierSelectHandler.options[4].modifierTypeOption.type.name).toBe(i18next.t("modifierType:ModifierType.RARER_CANDY.name"));
|
||||
});
|
||||
|
||||
it("should leave encounter without battle", async () => {
|
||||
|
@ -198,12 +198,12 @@ describe("Field Trip - Mystery Encounter", () => {
|
|||
expect(scene.ui.getMode()).to.equal(Mode.MODIFIER_SELECT);
|
||||
const modifierSelectHandler = scene.ui.handlers.find(h => h instanceof ModifierSelectUiHandler) as ModifierSelectUiHandler;
|
||||
expect(modifierSelectHandler.options.length).toEqual(5);
|
||||
expect(modifierSelectHandler.options[0].modifierTypeOption.type.name).toBe("modifierType:TempStatStageBoosterItem.x_accuracy");
|
||||
expect(modifierSelectHandler.options[1].modifierTypeOption.type.name).toBe("modifierType:TempStatStageBoosterItem.x_speed");
|
||||
expect(modifierSelectHandler.options[2].modifierTypeOption.type.name).toBe("modifierType:ModifierType.AddPokeballModifierType.name");
|
||||
expect(i18next.t).toHaveBeenCalledWith("modifierType:ModifierType.AddPokeballModifierType.name", expect.objectContaining({ modifierCount: 5 }));
|
||||
expect(modifierSelectHandler.options[3].modifierTypeOption.type.name).toBe("modifierType:ModifierType.IV_SCANNER.name");
|
||||
expect(modifierSelectHandler.options[4].modifierTypeOption.type.name).toBe("modifierType:ModifierType.RARER_CANDY.name");
|
||||
expect(modifierSelectHandler.options[0].modifierTypeOption.type.name).toBe(i18next.t("modifierType:TempStatStageBoosterItem.x_accuracy"));
|
||||
expect(modifierSelectHandler.options[1].modifierTypeOption.type.name).toBe(i18next.t("modifierType:TempStatStageBoosterItem.x_speed"));
|
||||
expect(modifierSelectHandler.options[2].modifierTypeOption.type.name).toBe(i18next.t("modifierType:ModifierType.AddPokeballModifierType.name", { modifierCount: 5, pokeballName: i18next.t("pokeball:greatBall") }));
|
||||
expect(i18next.t).toHaveBeenCalledWith(("modifierType:ModifierType.AddPokeballModifierType.name"), expect.objectContaining({ modifierCount: 5 }));
|
||||
expect(modifierSelectHandler.options[3].modifierTypeOption.type.name).toBe(i18next.t("modifierType:ModifierType.IV_SCANNER.name"));
|
||||
expect(modifierSelectHandler.options[4].modifierTypeOption.type.name).toBe(i18next.t("modifierType:ModifierType.RARER_CANDY.name"));
|
||||
});
|
||||
|
||||
it("should leave encounter without battle", async () => {
|
||||
|
|
|
@ -22,6 +22,7 @@ import { initSceneWithoutEncounterPhase } from "#test/utils/gameManagerUtils";
|
|||
import { CommandPhase } from "#app/phases/command-phase";
|
||||
import { MovePhase } from "#app/phases/move-phase";
|
||||
import { SelectModifierPhase } from "#app/phases/select-modifier-phase";
|
||||
import i18next from "i18next";
|
||||
|
||||
const namespace = "mysteryEncounters/fieryFallout";
|
||||
/** Arcanine and Ninetails for 2 Fire types. Lapras, Gengar, Abra for burnable mon. */
|
||||
|
@ -205,7 +206,7 @@ describe("Fiery Fallout - Mystery Encounter", () => {
|
|||
|
||||
const burnablePokemon = party.filter((pkm) => pkm.isAllowedInBattle() && !pkm.getTypes().includes(Type.FIRE));
|
||||
const notBurnablePokemon = party.filter((pkm) => !pkm.isAllowedInBattle() || pkm.getTypes().includes(Type.FIRE));
|
||||
expect(scene.currentBattle.mysteryEncounter?.dialogueTokens["burnedPokemon"]).toBe("pokemon:gengar");
|
||||
expect(scene.currentBattle.mysteryEncounter?.dialogueTokens["burnedPokemon"]).toBe(i18next.t("pokemon:gengar"));
|
||||
burnablePokemon.forEach((pkm) => {
|
||||
expect(pkm.hp, `${pkm.name} should have received 20% damage: ${pkm.hp} / ${pkm.getMaxHp()} HP`).toBe(pkm.getMaxHp() - Math.floor(pkm.getMaxHp() * 0.2));
|
||||
});
|
||||
|
|
|
@ -14,6 +14,7 @@ import { initSceneWithoutEncounterPhase } from "#test/utils/gameManagerUtils";
|
|||
import BattleScene from "#app/battle-scene";
|
||||
import { MysteryEncounterPhase } from "#app/phases/mystery-encounter-phases";
|
||||
import { PartyExpPhase } from "#app/phases/party-exp-phase";
|
||||
import i18next from "i18next";
|
||||
|
||||
|
||||
const namespace = "mysteryEncounters/lostAtSea";
|
||||
|
@ -86,8 +87,8 @@ describe("Lost at Sea - Mystery Encounter", () => {
|
|||
const onInitResult = onInit!(scene);
|
||||
|
||||
expect(LostAtSeaEncounter.dialogueTokens?.damagePercentage).toBe("25");
|
||||
expect(LostAtSeaEncounter.dialogueTokens?.option1RequiredMove).toBe("move:surf.name");
|
||||
expect(LostAtSeaEncounter.dialogueTokens?.option2RequiredMove).toBe("move:fly.name");
|
||||
expect(LostAtSeaEncounter.dialogueTokens?.option1RequiredMove).toBe(i18next.t("move:surf.name"));
|
||||
expect(LostAtSeaEncounter.dialogueTokens?.option2RequiredMove).toBe(i18next.t("move:fly.name"));
|
||||
expect(onInitResult).toBe(true);
|
||||
});
|
||||
|
||||
|
|
|
@ -1,21 +1,22 @@
|
|||
import * as MysteryEncounters from "#app/data/mystery-encounters/mystery-encounters";
|
||||
import { Biome } from "#app/enums/biome";
|
||||
import { MysteryEncounterType } from "#app/enums/mystery-encounter-type";
|
||||
import { Species } from "#app/enums/species";
|
||||
import GameManager from "#app/test/utils/gameManager";
|
||||
import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { runMysteryEncounterToEnd, runSelectMysteryEncounterOption, skipBattleRunMysteryEncounterRewardsPhase } from "#test/mystery-encounter/encounter-test-utils";
|
||||
import BattleScene from "#app/battle-scene";
|
||||
import { TeleportingHijinksEncounter } from "#app/data/mystery-encounters/encounters/teleporting-hijinks-encounter";
|
||||
import * as MysteryEncounters from "#app/data/mystery-encounters/mystery-encounters";
|
||||
import { Abilities } from "#enums/abilities";
|
||||
import { Biome } from "#enums/biome";
|
||||
import { MysteryEncounterType } from "#enums/mystery-encounter-type";
|
||||
import { Species } from "#enums/species";
|
||||
import { CommandPhase } from "#app/phases/command-phase";
|
||||
import { MysteryEncounterPhase } from "#app/phases/mystery-encounter-phases";
|
||||
import { SelectModifierPhase } from "#app/phases/select-modifier-phase";
|
||||
import GameManager from "#test/utils/gameManager";
|
||||
import ModifierSelectUiHandler from "#app/ui/modifier-select-ui-handler";
|
||||
import { Mode } from "#app/ui/ui";
|
||||
import { MysteryEncounterOptionMode } from "#enums/mystery-encounter-option-mode";
|
||||
import { MysteryEncounterTier } from "#enums/mystery-encounter-tier";
|
||||
import { runMysteryEncounterToEnd, runSelectMysteryEncounterOption, skipBattleRunMysteryEncounterRewardsPhase } from "#test/mystery-encounter/encounter-test-utils";
|
||||
import { initSceneWithoutEncounterPhase } from "#test/utils/gameManagerUtils";
|
||||
import { MysteryEncounterPhase } from "#app/phases/mystery-encounter-phases";
|
||||
import { CommandPhase } from "#app/phases/command-phase";
|
||||
import { TeleportingHijinksEncounter } from "#app/data/mystery-encounters/encounters/teleporting-hijinks-encounter";
|
||||
import { SelectModifierPhase } from "#app/phases/select-modifier-phase";
|
||||
import { Mode } from "#app/ui/ui";
|
||||
import ModifierSelectUiHandler from "#app/ui/modifier-select-ui-handler";
|
||||
import { Abilities } from "#app/enums/abilities";
|
||||
import i18next from "i18next";
|
||||
import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
const namespace = "mysteryEncounters/teleportingHijinks";
|
||||
const defaultParty = [ Species.LAPRAS, Species.GENGAR, Species.ABRA ];
|
||||
|
@ -300,8 +301,8 @@ describe("Teleporting Hijinks - Mystery Encounter", () => {
|
|||
|
||||
expect(scene.ui.getMode()).to.equal(Mode.MODIFIER_SELECT);
|
||||
const modifierSelectHandler = scene.ui.handlers.find(h => h instanceof ModifierSelectUiHandler) as ModifierSelectUiHandler;
|
||||
expect(modifierSelectHandler.options.some(opt => opt.modifierTypeOption.type.name === "modifierType:AttackTypeBoosterItem.metal_coat")).toBe(true);
|
||||
expect(modifierSelectHandler.options.some(opt => opt.modifierTypeOption.type.name === "modifierType:AttackTypeBoosterItem.magnet")).toBe(true);
|
||||
expect(modifierSelectHandler.options.some(opt => opt.modifierTypeOption.type.name === i18next.t("modifierType:AttackTypeBoosterItem.metal_coat"))).toBe(true);
|
||||
expect(modifierSelectHandler.options.some(opt => opt.modifierTypeOption.type.name === i18next.t("modifierType:AttackTypeBoosterItem.magnet"))).toBe(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -9,6 +9,7 @@ import MysteryEncounterUiHandler from "#app/ui/mystery-encounter-ui-handler";
|
|||
import { MysteryEncounterType } from "#enums/mystery-encounter-type";
|
||||
import MessageUiHandler from "#app/ui/message-ui-handler";
|
||||
import { MysteryEncounterTier } from "#enums/mystery-encounter-tier";
|
||||
import i18next from "i18next";
|
||||
|
||||
describe("Mystery Encounter Phases", () => {
|
||||
let phaserGame: Phaser.Game;
|
||||
|
@ -78,9 +79,9 @@ describe("Mystery Encounter Phases", () => {
|
|||
expect(ui.getMode()).toBe(Mode.MESSAGE);
|
||||
expect(ui.showDialogue).toHaveBeenCalledTimes(1);
|
||||
expect(ui.showText).toHaveBeenCalledTimes(2);
|
||||
expect(ui.showDialogue).toHaveBeenCalledWith("battle:mysteryEncounterAppeared", "???", null, expect.any(Function));
|
||||
expect(ui.showText).toHaveBeenCalledWith("mysteryEncounters/mysteriousChallengers:intro", null, expect.any(Function), 750, true);
|
||||
expect(ui.showText).toHaveBeenCalledWith("mysteryEncounters/mysteriousChallengers:option.selected", null, expect.any(Function), 300, true);
|
||||
expect(ui.showDialogue).toHaveBeenCalledWith(i18next.t("battle:mysteryEncounterAppeared"), "???", null, expect.any(Function));
|
||||
expect(ui.showText).toHaveBeenCalledWith(i18next.t("mysteryEncounters/mysteriousChallengers:intro"), null, expect.any(Function), 750, true);
|
||||
expect(ui.showText).toHaveBeenCalledWith(i18next.t("mysteryEncounters/mysteriousChallengers:option.selected"), null, expect.any(Function), 300, true);
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
@ -11,13 +11,15 @@ import * as account from "../../account";
|
|||
|
||||
const apiBase = import.meta.env.VITE_API_BASE_URL ?? "http://localhost:8001";
|
||||
|
||||
export const server = setupServer();
|
||||
/** We need a custom server. For some reasons I can't extend the listeners of {@linkcode global.i18nServer} with {@linkcode global.i18nServer.use} */
|
||||
const server = setupServer();
|
||||
|
||||
describe("System - Game Data", () => {
|
||||
let phaserGame: Phaser.Game;
|
||||
let game: GameManager;
|
||||
|
||||
beforeAll(() => {
|
||||
global.i18nServer.close();
|
||||
server.listen();
|
||||
phaserGame = new Phaser.Game({
|
||||
type: Phaser.HEADLESS,
|
||||
|
@ -26,6 +28,7 @@ describe("System - Game Data", () => {
|
|||
|
||||
afterAll(() => {
|
||||
server.close();
|
||||
global.i18nServer.listen();
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
|
|
|
@ -14,6 +14,7 @@ import { Abilities } from "#enums/abilities";
|
|||
import { Button } from "#enums/buttons";
|
||||
import { Species } from "#enums/species";
|
||||
import GameManager from "#test/utils/gameManager";
|
||||
import i18next from "i18next";
|
||||
import Phaser from "phaser";
|
||||
import { afterEach, beforeAll, beforeEach, describe, expect, it } from "vitest";
|
||||
|
||||
|
@ -66,11 +67,11 @@ describe("UI - Starter select", () => {
|
|||
resolve();
|
||||
});
|
||||
});
|
||||
expect(options.some(option => option.label === "starterSelectUiHandler:addToParty")).toBe(true);
|
||||
expect(options.some(option => option.label === "starterSelectUiHandler:toggleIVs")).toBe(true);
|
||||
expect(options.some(option => option.label === "starterSelectUiHandler:manageMoves")).toBe(true);
|
||||
expect(options.some(option => option.label === "starterSelectUiHandler:useCandies")).toBe(true);
|
||||
expect(options.some(option => option.label === "menu:cancel")).toBe(true);
|
||||
expect(options.some(option => option.label === i18next.t("starterSelectUiHandler:addToParty"))).toBe(true);
|
||||
expect(options.some(option => option.label === i18next.t("starterSelectUiHandler:toggleIVs"))).toBe(true);
|
||||
expect(options.some(option => option.label === i18next.t("starterSelectUiHandler:manageMoves"))).toBe(true);
|
||||
expect(options.some(option => option.label === i18next.t("starterSelectUiHandler:useCandies"))).toBe(true);
|
||||
expect(options.some(option => option.label === i18next.t("menu:cancel"))).toBe(true);
|
||||
optionSelectUiHandler?.processInput(Button.ACTION);
|
||||
|
||||
await new Promise<void>((resolve) => {
|
||||
|
@ -127,11 +128,11 @@ describe("UI - Starter select", () => {
|
|||
resolve();
|
||||
});
|
||||
});
|
||||
expect(options.some(option => option.label === "starterSelectUiHandler:addToParty")).toBe(true);
|
||||
expect(options.some(option => option.label === "starterSelectUiHandler:toggleIVs")).toBe(true);
|
||||
expect(options.some(option => option.label === "starterSelectUiHandler:manageMoves")).toBe(true);
|
||||
expect(options.some(option => option.label === "starterSelectUiHandler:useCandies")).toBe(true);
|
||||
expect(options.some(option => option.label === "menu:cancel")).toBe(true);
|
||||
expect(options.some(option => option.label === i18next.t("starterSelectUiHandler:addToParty"))).toBe(true);
|
||||
expect(options.some(option => option.label === i18next.t("starterSelectUiHandler:toggleIVs"))).toBe(true);
|
||||
expect(options.some(option => option.label === i18next.t("starterSelectUiHandler:manageMoves"))).toBe(true);
|
||||
expect(options.some(option => option.label === i18next.t("starterSelectUiHandler:useCandies"))).toBe(true);
|
||||
expect(options.some(option => option.label === i18next.t("menu:cancel"))).toBe(true);
|
||||
optionSelectUiHandler?.processInput(Button.ACTION);
|
||||
|
||||
await new Promise<void>((resolve) => {
|
||||
|
@ -191,11 +192,11 @@ describe("UI - Starter select", () => {
|
|||
resolve();
|
||||
});
|
||||
});
|
||||
expect(options.some(option => option.label === "starterSelectUiHandler:addToParty")).toBe(true);
|
||||
expect(options.some(option => option.label === "starterSelectUiHandler:toggleIVs")).toBe(true);
|
||||
expect(options.some(option => option.label === "starterSelectUiHandler:manageMoves")).toBe(true);
|
||||
expect(options.some(option => option.label === "starterSelectUiHandler:useCandies")).toBe(true);
|
||||
expect(options.some(option => option.label === "menu:cancel")).toBe(true);
|
||||
expect(options.some(option => option.label === i18next.t("starterSelectUiHandler:addToParty"))).toBe(true);
|
||||
expect(options.some(option => option.label === i18next.t("starterSelectUiHandler:toggleIVs"))).toBe(true);
|
||||
expect(options.some(option => option.label === i18next.t("starterSelectUiHandler:manageMoves"))).toBe(true);
|
||||
expect(options.some(option => option.label === i18next.t("starterSelectUiHandler:useCandies"))).toBe(true);
|
||||
expect(options.some(option => option.label === i18next.t("menu:cancel"))).toBe(true);
|
||||
optionSelectUiHandler?.processInput(Button.ACTION);
|
||||
|
||||
await new Promise<void>((resolve) => {
|
||||
|
@ -254,11 +255,11 @@ describe("UI - Starter select", () => {
|
|||
resolve();
|
||||
});
|
||||
});
|
||||
expect(options.some(option => option.label === "starterSelectUiHandler:addToParty")).toBe(true);
|
||||
expect(options.some(option => option.label === "starterSelectUiHandler:toggleIVs")).toBe(true);
|
||||
expect(options.some(option => option.label === "starterSelectUiHandler:manageMoves")).toBe(true);
|
||||
expect(options.some(option => option.label === "starterSelectUiHandler:useCandies")).toBe(true);
|
||||
expect(options.some(option => option.label === "menu:cancel")).toBe(true);
|
||||
expect(options.some(option => option.label === i18next.t("starterSelectUiHandler:addToParty"))).toBe(true);
|
||||
expect(options.some(option => option.label === i18next.t("starterSelectUiHandler:toggleIVs"))).toBe(true);
|
||||
expect(options.some(option => option.label === i18next.t("starterSelectUiHandler:manageMoves"))).toBe(true);
|
||||
expect(options.some(option => option.label === i18next.t("starterSelectUiHandler:useCandies"))).toBe(true);
|
||||
expect(options.some(option => option.label === i18next.t("menu:cancel"))).toBe(true);
|
||||
optionSelectUiHandler?.processInput(Button.ACTION);
|
||||
|
||||
await new Promise<void>((resolve) => {
|
||||
|
@ -315,11 +316,11 @@ describe("UI - Starter select", () => {
|
|||
resolve();
|
||||
});
|
||||
});
|
||||
expect(options.some(option => option.label === "starterSelectUiHandler:addToParty")).toBe(true);
|
||||
expect(options.some(option => option.label === "starterSelectUiHandler:toggleIVs")).toBe(true);
|
||||
expect(options.some(option => option.label === "starterSelectUiHandler:manageMoves")).toBe(true);
|
||||
expect(options.some(option => option.label === "starterSelectUiHandler:useCandies")).toBe(true);
|
||||
expect(options.some(option => option.label === "menu:cancel")).toBe(true);
|
||||
expect(options.some(option => option.label === i18next.t("starterSelectUiHandler:addToParty"))).toBe(true);
|
||||
expect(options.some(option => option.label === i18next.t("starterSelectUiHandler:toggleIVs"))).toBe(true);
|
||||
expect(options.some(option => option.label === i18next.t("starterSelectUiHandler:manageMoves"))).toBe(true);
|
||||
expect(options.some(option => option.label === i18next.t("starterSelectUiHandler:useCandies"))).toBe(true);
|
||||
expect(options.some(option => option.label === i18next.t("menu:cancel"))).toBe(true);
|
||||
optionSelectUiHandler?.processInput(Button.ACTION);
|
||||
|
||||
await new Promise<void>((resolve) => {
|
||||
|
@ -376,11 +377,11 @@ describe("UI - Starter select", () => {
|
|||
resolve();
|
||||
});
|
||||
});
|
||||
expect(options.some(option => option.label === "starterSelectUiHandler:addToParty")).toBe(true);
|
||||
expect(options.some(option => option.label === "starterSelectUiHandler:toggleIVs")).toBe(true);
|
||||
expect(options.some(option => option.label === "starterSelectUiHandler:manageMoves")).toBe(true);
|
||||
expect(options.some(option => option.label === "starterSelectUiHandler:useCandies")).toBe(true);
|
||||
expect(options.some(option => option.label === "menu:cancel")).toBe(true);
|
||||
expect(options.some(option => option.label === i18next.t("starterSelectUiHandler:addToParty"))).toBe(true);
|
||||
expect(options.some(option => option.label === i18next.t("starterSelectUiHandler:toggleIVs"))).toBe(true);
|
||||
expect(options.some(option => option.label === i18next.t("starterSelectUiHandler:manageMoves"))).toBe(true);
|
||||
expect(options.some(option => option.label === i18next.t("starterSelectUiHandler:useCandies"))).toBe(true);
|
||||
expect(options.some(option => option.label === i18next.t("menu:cancel"))).toBe(true);
|
||||
optionSelectUiHandler?.processInput(Button.ACTION);
|
||||
|
||||
await new Promise<void>((resolve) => {
|
||||
|
@ -436,11 +437,11 @@ describe("UI - Starter select", () => {
|
|||
resolve();
|
||||
});
|
||||
});
|
||||
expect(options.some(option => option.label === "starterSelectUiHandler:addToParty")).toBe(true);
|
||||
expect(options.some(option => option.label === "starterSelectUiHandler:toggleIVs")).toBe(true);
|
||||
expect(options.some(option => option.label === "starterSelectUiHandler:manageMoves")).toBe(true);
|
||||
expect(options.some(option => option.label === "starterSelectUiHandler:useCandies")).toBe(true);
|
||||
expect(options.some(option => option.label === "menu:cancel")).toBe(true);
|
||||
expect(options.some(option => option.label === i18next.t("starterSelectUiHandler:addToParty"))).toBe(true);
|
||||
expect(options.some(option => option.label === i18next.t("starterSelectUiHandler:toggleIVs"))).toBe(true);
|
||||
expect(options.some(option => option.label === i18next.t("starterSelectUiHandler:manageMoves"))).toBe(true);
|
||||
expect(options.some(option => option.label === i18next.t("starterSelectUiHandler:useCandies"))).toBe(true);
|
||||
expect(options.some(option => option.label === i18next.t("menu:cancel"))).toBe(true);
|
||||
optionSelectUiHandler?.processInput(Button.ACTION);
|
||||
|
||||
await new Promise<void>((resolve) => {
|
||||
|
@ -496,11 +497,11 @@ describe("UI - Starter select", () => {
|
|||
resolve();
|
||||
});
|
||||
});
|
||||
expect(options.some(option => option.label === "starterSelectUiHandler:addToParty")).toBe(true);
|
||||
expect(options.some(option => option.label === "starterSelectUiHandler:toggleIVs")).toBe(true);
|
||||
expect(options.some(option => option.label === "starterSelectUiHandler:manageMoves")).toBe(true);
|
||||
expect(options.some(option => option.label === "starterSelectUiHandler:useCandies")).toBe(true);
|
||||
expect(options.some(option => option.label === "menu:cancel")).toBe(true);
|
||||
expect(options.some(option => option.label === i18next.t("starterSelectUiHandler:addToParty"))).toBe(true);
|
||||
expect(options.some(option => option.label === i18next.t("starterSelectUiHandler:toggleIVs"))).toBe(true);
|
||||
expect(options.some(option => option.label === i18next.t("starterSelectUiHandler:manageMoves"))).toBe(true);
|
||||
expect(options.some(option => option.label === i18next.t("starterSelectUiHandler:useCandies"))).toBe(true);
|
||||
expect(options.some(option => option.label === i18next.t("menu:cancel"))).toBe(true);
|
||||
optionSelectUiHandler?.processInput(Button.ACTION);
|
||||
|
||||
let starterSelectUiHandler: StarterSelectUiHandler;
|
||||
|
@ -561,11 +562,11 @@ describe("UI - Starter select", () => {
|
|||
resolve();
|
||||
});
|
||||
});
|
||||
expect(options.some(option => option.label === "starterSelectUiHandler:addToParty")).toBe(true);
|
||||
expect(options.some(option => option.label === "starterSelectUiHandler:toggleIVs")).toBe(true);
|
||||
expect(options.some(option => option.label === "starterSelectUiHandler:manageMoves")).toBe(true);
|
||||
expect(options.some(option => option.label === "starterSelectUiHandler:useCandies")).toBe(true);
|
||||
expect(options.some(option => option.label === "menu:cancel")).toBe(true);
|
||||
expect(options.some(option => option.label === i18next.t("starterSelectUiHandler:addToParty"))).toBe(true);
|
||||
expect(options.some(option => option.label === i18next.t("starterSelectUiHandler:toggleIVs"))).toBe(true);
|
||||
expect(options.some(option => option.label === i18next.t("starterSelectUiHandler:manageMoves"))).toBe(true);
|
||||
expect(options.some(option => option.label === i18next.t("starterSelectUiHandler:useCandies"))).toBe(true);
|
||||
expect(options.some(option => option.label === i18next.t("menu:cancel"))).toBe(true);
|
||||
optionSelectUiHandler?.processInput(Button.ACTION);
|
||||
|
||||
let starterSelectUiHandler: StarterSelectUiHandler | undefined;
|
||||
|
|
|
@ -7,7 +7,8 @@ import { Mode } from "#app/ui/ui";
|
|||
import GameManager from "#test/utils/gameManager";
|
||||
import Phaser from "phaser";
|
||||
import { afterEach, beforeAll, beforeEach, describe, expect, it } from "vitest";
|
||||
import MockText from "../utils/mocks/mocksContainer/mockText";
|
||||
import MockText from "#test/utils/mocks/mocksContainer/mockText";
|
||||
import i18next from "i18next";
|
||||
|
||||
describe("UI - Type Hints", () => {
|
||||
let phaserGame: Phaser.Game;
|
||||
|
@ -53,7 +54,7 @@ describe("UI - Type Hints", () => {
|
|||
const movesContainer = ui.getByName<Phaser.GameObjects.Container>(FightUiHandler.MOVES_CONTAINER_NAME);
|
||||
const dragonClawText = movesContainer
|
||||
.getAll<Phaser.GameObjects.Text>()
|
||||
.find((text) => text.text === "move:dragonClaw.name")! as unknown as MockText;
|
||||
.find((text) => text.text === i18next.t("move:dragonClaw.name"))! as unknown as MockText;
|
||||
|
||||
expect.soft(dragonClawText.color).toBe("#929292");
|
||||
ui.getHandler().processInput(Button.ACTION);
|
||||
|
@ -78,7 +79,7 @@ describe("UI - Type Hints", () => {
|
|||
const movesContainer = ui.getByName<Phaser.GameObjects.Container>(FightUiHandler.MOVES_CONTAINER_NAME);
|
||||
const growlText = movesContainer
|
||||
.getAll<Phaser.GameObjects.Text>()
|
||||
.find((text) => text.text === "move:growl.name")! as unknown as MockText;
|
||||
.find((text) => text.text === i18next.t("move:growl.name"))! as unknown as MockText;
|
||||
|
||||
expect.soft(growlText.color).toBe(undefined);
|
||||
ui.getHandler().processInput(Button.ACTION);
|
||||
|
|
|
@ -4,16 +4,17 @@ import { initLoggedInUser } from "#app/account";
|
|||
import { initAbilities } from "#app/data/ability";
|
||||
import { initBiomes } from "#app/data/balance/biomes";
|
||||
import { initEggMoves } from "#app/data/balance/egg-moves";
|
||||
import { initPokemonPrevolutions } from "#app/data/balance/pokemon-evolutions";
|
||||
import { initMoves } from "#app/data/move";
|
||||
import { initMysteryEncounters } from "#app/data/mystery-encounters/mystery-encounters";
|
||||
import { initPokemonPrevolutions } from "#app/data/balance/pokemon-evolutions";
|
||||
import { initPokemonForms } from "#app/data/pokemon-forms";
|
||||
import { initSpecies } from "#app/data/pokemon-species";
|
||||
import { initAchievements } from "#app/system/achv";
|
||||
import { initVouchers } from "#app/system/voucher";
|
||||
import { initStatsKeys } from "#app/ui/game-stats-ui-handler";
|
||||
import { beforeAll, vi } from "vitest";
|
||||
import { afterAll, beforeAll, vi } from "vitest";
|
||||
|
||||
/** Set the timezone to UTC for tests. */
|
||||
process.env.TZ = "UTC";
|
||||
|
||||
/** Mock the override import to always return default values, ignoring any custom overrides. */
|
||||
|
@ -26,26 +27,36 @@ vi.mock("#app/overrides", async (importOriginal) => {
|
|||
} satisfies typeof import("#app/overrides");
|
||||
});
|
||||
|
||||
vi.mock("i18next", () => ({
|
||||
default: {
|
||||
use: () => {},
|
||||
t: (key: string) => key,
|
||||
changeLanguage: () => Promise.resolve(),
|
||||
init: () => Promise.resolve(),
|
||||
resolvedLanguage: "en",
|
||||
exists: () => true,
|
||||
getDataByLanguage:() => ({
|
||||
en: {
|
||||
keys: [ "foo" ]
|
||||
},
|
||||
}),
|
||||
services: {
|
||||
formatter: {
|
||||
add: () => {},
|
||||
/**
|
||||
* This is a hacky way to mock the i18n backend requests (with the help of {@link https://mswjs.io/ | msw}).
|
||||
* The reason to put it inside of a mock is to elevate it.
|
||||
* This is necessary because how our code is structured.
|
||||
* Do NOT try to put any of this code into external functions, it won't work as it's elevated during runtime.
|
||||
*/
|
||||
vi.mock("i18next", async (importOriginal) => {
|
||||
console.log("Mocking i18next");
|
||||
const { setupServer } = await import("msw/node");
|
||||
const { http, HttpResponse } = await import("msw");
|
||||
|
||||
global.i18nServer = setupServer(
|
||||
http.get("/locales/en/*", async (req) => {
|
||||
const filename = req.params[0];
|
||||
|
||||
try {
|
||||
const json = await import(`../../public/locales/en/${req.params[0]}`);
|
||||
console.log("Loaded locale", filename);
|
||||
return HttpResponse.json(json);
|
||||
} catch (err) {
|
||||
console.log(`Failed to load locale ${filename}!`, err);
|
||||
return HttpResponse.json({});
|
||||
}
|
||||
},
|
||||
},
|
||||
}));
|
||||
})
|
||||
);
|
||||
global.i18nServer.listen({ onUnhandledRequest: "error" });
|
||||
console.log("i18n MSW server listening!");
|
||||
|
||||
return await importOriginal();
|
||||
});
|
||||
|
||||
initVouchers();
|
||||
initAchievements();
|
||||
|
@ -70,3 +81,8 @@ beforeAll(() => {
|
|||
},
|
||||
});
|
||||
});
|
||||
|
||||
afterAll(() => {
|
||||
global.i18nServer.close();
|
||||
console.log("Closing i18n MSW server!");
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue