Public Access
test: data router, one render helper, fetchRoutes in every test
This commit is contained in:
1 parent
d0ea9e900d
commit
2a22789435
37 files changed
+454
-425
No files matched your search
@@ -4,10 +4,11 @@ import {cleanup, fireEvent, render, screen, waitFor} from '@testing-library/reac
|
||||
import {MemoryRouter} from 'react-router-dom';
|
||||
import StatsPage from './StatsPage.jsx';
|
||||
import {PreferencesProvider} from '../context/PreferencesContext.jsx';
|
||||
import {fetchRoutes, json} from '../test/fetchRoutes.js';
|
||||
|
||||
vi.mock('react-i18next', () => import('../test/i18n-mock.js'));
|
||||
|
||||
const json = (body, status = 200) => ({ok: status < 400, status, json: async () => body});
|
||||
const answerStats = (answer) => fetchRoutes({'GET /api/library/stats': answer});
|
||||
|
||||
const stats = (extra = {}) => ({
|
||||
overview: {totalGames: 12, totalPlaytimeMinutes: 6000, playedGames: 8, neverStarted: 4,
|
||||
@@ -38,7 +39,7 @@ describe('StatsPage', () => {
|
||||
});
|
||||
|
||||
it('asks for every group once and shows each of them', async () => {
|
||||
globalThis.fetch = vi.fn(async () => json(stats()));
|
||||
answerStats(json(200, stats()));
|
||||
renderPage();
|
||||
|
||||
expect(await screen.findByText('STATS.OVERVIEW.TITLE')).toBeTruthy();
|
||||
@@ -56,7 +57,7 @@ describe('StatsPage', () => {
|
||||
|
||||
it('shows the empty texts of a new library', async () => {
|
||||
const empty = stats();
|
||||
globalThis.fetch = vi.fn(async () => json({
|
||||
answerStats(json(200, {
|
||||
...empty,
|
||||
pile: {...empty.pile, paceWeeks: null, oldestUnplayed: null},
|
||||
topGames: {mostPlayed: [], mostLoyal: null},
|
||||
@@ -77,7 +78,7 @@ describe('StatsPage', () => {
|
||||
});
|
||||
|
||||
it('offers a retry when the stats could not be loaded', async () => {
|
||||
globalThis.fetch = vi.fn(async () => json({}, 500));
|
||||
answerStats(json(500, {}));
|
||||
renderPage();
|
||||
|
||||
fireEvent.click(await screen.findByRole('button', {name: /DASHBOARD.RETRY/}));
|
||||
|
||||
Reference in new issue
Block a user