2026-03-07 15:57:51 -08:00
|
|
|
import { describe, it, expect } from "vitest";
|
2026-03-27 20:45:15 -07:00
|
|
|
import { buildTiedRankChecker, getDisplayRank } from "../standings-display";
|
|
|
|
|
|
|
|
|
|
describe("buildTiedRankChecker", () => {
|
|
|
|
|
it("returns false for a rank held by only one team", () => {
|
|
|
|
|
const isTied = buildTiedRankChecker([1, 2, 3]);
|
|
|
|
|
expect(isTied(1)).toBe(false);
|
|
|
|
|
expect(isTied(2)).toBe(false);
|
|
|
|
|
expect(isTied(3)).toBe(false);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("returns true for a rank shared by two or more teams", () => {
|
|
|
|
|
const isTied = buildTiedRankChecker([1, 3, 3, 5]);
|
|
|
|
|
expect(isTied(3)).toBe(true);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("returns false for a rank not present in the list", () => {
|
|
|
|
|
const isTied = buildTiedRankChecker([1, 2]);
|
|
|
|
|
expect(isTied(99)).toBe(false);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("handles all teams tied at rank 1", () => {
|
|
|
|
|
const isTied = buildTiedRankChecker([1, 1, 1]);
|
|
|
|
|
expect(isTied(1)).toBe(true);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("handles an empty list without throwing", () => {
|
|
|
|
|
const isTied = buildTiedRankChecker([]);
|
|
|
|
|
expect(isTied(1)).toBe(false);
|
|
|
|
|
});
|
|
|
|
|
});
|
2026-03-07 15:57:51 -08:00
|
|
|
|
|
|
|
|
describe("getDisplayRank", () => {
|
|
|
|
|
describe("when the team has a standing", () => {
|
|
|
|
|
it("returns the numeric rank regardless of how many other teams have standings", () => {
|
|
|
|
|
expect(getDisplayRank({ currentRank: 1 }, 5)).toBe(1);
|
|
|
|
|
expect(getDisplayRank({ currentRank: 3 }, 5)).toBe(3);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("returns rank 1 when the team is first", () => {
|
|
|
|
|
expect(getDisplayRank({ currentRank: 1 }, 1)).toBe(1);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
describe("when the team has no standing and no teams have been scored yet", () => {
|
|
|
|
|
it("returns T1 — all teams are genuinely tied at zero", () => {
|
|
|
|
|
expect(getDisplayRank(undefined, 0)).toBe("T1");
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
describe("when the team has no standing but other teams have been scored", () => {
|
|
|
|
|
it("returns T{n+1} where n is the number of teams with standings", () => {
|
|
|
|
|
// 1 team has a standing → unranked teams are tied for 2nd
|
|
|
|
|
expect(getDisplayRank(undefined, 1)).toBe("T2");
|
|
|
|
|
|
|
|
|
|
// 3 teams have standings → unranked teams are tied for 4th
|
|
|
|
|
expect(getDisplayRank(undefined, 3)).toBe("T4");
|
|
|
|
|
|
|
|
|
|
// 9 teams have standings → unranked team is tied for 10th
|
|
|
|
|
expect(getDisplayRank(undefined, 9)).toBe("T10");
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("never shows T1 when any other team has a standing", () => {
|
|
|
|
|
// Would be wrong to show T1 here — that team isn't first
|
|
|
|
|
expect(getDisplayRank(undefined, 1)).not.toBe("T1");
|
|
|
|
|
expect(getDisplayRank(undefined, 5)).not.toBe("T1");
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|