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,6 +4,7 @@ import {cleanup, fireEvent, render, screen, waitFor} from '@testing-library/reac
|
||||
import {MemoryRouter} from 'react-router-dom';
|
||||
import {toast} from 'sonner';
|
||||
import GameMergeDialog from './GameMergeDialog.jsx';
|
||||
import {fetchRoutes, json} from '../test/fetchRoutes.js';
|
||||
|
||||
vi.mock('react-i18next', () => import('../test/i18n-mock.js'));
|
||||
vi.mock('sonner', () => ({toast: {success: vi.fn(), error: vi.fn()}}));
|
||||
@@ -12,12 +13,11 @@ const hades = {appid: 1145360, name: 'Hades'};
|
||||
const hit = (appid, name) => ({appid, igdbId: Math.abs(appid), name, year: 2020, imageUrl: null,
|
||||
platforms: ['Switch'], inLibrary: false, inCatalog: true});
|
||||
|
||||
const json = (status, body) => ({ok: status < 400, status, json: async () => body});
|
||||
|
||||
function renderDialog(game, post, results) {
|
||||
globalThis.fetch = vi.fn(async (url, init) => init?.method === 'POST'
|
||||
? post
|
||||
: json(200, {available: true, results}));
|
||||
fetchRoutes({
|
||||
'GET /api/library/game-search': json(200, {available: true, results}),
|
||||
[`POST /api/library/games/${game.appid}/merge`]: post,
|
||||
});
|
||||
const onMerged = vi.fn();
|
||||
render(<MemoryRouter><GameMergeDialog game={game} open onOpenChange={vi.fn()} onMerged={onMerged}/></MemoryRouter>);
|
||||
return onMerged;
|
||||
|
||||
Reference in new issue
Block a user