Files
buzz-sheet/lib/guides/team-tools.test.ts
T
2026-09-03 23:24:51 +07:00

36 lines
1.7 KiB
TypeScript

import { describe, expect, it } from "vitest";
import { applyTeamFields, limitPresets, parseTeamPresets } from "./team-tools";
const team = (id: string, title = id) => ({
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("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([]);
});
});