78 lines
3.0 KiB
TypeScript
78 lines
3.0 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
|
|
import {
|
|
applyTeamFields,
|
|
findUnsupportedTeamWeapon,
|
|
limitPresets,
|
|
parseTeamPresets,
|
|
type TeamToolValue,
|
|
} from "./team-tools";
|
|
|
|
const team = (id: string, title = id): TeamToolValue => ({
|
|
clientId: id, title, rotationSeconds: "20", combo: "E > Q",
|
|
members: [1, 2, 3, 4].map((n) => ({ characterKey: `${id}-${n}`, weaponKey: null, artifactKey: null, secondArtifactKey: null, constellation: 0, refinement: 1, damage: String(n) })),
|
|
});
|
|
|
|
describe("team bulk tools", () => {
|
|
it("copies selected fields without changing titles or mutating source", () => {
|
|
const source = team("source", "Source");
|
|
const target = team("target", "Keep title");
|
|
const result = applyTeamFields([source, target], "source", new Set(["target"]), ["loadout"]);
|
|
expect(result[1].title).toBe("Keep title");
|
|
expect(result[1].members.map((member) => member.characterKey)).toEqual(["source-1", "source-2", "source-3", "source-4"]);
|
|
expect(result[1].members.map((member) => member.damage)).toEqual(["1", "2", "3", "4"]);
|
|
expect(source.members[0].characterKey).toBe("source-1");
|
|
});
|
|
|
|
it("does not apply to the source team", () => {
|
|
const source = team("source");
|
|
expect(applyTeamFields([source], "source", new Set(["source"]), ["combo"])).toEqual([source]);
|
|
});
|
|
|
|
it("copies one field for one character slot only", () => {
|
|
const source = team("source");
|
|
const target = team("target");
|
|
source.members[0] = { ...source.members[0], characterKey: "mavuika", refinement: 1 };
|
|
target.members[0] = { ...target.members[0], characterKey: "keep-character", refinement: 5 };
|
|
|
|
const result = applyTeamFields(
|
|
[source, target],
|
|
"source",
|
|
new Set(["target"]),
|
|
["member:0:refinement"],
|
|
);
|
|
|
|
expect(result[1].members[0].refinement).toBe(1);
|
|
expect(result[1].members[0].characterKey).toBe("keep-character");
|
|
expect(result[1].members.slice(1)).toEqual(target.members.slice(1));
|
|
});
|
|
|
|
it("detects an unsupported character and weapon after bulk apply", () => {
|
|
const target = team("target");
|
|
target.members[0] = {
|
|
...target.members[0],
|
|
characterKey: "varka",
|
|
weaponKey: "wolf-fang",
|
|
};
|
|
|
|
expect(
|
|
findUnsupportedTeamWeapon(
|
|
[target],
|
|
new Set(["target"]),
|
|
[{ key: "varka", name: "Varka", weaponType: "WEAPON_CLAYMORE" }],
|
|
[{ key: "wolf-fang", name: "Wolf-Fang", weaponType: "WEAPON_SWORD_ONE_HAND" }],
|
|
),
|
|
).toEqual({ characterName: "Varka", weaponName: "Wolf-Fang" });
|
|
});
|
|
|
|
it("deduplicates and limits presets", () => {
|
|
const presets = Array.from({ length: 7 }, (_, index) => ({ id: String(index), name: String(index), createdAt: String(index), team: { ...team(String(index)), clientId: undefined as never } }));
|
|
expect(limitPresets([presets[0], presets[0], ...presets.slice(1)])).toHaveLength(5);
|
|
});
|
|
|
|
it("rejects malformed preset storage", () => {
|
|
expect(parseTeamPresets("not-json")).toEqual([]);
|
|
expect(parseTeamPresets(JSON.stringify([{ id: 1 }]))).toEqual([]);
|
|
});
|
|
});
|