Files
ToBePlayed-Frontend/src/components/WelcomeGate.test.jsx
T
lobo b129f6a6e4 feat(welcome): add welcome page for new users after first login
Shows six feature cards and two next steps (Steam, import). The dashboard
redirects to it while Auth settings.welcomeSeenAt is null; "Let's go" and
"Skip" set the stamp. Settings links to it to reopen later.
2026-10-01 10:44:22 +02:00

47 lines
1.6 KiB
React

// @vitest-environment jsdom
import {afterEach, beforeEach, describe, expect, it, vi} from 'vitest';
import {cleanup, screen, waitFor} from '@testing-library/react';
import WelcomeGate from './WelcomeGate.jsx';
import {fetchRoutes, json} from '../test/fetchRoutes.js';
import {renderWithProviders} from '../test/renderWithProviders.jsx';
vi.mock('react-i18next', () => import('../test/i18n-mock.js'));
const me = (settings) => ({id: 1, email: 'a@b.de', role: 'USER', settings});
const renderGate = (settings) => {
fetchRoutes({'GET /api/users/me': json(200, me(settings))});
return renderWithProviders(<WelcomeGate><p>dashboard</p></WelcomeGate>, {
path: '/dashboard', entries: ['/dashboard'], routes: {'/welcome': <p>welcome</p>},
});
};
describe('WelcomeGate', () => {
beforeEach(() => localStorage.setItem('tbp_session', '1'));
afterEach(() => {
cleanup();
localStorage.clear();
});
it('opens the welcome page when the user has not seen it', async () => {
const {router} = renderGate({welcomeSeenAt: null});
await screen.findByText('welcome');
expect(router.state.location.pathname).toBe('/welcome');
});
it('shows the children once the welcome page was seen', async () => {
renderGate({welcomeSeenAt: '2026-10-01T10:00:00Z'});
expect(await screen.findByText('dashboard')).toBeTruthy();
});
it('shows the children when /me has no such field', async () => {
const {router} = renderGate({});
expect(await screen.findByText('dashboard')).toBeTruthy();
await waitFor(() => expect(router.state.location.pathname).toBe('/dashboard'));
});
});