78 lines
2.6 KiB
TypeScript
78 lines
2.6 KiB
TypeScript
import assert from "node:assert/strict";
|
|
import test from "node:test";
|
|
import {
|
|
createMatchDetailTabSearchParams,
|
|
createMatchDetailTabs,
|
|
moveMatchDetailTabFocus,
|
|
resolveMatchDetailTab,
|
|
} from "../src/components/competition/match-detail-tabs.ts";
|
|
|
|
test("uses tabs only in progress or when finished and exposes operations only to managers", () => {
|
|
assert.deepEqual(
|
|
createMatchDetailTabs({ status: "recruiting", canManage: true }),
|
|
[],
|
|
);
|
|
assert.deepEqual(
|
|
createMatchDetailTabs({ status: "team-built", canManage: true }),
|
|
[],
|
|
);
|
|
|
|
const publicTabs = createMatchDetailTabs({
|
|
status: "in-progress",
|
|
canManage: false,
|
|
});
|
|
assert.deepEqual(
|
|
publicTabs.map((tab) => tab.id),
|
|
["bracket", "games", "teams", "info"],
|
|
);
|
|
assert.deepEqual(
|
|
publicTabs.map((tab) => tab.label),
|
|
["대진표·순위", "경기 일정·결과", "팀", "안내"],
|
|
);
|
|
|
|
const managerTabs = createMatchDetailTabs({
|
|
status: "finished",
|
|
canManage: true,
|
|
});
|
|
assert.deepEqual(
|
|
managerTabs.map((tab) => tab.id),
|
|
["bracket", "games", "teams", "info", "ops"],
|
|
);
|
|
});
|
|
|
|
test("falls back to the bracket for missing, invalid, or unauthorized tabs", () => {
|
|
const publicTabs = createMatchDetailTabs({
|
|
status: "in-progress",
|
|
canManage: false,
|
|
});
|
|
|
|
assert.equal(resolveMatchDetailTab(null, []), null);
|
|
assert.equal(resolveMatchDetailTab(null, publicTabs), "bracket");
|
|
assert.equal(resolveMatchDetailTab("unknown", publicTabs), "bracket");
|
|
assert.equal(resolveMatchDetailTab("ops", publicTabs), "bracket");
|
|
assert.equal(resolveMatchDetailTab("games", publicTabs), "games");
|
|
});
|
|
|
|
test("updates the tab query without mutating or dropping unrelated parameters", () => {
|
|
const current = new URLSearchParams("season=2026&tab=teams&from=history");
|
|
const next = createMatchDetailTabSearchParams(current, "games");
|
|
|
|
assert.equal(next.get("tab"), "games");
|
|
assert.equal(next.get("season"), "2026");
|
|
assert.equal(next.get("from"), "history");
|
|
assert.equal(current.get("tab"), "teams");
|
|
});
|
|
|
|
test("moves tab focus with wrapping arrow keys and boundary keys", () => {
|
|
const tabs = createMatchDetailTabs({
|
|
status: "in-progress",
|
|
canManage: false,
|
|
});
|
|
|
|
assert.equal(moveMatchDetailTabFocus(tabs, "bracket", "ArrowRight"), "games");
|
|
assert.equal(moveMatchDetailTabFocus(tabs, "bracket", "ArrowLeft"), "info");
|
|
assert.equal(moveMatchDetailTabFocus(tabs, "info", "ArrowRight"), "bracket");
|
|
assert.equal(moveMatchDetailTabFocus(tabs, "teams", "Home"), "bracket");
|
|
assert.equal(moveMatchDetailTabFocus(tabs, "games", "End"), "info");
|
|
});
|