feat: enhance auction interactions and player statistics UI

This commit is contained in:
dahyeon committed 2026-11-11 20:06:22 +09:00
1 parent 6c582ba3cf
commit be4de61bb7
115 files changed
+13292 -2871

No files matched your search

+47
View File
@@ -0,0 +1,47 @@
import assert from "node:assert/strict";
import test from "node:test";
import { sendAuctionChatMessage } from "../src/api/auction-chat.ts";
test("only confirms delivery when the server returns the saved message", async () => {
const message = {
id: "saved",
displayName: "팀장",
message: "확인",
sentAt: "2026-11-11T12:00:00Z",
};
assert.equal(
await sendAuctionChatMessage(async () => ({ ok: true, message })),
message,
);
await assert.rejects(
sendAuctionChatMessage(async () => ({ ok: true })),
/보내지 못했습니다/,
);
});
test("disconnection and timeout reject so the outbox can retain the original", async () => {
await assert.rejects(sendAuctionChatMessage(undefined), /연결이 끊겼습니다/);
await assert.rejects(
sendAuctionChatMessage(async () => {
throw new Error("timeout");
}),
/전송을 확인하지 못했습니다/,
);
});
test("server rejection is a failure with localized feedback", async () => {
await assert.rejects(
sendAuctionChatMessage(async () => ({
ok: false,
message: "Chat message must be 300 characters or less.",
})),
/300자/,
);
await assert.rejects(
sendAuctionChatMessage(async () => ({
ok: false,
message: "Internal implementation detail",
})),
/메시지를 보내지 못했습니다/,
);
});
@@ -0,0 +1,168 @@
import assert from "node:assert/strict";
import test from "node:test";
import type { ApiRecentMatchView } from "../src/api/types.ts";
import {
metricLabel,
selectProfileGames,
summarizeProfileGames,
} from "../src/components/auction-player-profile/stats.ts";
import {
collectProfileWindows,
profileWindow,
} from "../src/components/auction-player-profile/history.ts";
function game(overrides: Partial<ApiRecentMatchView> = {}): ApiRecentMatchView {
return {
matchId: "KR_1",
gameCreation: 100,
teamPosition: "MIDDLE",
championId: 1,
win: true,
remake: false,
kills: 4,
deaths: 2,
assists: 8,
gameDuration: 1200,
csPerMin: 6,
killParticipation: 60,
damageShare: 30,
visionScore: 20,
...overrides,
} as ApiRecentMatchView;
}
test("each position selects its own newest twenty, with no mutation or empty-lane fallback", () => {
const older = Array.from({ length: 25 }, (_, i) =>
game({ matchId: `mid-${i}`, gameCreation: i }),
);
const newer = Array.from({ length: 30 }, (_, i) =>
game({
matchId: `sup-${i}`,
teamPosition: "UTILITY",
gameCreation: 100 + i,
}),
);
const history = [...older, ...newer];
assert.equal(selectProfileGames(history, "ALL")[0].matchId, "sup-29");
const mid = selectProfileGames(history, "MID");
assert.equal(mid.length, 20);
assert.equal(mid[0].matchId, "mid-24");
assert.equal(mid.at(-1)?.matchId, "mid-5");
assert.deepEqual(selectProfileGames(history, "JGL"), []);
assert.equal(history[0].matchId, "mid-0");
});
test("summary, champions and performance use the same selected games, excluding remakes", () => {
const result = summarizeProfileGames([
game(),
game({
win: false,
kills: 2,
deaths: 4,
assists: 4,
gameDuration: 2400,
csPerMin: 8,
killParticipation: 40,
damageShare: 10,
visionScore: 20,
}),
game({ remake: true, championId: 99, kills: 100, deaths: 0 }),
])!;
assert.equal(result.games, 2);
assert.equal(result.winRate, 50);
assert.equal(result.kda, "3.00");
assert.equal(result.averageKda, "3.0/3.0/6.0");
assert.equal(result.killParticipation, 50);
assert.equal(result.csPerMinute, 7);
assert.equal(result.damageShare, 20);
assert.equal(result.visionPerMinute, 0.75);
assert.deepEqual(result.champions, [{ championId: 1, games: 2, wins: 1 }]);
});
test("missing metrics and history remain unknown; zero and Perfect are distinguished", () => {
assert.equal(summarizeProfileGames([]), null);
assert.equal(summarizeProfileGames([game({ remake: true })]), null);
const result = summarizeProfileGames([
game({ damageShare: undefined, gameDuration: 0, deaths: 0 }),
])!;
assert.equal(result.damageShare, null);
assert.equal(result.visionPerMinute, null);
assert.equal(result.kda, "Perfect");
assert.equal(
summarizeProfileGames([game({ kills: 0, deaths: 0, assists: 0 })])?.kda,
"0.00",
);
assert.equal(metricLabel(null, 0, "%"), "—");
assert.equal(metricLabel(0, 0, "%"), "0%");
});
test("legacy pagination discovers older lane matches and computes independent counts", async () => {
const requests: (number | undefined)[] = [];
const history = [
...Array.from({ length: 35 }, (_, i) =>
game({
matchId: `sup-${i}`,
teamPosition: "UTILITY",
gameCreation: 100 - i,
}),
),
...Array.from({ length: 25 }, (_, i) =>
game({ matchId: `mid-${i}`, gameCreation: 50 - i }),
),
];
const result = await collectProfileWindows(async (cursor) => {
requests.push(cursor);
const remaining = history.filter(
(game) => cursor === undefined || game.gameCreation < cursor,
);
const page = remaining.slice(0, 30);
return {
matches: page,
nextCursor: remaining.length > 30 ? page.at(-1)!.gameCreation : null,
lastFetchedAt: null,
season: { id: "all", label: "전체", startedAt: null, endedAt: null },
};
});
assert.equal(requests.length, 2);
assert.deepEqual(result.positionCounts, {
ALL: 20,
TOP: 0,
JUNGLE: 0,
MIDDLE: 20,
BOTTOM: 0,
UTILITY: 20,
});
assert.equal(profileWindow(result, "MID").matches.length, 20);
assert.equal(profileWindow(result, "MID").matches.at(-1)?.matchId, "mid-19");
assert.equal(profileWindow(result, "ALL").matches[0].matchId, "sup-0");
});
test("legacy pagination rejects a stalled cursor instead of showing an incomplete window", async () => {
await assert.rejects(
collectProfileWindows(async () => ({
matches: [],
nextCursor: 100,
lastFetchedAt: null,
season: { id: "all", label: "전체", startedAt: null, endedAt: null },
})),
/이어 불러오지/,
);
});
test("older match responses derive damage share from the player team, not both teams", () => {
const sample = game({
damageShare: undefined,
damageDealtToChampions: 20_000,
teams: [
{ win: false, participants: [{ damageDealtToChampions: 500_000 }] },
{
win: true,
participants: [
{ damageDealtToChampions: 20_000 },
{ damageDealtToChampions: 60_000 },
],
},
] as ApiRecentMatchView["teams"],
});
assert.equal(summarizeProfileGames([sample])?.damageShare, 25);
});
+88
View File
@@ -0,0 +1,88 @@
import assert from "node:assert/strict";
import test from "node:test";
import {
appendAuctionReaction,
isAuctionReaction,
MAX_VISIBLE_REACTIONS,
REACTION_LIFETIME_MS,
sendAuctionReaction,
} from "../src/api/auction-reactions.ts";
const reaction = {
id: "reaction-1",
kind: "clap" as const,
displayName: "팀장",
sentAt: 1000,
};
test("rejects unsupported or malformed realtime reactions", () => {
assert.equal(isAuctionReaction(reaction), true);
for (const value of [
null,
{},
{ ...reaction, kind: "__proto__" },
{ ...reaction, kind: "custom" },
{ ...reaction, id: "" },
{ ...reaction, sentAt: Infinity },
{ ...reaction, displayName: "a".repeat(161) },
]) {
assert.equal(isAuctionReaction(value), false);
}
});
test("deduplicates the broadcast and acknowledgement and caps simultaneous effects", () => {
const first = appendAuctionReaction([], reaction, 1000);
assert.deepEqual(appendAuctionReaction(first, reaction, 1100), first);
let current = first;
for (let index = 0; index < 40; index++) {
current = appendAuctionReaction(
current,
{ ...reaction, id: String(index) },
1200,
);
}
assert.equal(current.length, MAX_VISIBLE_REACTIONS);
assert.equal(current.at(-1)?.id, "39");
});
test("expires by local receipt time even when the server clock differs", () => {
const first = appendAuctionReaction(
[],
{ ...reaction, sentAt: 9_999_999 },
1000,
);
const next = appendAuctionReaction(
first,
{ ...reaction, id: "next" },
1000 + REACTION_LIFETIME_MS,
);
assert.deepEqual(
next.map((value) => value.id),
["next"],
);
});
test("only accepts valid server acknowledgements and explains unavailable sends", async () => {
assert.equal(
await sendAuctionReaction(async () => ({ ok: true, reaction })),
reaction,
);
await assert.rejects(sendAuctionReaction(undefined), /연결되면/);
await assert.rejects(
sendAuctionReaction(async () => ({
ok: false,
code: "REACTION_RATE_LIMITED",
})),
/기다렸다가/,
);
await assert.rejects(
sendAuctionReaction(async () => {
throw new Error("timeout");
}),
/보내지 못했습니다/,
);
await assert.rejects(
sendAuctionReaction(async () => ({ ok: true })),
/보내지 못했습니다/,
);
});
@@ -571,10 +571,9 @@ test("describes recorded Games, decisions, and legacy missing records", () => {
outcome: "walkover",
});
assert.equal(getSeriesHistoryRecordLabel(played, 2, false), "게임 상세 (2)");
assert.equal(getSeriesHistoryRecordLabel(played, 2, true), "게임 상세 접기");
assert.equal(getSeriesHistoryRecordLabel(decision, 0, false), "경기 없이 결정");
assert.equal(getSeriesHistoryRecordLabel(played, 0, false), "게임 기록 미등록");
assert.equal(getSeriesHistoryRecordLabel(played, 2), "게임 기록 2개");
assert.equal(getSeriesHistoryRecordLabel(decision, 0), "경기 없이 결정");
assert.equal(getSeriesHistoryRecordLabel(played, 0), "게임 기록 미등록");
});
test("presents known and unknown future times without an invalid time value", () => {
@@ -0,0 +1,84 @@
import test from 'node:test';
import assert from 'node:assert/strict';
import { events, games, players } from '../src/design-previews/internal-stats/data.ts';
import { aggregateRows, filterEvents, gamesForSeason, playerGames, seasonMetrics } from '../src/design-previews/internal-stats/model.ts';
test('season metrics distinguish official results from analyzable records', () => {
const june = seasonMetrics('2026-2');
assert.equal(june.events, 6);
assert.equal(june.sets, 62);
assert.equal(june.ready, 54);
assert.equal(june.players, 40);
assert.equal(gamesForSeason('all').length, games.length);
assert.equal(gamesForSeason('2026-1').length + june.sets, games.length);
assert.ok(gamesForSeason('2026-1').every(g => g.eventId.startsWith('may-')));
});
test('every event keeps its official series, opponents, scores, and complete set order', () => {
for (const event of events) {
let n = 0;
for (const series of event.series) {
assert.equal(series.scoreA + series.scoreB, series.games.length);
assert.equal(series.winner, series.scoreA > series.scoreB ? series.a : series.b);
series.games.forEach((game, index) => {
assert.equal(game.number, ++n);
assert.equal(game.ordinal, index + 1);
assert.equal(game.seriesId, series.id);
assert.deepEqual(new Set([game.blue, game.red]), new Set([series.a, series.b]));
assert.equal(game.participants.length, 10);
assert.equal(game.participants.filter(p => p.won).length, 5);
assert.equal(game.participants.reduce((n, p) => n + p.kills, 0), game.participants.reduce((n, p) => n + p.deaths, 0));
});
}
}
});
test('date, event type, participant, and search filters compose', () => {
const base = { season: '2026-2', query: '', format: 'all', from: '', to: '', player: '' };
assert.deepEqual(filterEvents({ ...base, from: '2026-06-23', to: '2026-06-23' }).map(e => e.id), ['tuesday-pair']);
assert.equal(filterEvents({ ...base, from: '2026-06-28', to: '2026-06-20' }).length, 0);
assert.ok(filterEvents({ ...base, format: 'pair' }).every(e => e.format === 'pair'));
assert.ok(filterEvents({ ...base, query: ' 정기 멸망전 ' }).every(e => e.id === 'summer-finals'));
const player = players[0];
assert.deepEqual(filterEvents({ ...base, query: player.name }).map(e => e.id), filterEvents({ ...base, player: player.id }).map(e => e.id));
assert.equal(filterEvents({ ...base, query: '존재하지않는검색어' }).length, 0);
});
test('lane selection recalculates all metrics from actual appearances', () => {
const laneRows = aggregateRows('2026-2', 'JUNGLE', 0, 'games');
const row = laneRows.find(r => r.id === 'p0')!; // This top player has role-swapped games.
const overall = aggregateRows('2026-2', 'all', 0, 'games').find(r => r.id === row.id)!;
const played = playerGames(row.id, '2026-2', 'JUNGLE');
assert.ok(row.games > 0 && row.games < overall.games);
assert.ok(played.every(v => v.game.evidence === 'ready' && v.participant.lane === 'JUNGLE'));
assert.equal(row.games, played.length);
const sum = (key: 'kills' | 'deaths' | 'assists') => played.reduce((n, v) => n + v.participant[key], 0);
assert.equal(row.kda, (sum('kills') + sum('assists')) / Math.max(sum('deaths'), 1));
assert.equal(row.winRate, played.filter(v => v.participant.won).length / played.length * 100);
assert.equal(row.gpm, played.reduce((n, v) => n + v.participant.gold / (v.game.duration / 60), 0) / played.length);
assert.equal(row.kp, played.reduce((n, v) => n + v.participant.kp, 0) / played.length);
assert.equal(row.cspm, played.reduce((n, v) => n + v.participant.cs / (v.game.duration / 60), 0) / played.length);
});
test('qualified players precede low samples and metric sorting works in either direction', () => {
for (const direction of ['asc', 'desc'] as const) {
const rows = aggregateRows('2026-2', 'all', 20, 'kda', direction);
const eligible = rows.filter(r => r.games >= 20);
assert.deepEqual(rows.slice(0, eligible.length), eligible);
assert.ok(rows.length > eligible.length && eligible.length > 0);
for (let i = 1; i < eligible.length; i++) assert.ok(direction === 'asc' ? eligible[i].kda >= eligible[i - 1].kda : eligible[i].kda <= eligible[i - 1].kda);
assert.deepEqual(rows.map(r => r.rank), rows.map((_, i) => i + 1));
}
});
test('season records link to the same season and single-game GPM is reproducible', () => {
for (const season of ['2026-1', '2026-2', 'all']) {
const metrics = seasonMetrics(season), best = metrics.bestGpm!;
const scoped = gamesForSeason(season);
assert.ok(scoped.some(g => g.id === best.game.id));
assert.equal(best.game.evidence, 'ready');
assert.equal(best.gpm, best.p.gold / (best.game.duration / 60));
assert.ok(metrics.topKda!.games >= 5 && metrics.topKp!.games >= 5 && metrics.topCs!.games >= 5);
for (const g of scoped.filter(g => g.evidence === 'ready')) for (const p of g.participants) assert.ok(p.gold / (g.duration / 60) <= best.gpm);
}
});
@@ -0,0 +1,95 @@
import test from "node:test";
import assert from "node:assert/strict";
import {
parseStatsSort,
sortStatsRows,
statsGroups,
} from "../src/components/internal-stats/stats-model.ts";
import {
statsTarget,
statsDuration,
parseStatsLane,
} from "../src/components/internal-stats/stats-navigation.ts";
import type {
ApiInternalMatchCard,
ApiLeaderboardRow,
} from "../src/api/types.ts";
test("minimum qualification takes precedence in either sort direction and source rows stay unchanged", () => {
const rows = [
{ userId: "a", summonerName: "가", games: 10, kda: 3 },
{ userId: "b", summonerName: "나", games: 1, kda: 99 },
{ userId: "c", summonerName: "다", games: 8, kda: 6 },
] as ApiLeaderboardRow[];
assert.deepEqual(
sortStatsRows(rows, "kda", 5, "desc").map((r) => [r.userId, r.rank]),
[
["c", 1],
["a", 2],
["b", 3],
],
);
assert.deepEqual(
sortStatsRows(rows, "kda", 5, "asc").map((r) => r.userId),
["a", "c", "b"],
);
assert.deepEqual(
sortStatsRows(rows, "kda", 0, "desc").map((r) => r.userId),
["b", "c", "a"],
);
assert.deepEqual(
rows.map((r) => r.userId),
["a", "b", "c"],
);
});
test("official series preserve rematches and set order; unknown games remain separate", () => {
const match = {
series: [{ seriesId: "upper" }, { seriesId: "final" }],
games: [
{ gameNumber: 3, seriesId: "final", ordinal: 2 },
{ gameNumber: 1, seriesId: "upper", ordinal: 1 },
{ gameNumber: 2, seriesId: "final", ordinal: 1 },
{ gameNumber: 4 },
{ gameNumber: 5 },
],
} as ApiInternalMatchCard;
assert.deepEqual(
statsGroups(match).map((g) => g.games.map((game) => game.gameNumber)),
[[1], [2, 3], [4], [5]],
);
});
test("detail navigation carries scope and a bounded return URL including searches and loaded pages", () => {
const parent =
"/communities/c/internal-stats?view=ranking&sort=kda&playerQ=선수&pages=3";
const target = new URL(
statsTarget(
"/communities/c/internal-stats/players/p",
new URLSearchParams({ seasonId: "june", lane: "TOP", championId: "1" }),
parent,
),
"https://example.test",
);
assert.equal(target.searchParams.get("seasonId"), "june");
assert.equal(target.searchParams.get("lane"), "TOP");
assert.equal(decodeURI(target.searchParams.get("returnTo")!), parent);
const next = new URL(
statsTarget(
"/game/1",
target.searchParams,
target.pathname + target.search,
),
target.origin,
);
assert.equal(
new URL(next.searchParams.get("returnTo")!, target.origin).searchParams.has(
"returnTo",
),
false,
);
assert.equal(parseStatsSort("wrong"), "games");
assert.equal(parseStatsLane("SUPPORT"), undefined);
assert.equal(statsDuration(0), "시간 미확인");
assert.equal(statsDuration(1872), "31:12");
});
@@ -0,0 +1,63 @@
import assert from "node:assert/strict";
import test from "node:test";
import { gamesByQueue } from "../src/design-previews/player-information-v2/data.ts";
import { selectRecentGames, summarizeGames } from "../src/design-previews/player-information-v2/stats.ts";
test("position filtering keeps summary, champion totals and rows on the same sample", () => {
const history = gamesByQueue.solo;
const all = selectRecentGames(history, "ALL");
const support = selectRecentGames(history, "SUP");
const adc = selectRecentGames(history, "ADC");
assert.equal(support.length, 20);
assert.equal(adc.length, 20);
assert.equal(summarizeGames(all)?.wins, 9);
assert.deepEqual(summarizeGames(adc)?.champions.map(champion => champion.championId), [81]);
assert.equal(summarizeGames(adc)?.champions[0].games, 20);
assert.ok(!summarizeGames(support)?.champions.some(champion => champion.championId === 81));
assert.equal(summarizeGames(support)?.champions.reduce((sum, row) => sum + row.games, 0), 20);
assert.equal(all.length, 20);
});
test("lane history is filtered before the latest twenty limit, sorted newest first, without mutating history", () => {
const history = [...gamesByQueue.solo].reverse();
const originalIds = history.map(game => game.id);
const overall = selectRecentGames(history, "ALL");
const mid = selectRecentGames(history, "MID");
assert.ok(overall.every(game => game.position !== "MID"));
assert.equal(mid.length, 20);
assert.ok(mid.every(game => game.position === "MID"));
assert.equal(mid[0].date, "2026-10-28");
assert.equal(mid.at(-1)?.date, "2026-10-09");
assert.ok(mid.every((game, index) => index === 0 || Date.parse(mid[index - 1].date) >= Date.parse(game.date)));
assert.ok(Date.parse(mid[0].date) < Date.parse(overall.at(-1)!.date));
assert.deepEqual(history.map(game => game.id), originalIds);
});
test("short and empty lane histories are not padded or replaced with overall results", () => {
assert.equal(selectRecentGames(gamesByQueue.solo, "TOP").length, 6);
assert.equal(selectRecentGames(gamesByQueue.internal, "TOP").length, 4);
assert.deepEqual(selectRecentGames(gamesByQueue.solo, "JGL"), []);
assert.equal(summarizeGames(selectRecentGames(gamesByQueue.solo, "JGL")), null);
assert.equal(selectRecentGames(gamesByQueue.internal, "MID").length, 20);
});
test("KDA uses combined kills and assists divided by combined deaths", () => {
const sample = gamesByQueue.internal.slice(0, 2);
assert.equal(summarizeGames(sample)?.kda, "3.17");
assert.equal(summarizeGames([sample[1]])?.kda, "Perfect");
assert.equal(summarizeGames(gamesByQueue.internal.slice(0, 7))?.winRate, 57);
});
test("play metrics average per-game rates and handle zero denominators", () => {
const first = { ...gamesByQueue.internal[0], minutes: 10, cs: 50, damage: 100, teamDamage: 1000, vision: 20, kills: 2, assists: 3, teamKills: 10 };
const second = { ...first, id: "second", minutes: 20, cs: 200, damage: 400, teamDamage: 1000, vision: 20, teamKills: 20 };
const summary = summarizeGames([first, second])!;
assert.equal(summary.csPerMinute, 7.5);
assert.equal(summary.visionPerMinute, 1.5);
assert.equal(summary.damageShare, 25);
assert.equal(summary.killParticipation, 37.5);
const emptyDenominators = summarizeGames([{ ...first, minutes: 0, teamDamage: 0, teamKills: 0 }])!;
assert.equal(emptyDenominators.csPerMinute, 0);
assert.equal(emptyDenominators.damageShare, 0);
assert.equal(emptyDenominators.killParticipation, 0);
});