Rework and test getTitle

This commit is contained in:
Laeticia PIERRE 2024-05-08 22:40:35 +02:00
parent 459fb95fbd
commit 3d9b0253ef
2 changed files with 76 additions and 11 deletions

View File

@ -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♂");
});
});
});

View File

@ -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<void> {