feat: enhance auction interactions and player statistics UI
This commit is contained in:
1 parent
6c582ba3cf
commit
be4de61bb7
115 files changed
+13292
-2871
No files matched your search
@@ -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);
|
||||
});
|
||||
Reference in new issue
Block a user