118 lines
3.8 KiB
TypeScript
118 lines
3.8 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
|
|
import {
|
|
avatarIconName,
|
|
ascensionSnapshot,
|
|
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}<color=#fff>bright</color>{/LINK} morning"')).toBe("A bright morning");
|
|
});
|
|
|
|
it("converts escaped Lunaris newlines into displayable lines", () => {
|
|
expect(cleanLunarisText("First line\\n\\n<i>Second line</i>")).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("normalizes scalar and grouped ascension materials", () => {
|
|
const detail = characterDetailSchema.parse({
|
|
ascension: {
|
|
"202": 7049900,
|
|
exp: { "104001": 2, "104003": 418 },
|
|
},
|
|
});
|
|
|
|
expect(ascensionSnapshot(detail)).toEqual([
|
|
{ type: "202", items: [{ key: "202", amount: 7049900 }] },
|
|
{
|
|
type: "exp",
|
|
items: [
|
|
{ key: "104001", amount: 2 },
|
|
{ key: "104003", amount: 418 },
|
|
],
|
|
},
|
|
]);
|
|
});
|
|
|
|
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);
|
|
});
|
|
});
|