// @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( dashboard
welcome
}, }); }; 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')); }); });