33 lines
1.8 KiB
TypeScript
33 lines
1.8 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
|
|
import { calculateTeamMetrics } from "@/lib/guides/calculations";
|
|
import { artifactSectionSchema, teamSectionSchema, weaponSectionSchema } from "@/lib/guides/schemas";
|
|
|
|
describe("structured guide validation", () => {
|
|
it("requires at least one weapon percentage", () => {
|
|
expect(weaponSectionSchema.safeParse({ expectedVersion: 1, rows: [{ weaponKey: "1", refinement: 5, overallPercent: null, personalPercent: null }] }).success).toBe(false);
|
|
expect(weaponSectionSchema.safeParse({ expectedVersion: 1, rows: [{ weaponKey: "1", refinement: 5, overallPercent: 104, personalPercent: null }] }).success).toBe(true);
|
|
});
|
|
|
|
it("limits artifact main stats to two per slot", () => {
|
|
const result = artifactSectionSchema.safeParse({ expectedVersion: 1, groups: [], sands: ["EM", "ER", "ATK%"], goblet: [], circlet: [], substats: [], targets: [], talents: [], note: null });
|
|
expect(result.success).toBe(false);
|
|
});
|
|
|
|
it("requires four unique team members and non-zero damage", () => {
|
|
const base = { expectedVersion: 1, teams: [{ title: "Test", rotationSeconds: 20, combo: "E > Q", members: ["1", "2", "3", "4"].map((characterKey) => ({ characterKey, damage: 100 })) }] };
|
|
expect(teamSectionSchema.safeParse(base).success).toBe(true);
|
|
expect(teamSectionSchema.safeParse({ ...base, teams: [{ ...base.teams[0], members: ["1", "1", "3", "4"].map((characterKey) => ({ characterKey, damage: 100 })) }] }).success).toBe(false);
|
|
});
|
|
});
|
|
|
|
describe("Team Calc", () => {
|
|
it("calculates exact shares and total DPS", () => {
|
|
expect(calculateTeamMetrics([50, 25, 15, 10], 20)).toEqual({ totalDamage: 100, totalDps: 5, shares: [50, 25, 15, 10] });
|
|
});
|
|
|
|
it("rejects an empty damage rotation", () => {
|
|
expect(() => calculateTeamMetrics([0, 0, 0, 0], 20)).toThrow();
|
|
});
|
|
});
|