import { describe, expect, it } from "vitest";
import {
avatarIconName,
characterDetailSchema,
cleanLunarisText,
constellationSnapshot,
nameCardImageName,
splashImageName,
supportsWeaponType,
talentSnapshot,
} from "@/lib/catalog/lunaris";
describe("Lunaris character data", () => {
it("maps CardImg names to the avatar icon endpoint", () => {
expect(avatarIconName("UI_Gacha_AvatarIcon_Ineffa")).toBe(
"UI_AvatarIcon_Ineffa",
);
});
it("maps CardImg names to Lunaris character card assets", () => {
expect(splashImageName("UI_Gacha_AvatarIcon_Ayaka")).toBe(
"UI_Gacha_AvatarImg_Ayaka.png",
);
expect(nameCardImageName("UI_Gacha_AvatarIcon_Ayaka")).toBe(
"UI_NameCardPic_Ayaka_P.png",
);
expect(nameCardImageName("UI_Gacha_AvatarIcon_Qin")).toBe(
"UI_NameCardPic_Qin_P.png",
);
});
it("removes display markup from constellation text", () => {
expect(cleanLunarisText('"A {LINK#N1}bright{/LINK} morning"')).toBe("A bright morning");
});
it("converts escaped Lunaris newlines into displayable lines", () => {
expect(cleanLunarisText("First line\\n\\nSecond line")).toBe("First line\n\nSecond line");
});
it("normalizes constellation levels and icon keys", () => {
const result = constellationSnapshot({
constellations: {
const1: { name: '"First"', description: "Detail", icon: "UI_Talent_Test_01" },
},
}, (icon) => `catalog/1/constellations/${icon}.webp`);
expect(result).toEqual([{
level: 1,
name: "First",
description: "Detail",
iconKey: "catalog/1/constellations/UI_Talent_Test_01.webp",
}]);
});
it("accepts characters that do not have constellations", () => {
const detail = characterDetailSchema.parse({ constellations: null });
expect(constellationSnapshot(detail, (icon) => icon)).toEqual([]);
});
it("reads the supported weapon type from character details", () => {
const detail = characterDetailSchema.parse({
info: { element: "Cryo", weapon: "WEAPON_SWORD_ONE_HAND" },
constellations: null,
});
expect(detail.info?.weapon).toBe("WEAPON_SWORD_ONE_HAND");
expect(detail.info?.element).toBe("Cryo");
});
it("maps normal, skill, and burst talent metadata", () => {
const detail = characterDetailSchema.parse({
skills: {
normalattack: { name: "Normal", description: "Line 1\\nLine 2", icon: "Skill_A_Test" },
elementalskill: { name: "Skill", description: "Skill detail", icon: "Skill_S_Test" },
elementalburst: { name: "Burst", description: "Burst detail", icon: "Skill_E_Test" },
},
});
expect(talentSnapshot(detail, (icon) => `${icon}.webp`)).toEqual([
{ type: "NA", name: "Normal", description: "Line 1\nLine 2", iconKey: "Skill_A_Test.webp" },
{ type: "E", name: "Skill", description: "Skill detail", iconKey: "Skill_S_Test.webp" },
{ type: "Q", name: "Burst", description: "Burst detail", iconKey: "Skill_E_Test.webp" },
]);
});
it("matches only weapons supported by the character", () => {
expect(
supportsWeaponType("WEAPON_SWORD_ONE_HAND", "WEAPON_SWORD_ONE_HAND"),
).toBe(true);
expect(
supportsWeaponType("WEAPON_SWORD_ONE_HAND", "WEAPON_CATALYST"),
).toBe(false);
expect(supportsWeaponType(undefined, "WEAPON_SWORD_ONE_HAND")).toBe(false);
});
});