Files
lolympus-tournament-support/apps/web/test/player-information-preview-v2.test.ts
T

64 lines
3.4 KiB
TypeScript

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);
});