feat: refresh the home page and separate match event types
Add an inhouse hero, Hall of Fame, rankings, and event-specific schedules. Carry the event type through the API and admin tools, and improve results and player history displays.
This commit is contained in:
1 parent
7e0cd7cb19
commit
664af15255
58 files changed
+2316
-593
No files matched your search
@@ -0,0 +1,105 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import test from 'node:test';
|
||||
import {
|
||||
getInternalMatchOutcome,
|
||||
getMainLane,
|
||||
parseLeaderboardSort,
|
||||
rankLeaderboardByLane,
|
||||
sortLeaderboardRows,
|
||||
} from '../src/lib/internal-stats-presentation.ts';
|
||||
|
||||
const rows = [
|
||||
{ id: 'many', games: 90, winRate: 46, kda: 2.1 },
|
||||
{ id: 'steady', games: 40, winRate: 55, kda: 3.4 },
|
||||
{ id: 'lucky', games: 2, winRate: 100, kda: 9 },
|
||||
{ id: 'sharp', games: 12, winRate: 55, kda: 4.2 },
|
||||
];
|
||||
const ids = (list: typeof rows) => list.map(({ id }) => id);
|
||||
|
||||
test('keeps the server order for the default sort and ignores unknown values', () => {
|
||||
assert.equal(parseLeaderboardSort(null), 'games');
|
||||
assert.equal(parseLeaderboardSort('nope'), 'games');
|
||||
assert.equal(parseLeaderboardSort('kda'), 'kda');
|
||||
assert.deepEqual(ids(sortLeaderboardRows(rows, 'games')), ids(rows));
|
||||
});
|
||||
|
||||
test('ranks small samples after players with enough games', () => {
|
||||
assert.deepEqual(ids(sortLeaderboardRows(rows, 'winRate')), [
|
||||
'steady',
|
||||
'sharp',
|
||||
'many',
|
||||
'lucky',
|
||||
]);
|
||||
assert.deepEqual(ids(sortLeaderboardRows(rows, 'kda')), [
|
||||
'sharp',
|
||||
'steady',
|
||||
'many',
|
||||
'lucky',
|
||||
]);
|
||||
});
|
||||
|
||||
test('ranks one lane by its own win rate and sample size', () => {
|
||||
const player = (
|
||||
id: string,
|
||||
byLane: Parameters<typeof rankLeaderboardByLane>[0][number]['byLane'],
|
||||
) => ({ id, games: 50, wins: 25, losses: 25, winRate: 50, kda: 3, byLane });
|
||||
const ranked = rankLeaderboardByLane(
|
||||
[
|
||||
player('offlane', { MIDDLE: { games: 20, wins: 18, kda: 5 } }),
|
||||
player('lucky', { TOP: { games: 2, wins: 2, kda: 9 } }),
|
||||
player('steady', { TOP: { games: 10, wins: 6, kda: 3 } }),
|
||||
player('sharp', { TOP: { games: 6, wins: 4, kda: 4 } }),
|
||||
],
|
||||
'TOP',
|
||||
);
|
||||
|
||||
assert.deepEqual(
|
||||
ranked.map(({ id }) => id),
|
||||
['sharp', 'steady', 'lucky'],
|
||||
);
|
||||
assert.deepEqual(
|
||||
{ games: ranked[0].games, wins: ranked[0].wins, losses: ranked[0].losses, winRate: ranked[0].winRate },
|
||||
{ games: 6, wins: 4, losses: 2, winRate: 67 },
|
||||
);
|
||||
});
|
||||
|
||||
test('picks the most played lane', () => {
|
||||
assert.equal(
|
||||
getMainLane({
|
||||
TOP: { games: 3, wins: 1, kda: 2 },
|
||||
BOTTOM: { games: 8, wins: 4, kda: 3 },
|
||||
}),
|
||||
'BOTTOM',
|
||||
);
|
||||
assert.equal(getMainLane({}), undefined);
|
||||
});
|
||||
|
||||
test('shows a score for a single two-team series and a winner otherwise', () => {
|
||||
const team = (teamIndex: number) => ({
|
||||
teamIndex,
|
||||
name: `${teamIndex + 1}팀`,
|
||||
members: [],
|
||||
});
|
||||
const pair = getInternalMatchOutcome({
|
||||
winnerTeamIndex: 1,
|
||||
teams: [team(0), team(1)],
|
||||
seriesResults: [
|
||||
{ teamAIndex: 0, teamBIndex: 1, teamAWins: 1, teamBWins: 2 },
|
||||
],
|
||||
});
|
||||
assert.equal(pair?.type, 'score');
|
||||
assert.equal(pair?.type === 'score' && pair.rightWins, 2);
|
||||
assert.equal(pair?.winner?.name, '2팀');
|
||||
|
||||
const tournament = getInternalMatchOutcome({
|
||||
winnerTeamIndex: 2,
|
||||
teams: [team(0), team(1), team(2), team(3)],
|
||||
seriesResults: [],
|
||||
});
|
||||
assert.deepEqual(tournament, { type: 'winner', winner: team(2) });
|
||||
|
||||
assert.equal(
|
||||
getInternalMatchOutcome({ teams: [team(0), team(1)], seriesResults: [] }),
|
||||
undefined,
|
||||
);
|
||||
});
|
||||
Reference in new issue
Block a user