Files
lolympus-tournament-support/apps/web/test/series-score-card-model.test.ts
dahyeon 03e88a03bc feat: improve series score card presentation
Show outcome-aware labels and scores, prioritize readable match names, and provide complete accessible summaries for bracket cards.
2026-07-13 23:16:43 -07:00

255 lines
7.1 KiB
TypeScript

import assert from "node:assert/strict";
import test from "node:test";
import type {
CompetitionFactId,
SeriesId,
SeriesProjection,
TeamId,
} from "@lolympus/contracts";
import {
formatSeriesScore,
getSeriesScoreCardAccessibleLabel,
getSeriesScoreCardIdentity,
getSeriesScoreCardPresentation,
} from "../src/components/competition/series-score-card-model.ts";
const TEAM_A = "team-a" as TeamId;
const TEAM_B = "team-b" as TeamId;
test("presents future and active Series with distinct status hierarchy", () => {
const inactive = pendingSeries("inactive", "inactive");
const waiting = pendingSeries("waiting", "waiting");
const ready = readySeries("ready");
const inProgress = inProgressSeries("running", 1, 0);
assert.deepEqual(getSeriesScoreCardPresentation(inactive), {
label: "비활성",
tone: "muted",
showScore: false,
});
assert.deepEqual(getSeriesScoreCardPresentation(waiting), {
label: "대진 대기",
tone: "muted",
showScore: false,
});
assert.deepEqual(getSeriesScoreCardPresentation(ready), {
label: "경기 가능",
tone: "ready",
showScore: false,
});
assert.deepEqual(getSeriesScoreCardPresentation(inProgress), {
label: "진행 중",
tone: "live",
showScore: true,
});
assert.equal(formatSeriesScore(waiting, 0), "—");
assert.equal(formatSeriesScore(ready, 0), "—");
assert.equal(formatSeriesScore(inProgress, 0), "0");
});
test("prioritizes a human-readable match name and keeps the code as metadata", () => {
const series = readySeries("WB_R2_M2");
assert.deepEqual(
getSeriesScoreCardIdentity(series, "브래킷 상위 2R · 2경기"),
{
label: "브래킷 상위 2R · 2경기",
code: "WB_R2_M2",
},
);
assert.deepEqual(getSeriesScoreCardIdentity(series), {
label: "WB_R2_M2",
code: undefined,
});
});
test("shows numeric scores only for played completed outcomes", () => {
const played = completedSeries("played", 2, 1);
const playedDraw = completedDraw("played", 1, 1);
const administrativeDraw = completedDraw("administrative", 0, 0);
assert.deepEqual(getSeriesScoreCardPresentation(played), {
label: "종료",
tone: "completed",
showScore: true,
});
assert.deepEqual(getSeriesScoreCardPresentation(playedDraw), {
label: "무승부",
tone: "completed",
showScore: true,
});
assert.deepEqual(getSeriesScoreCardPresentation(administrativeDraw), {
label: "무승부",
tone: "adjudicated",
showScore: false,
});
assert.equal(formatSeriesScore(played, 2), "2");
assert.equal(formatSeriesScore(playedDraw, 1), "1");
assert.equal(formatSeriesScore(administrativeDraw, 0), "—");
});
test("names adjudicated outcomes without inferring from their scores", () => {
const walkover = completedSeries("walkover", 0, 0);
const forfeit = completedSeries("forfeit", 0, 1);
const administrative = completedSeries("administrative", 1, 0);
assert.deepEqual(getSeriesScoreCardPresentation(walkover), {
label: "부전승",
tone: "adjudicated",
showScore: false,
});
assert.deepEqual(getSeriesScoreCardPresentation(forfeit), {
label: "기권승",
tone: "adjudicated",
showScore: false,
});
assert.deepEqual(getSeriesScoreCardPresentation(administrative), {
label: "판정",
tone: "adjudicated",
showScore: false,
});
assert.equal(getSeriesScoreCardPresentation(walkover).showScore, false);
assert.equal(getSeriesScoreCardPresentation(forfeit).showScore, false);
assert.equal(getSeriesScoreCardPresentation(administrative).showScore, false);
assert.equal(formatSeriesScore(walkover, 0), "—");
assert.equal(formatSeriesScore(forfeit, 1), "—");
assert.equal(formatSeriesScore(administrative, 1), "—");
});
test("summarizes status, teams, scores, and winner for a focus target", () => {
const series = completedSeries("played", 2, 1);
const teamById = new Map([
[TEAM_A, { name: "나물장수" }],
[TEAM_B, { name: "원딜미아요" }],
]);
assert.equal(
getSeriesScoreCardAccessibleLabel(
series,
"브래킷 1라운드 · 1경기",
teamById,
),
"브래킷 1라운드 · 1경기, 코드 PLAYED, 종료. A 나물장수, 2승, 승리. B 원딜미아요, 1승.",
);
});
test("announces an adjudicated official winner without a numeric score", () => {
const series = completedSeries("forfeit", 0, 1);
const teamById = new Map([
[TEAM_A, { name: "나물장수" }],
[TEAM_B, { name: "원딜미아요" }],
]);
assert.equal(
getSeriesScoreCardAccessibleLabel(
series,
"브래킷 1라운드 · 1경기",
teamById,
),
"브래킷 1라운드 · 1경기, 코드 FORFEIT, 기권승. A 나물장수, 점수 없음, 승리. B 원딜미아요, 점수 없음.",
);
});
function baseSeries(id: string) {
return {
seriesId: id as SeriesId,
code: id.toUpperCase(),
stage: { type: "upper" as const, roundNumber: 1, displayOrder: 1 },
rule: { type: "first-to" as const, winsRequired: 2, maxGames: 3 },
};
}
function pendingSeries(
id: string,
status: "inactive" | "waiting",
): SeriesProjection {
return {
...baseSeries(id),
status,
entries: [
{ slot: "A", teamId: null, gameWins: 0 },
{ slot: "B", teamId: null, gameWins: 0 },
],
};
}
function readySeries(id: string): SeriesProjection {
return {
...baseSeries(id),
status: "ready",
entries: [
{ slot: "A", teamId: TEAM_A, gameWins: 0 },
{ slot: "B", teamId: TEAM_B, gameWins: 0 },
],
};
}
function inProgressSeries(
id: string,
scoreA: number,
scoreB: number,
): SeriesProjection {
return {
...baseSeries(id),
status: "in-progress",
entries: [
{ slot: "A", teamId: TEAM_A, gameWins: scoreA },
{ slot: "B", teamId: TEAM_B, gameWins: scoreB },
],
};
}
function completedSeries(
outcome: "played" | "walkover" | "forfeit" | "administrative",
scoreA: number,
scoreB: number,
): SeriesProjection {
const sharedOutcome = {
winnerTeamId: TEAM_A,
loserTeamId: TEAM_B,
completedAt: "2026-07-13T00:00:00.000Z",
};
return {
...baseSeries(outcome),
status: "completed",
entries: [
{ slot: "A", teamId: TEAM_A, gameWins: scoreA },
{ slot: "B", teamId: TEAM_B, gameWins: scoreB },
],
outcome:
outcome === "played"
? { ...sharedOutcome, type: outcome, decidedByGameIds: [] }
: {
...sharedOutcome,
type: outcome,
decisionFactId: `${outcome}-fact` as CompetitionFactId,
},
};
}
function completedDraw(
basis: "played" | "administrative",
scoreA: number,
scoreB: number,
): SeriesProjection {
return {
...baseSeries(`${basis}-draw`),
status: "completed",
entries: [
{ slot: "A", teamId: TEAM_A, gameWins: scoreA },
{ slot: "B", teamId: TEAM_B, gameWins: scoreB },
],
outcome: {
type: "draw",
basis:
basis === "played"
? { type: basis, decidedByGameIds: [] }
: {
type: basis,
decisionFactId: "draw-fact" as CompetitionFactId,
},
completedAt: "2026-07-13T00:00:00.000Z",
},
};
}