feat(stats): add platform statistics and landing blocks

Add PlatformStats component to stats page. Extract YearBars from
FinishedStats for reuse on landing. Add three blocks to landing: games
per platform, top genres, finished per year. Update translations.
This commit is contained in:
lobo committed 2026-10-01 11:10:59 +02:00
1 parent b129f6a6e4
commit 22633a9e45
12 files changed
+143 -18

No files matched your search

+45
View File
@@ -0,0 +1,45 @@
// @vitest-environment jsdom
import {afterEach, describe, expect, it, vi} from 'vitest';
import {cleanup, render, screen} from '@testing-library/react';
import {MemoryRouter} from 'react-router-dom';
import LandingPage from './LandingPage.jsx';
import {fetchRoutes, json} from '../test/fetchRoutes.js';
vi.mock('react-i18next', () => import('../test/i18n-mock.js'));
vi.mock('../hooks/useSession.js', () => ({default: () => ({active: false})}));
// Auth and Core answer the same path; one object serves both shapes.
const answer = (core) => fetchRoutes({'GET /api/stats/public': json(200, {topPlayedGames: [], topOwnedGames: [], ...core})});
const renderPage = () => render(<MemoryRouter><LandingPage/></MemoryRouter>);
describe('LandingPage', () => {
afterEach(cleanup);
it('shows games per platform, top genres and finished per year', async () => {
answer({
gamesPerPlatform: [{name: 'PS5', games: 3, minutes: 600}],
topGenres: [{name: 'Shooter', games: 2, minutes: 1200}],
finishedPerYear: [{year: 2025, games: 4}],
});
renderPage();
expect(await screen.findByText('LANDING.PLATFORMS')).toBeTruthy();
expect(screen.getByText('PS5')).toBeTruthy();
expect(screen.getByText('LANDING.TOP_GENRES')).toBeTruthy();
expect(screen.getByText('STATS.GENRE.SHOOTER')).toBeTruthy();
expect(screen.getByText('LANDING.FINISHED_PER_YEAR')).toBeTruthy();
expect(screen.getByText('2025')).toBeTruthy();
});
it('hides the three blocks while their lists are empty', async () => {
answer({gamesPerPlatform: [], topGenres: [], finishedPerYear: []});
renderPage();
await screen.findByText('LANDING.STATS_TITLE');
await vi.waitFor(() => expect(fetch).toHaveBeenCalledTimes(2));
for (const title of ['PLATFORMS', 'TOP_GENRES', 'FINISHED_PER_YEAR']) {
expect(screen.queryByText(`LANDING.${title}`)).toBeNull();
}
});
});