diff --git a/src/data/trainer-config.test.ts b/src/data/trainer-config.test.ts new file mode 100644 index 00000000000..dcacbbc72d5 --- /dev/null +++ b/src/data/trainer-config.test.ts @@ -0,0 +1,69 @@ +import { expect, describe, it, beforeAll, vi, afterAll, beforeEach } from "vitest"; +import { TrainerConfig, TrainerSlot } from "./trainer-config"; +import { TrainerType } from "./enums/trainer-type"; +import { TrainerVariant } from "#app/field/trainer.js"; + +describe("trainer-config", () => { + describe("getTitle", () => { + let trainerConfig: TrainerConfig; + + beforeAll(() => { + // Error when importing biomes / voucher (imported by different files) + vi.mock('./biomes', () => ({ + biomeLinks: {}, + BiomePoolTier: {}, + PokemonPools: {}, + getBiomeName: () => "", + BiomeTierTrainerPools: {}, + biomePokemonPools: {}, + biomeTrainerPools: {}, + })); + vi.mock('../system/voucher', () => ({ + vouchers: {}, + VoucherType: {}, + getVoucherTypeIcon: () => "", + Voucher: {}, + getVoucherTypeName: () => "", + })); + }); + + afterAll(() => { + vi.clearAllMocks(); + }); + + beforeEach(() => { + trainerConfig = new TrainerConfig(TrainerType.ARTIST, false); + }); + + it("returns the name double when trainer variant double", () => { + trainerConfig.nameDouble = "Lae & Ticia"; + expect(trainerConfig.getTitle(TrainerSlot.NONE, TrainerVariant.DOUBLE)).toBe("Lae & Ticia"); + }); + + it("returns the trainer type name when no gender selected", () => { + expect(trainerConfig.getTitle(TrainerSlot.NONE, TrainerVariant.DEFAULT)).toBe("Artist"); + }); + + it("returns the female name when gender is female", () => { + trainerConfig.nameFemale = "Laeticia"; + trainerConfig.hasGenders = true; + expect(trainerConfig.getTitle(TrainerSlot.NONE, TrainerVariant.FEMALE)).toBe("Laeticia"); + }); + + it("returns the female name when trainer variant double and trainer partner", () => { + trainerConfig.nameFemale = "Laeticia"; + trainerConfig.hasGenders = true; + expect(trainerConfig.getTitle(TrainerSlot.TRAINER_PARTNER, TrainerVariant.DOUBLE)).toBe("Laeticia"); + }); + + it("returns the trainer type name with the female gender", () => { + trainerConfig.hasGenders = true; + expect(trainerConfig.getTitle(TrainerSlot.NONE, TrainerVariant.FEMALE)).toBe("Artist♀"); + }); + + it("returns the trainer type name with the male gender", () => { + trainerConfig.hasGenders = true; + expect(trainerConfig.getTitle(TrainerSlot.NONE, TrainerVariant.DEFAULT)).toBe("Artist♂"); + }); + }); +}); diff --git a/src/data/trainer-config.ts b/src/data/trainer-config.ts index 36d76edcfab..cd3e78a0dfb 100644 --- a/src/data/trainer-config.ts +++ b/src/data/trainer-config.ts @@ -429,20 +429,16 @@ export class TrainerConfig { } getTitle(trainerSlot: TrainerSlot = TrainerSlot.NONE, variant: TrainerVariant): string { - let ret = this.name; - - if (!trainerSlot && variant === TrainerVariant.DOUBLE && this.nameDouble) + if (trainerSlot === TrainerSlot.NONE && variant === TrainerVariant.DOUBLE && this.nameDouble) return this.nameDouble; - if (this.hasGenders) { - if (this.nameFemale) { - if (variant === TrainerVariant.FEMALE || (variant === TrainerVariant.DOUBLE && trainerSlot === TrainerSlot.TRAINER_PARTNER)) - return this.nameFemale; - } else - ret += !variant ? '♂' : '♀'; - } + if (!this.hasGenders) + return this.name; - return ret; + if (this.nameFemale && (variant === TrainerVariant.FEMALE || (variant === TrainerVariant.DOUBLE && trainerSlot === TrainerSlot.TRAINER_PARTNER))) + return this.nameFemale; + + return `${this.name}${variant === TrainerVariant.DEFAULT ? '♂' : '♀'}`; } loadAssets(scene: BattleScene, variant: TrainerVariant): Promise {