- tests/helpers/fakeSupabase: in-memory auth events + profiles/profile_roles builder - validation schemas and safeNextPath; classifyAuthError mapping (packages/supabase) - LoginRoute (unavailable, validation, next path, phrased failure, OAuth buttons, show password) - SignupRoute (policy, mismatch, metadata + redirect, user exists) - RequireAuth / RedirectIfSignedIn, AppLayout (nav, active, drawer, sign out), Dashboard, Account forms
59 lines
2.2 KiB
TypeScript
59 lines
2.2 KiB
TypeScript
import { afterEach, beforeEach, describe, expect, it } from 'vitest'
|
|
import { cleanup, render, screen } from '@testing-library/react'
|
|
import { MemoryRouter } from 'react-router-dom'
|
|
import DashboardRoute from '@/app/routes/app/DashboardRoute'
|
|
import { useAuthStore } from '@/state/authStore'
|
|
import { useLocaleStore } from '@/state/localeStore'
|
|
import { fr } from '@/i18n/fr'
|
|
import { fakeProfile, fakeUser } from '../helpers/fakeSupabase'
|
|
|
|
beforeEach(() => useLocaleStore.setState({ locale: 'fr' }))
|
|
afterEach(cleanup)
|
|
|
|
function mount() {
|
|
return render(
|
|
<MemoryRouter>
|
|
<DashboardRoute />
|
|
</MemoryRouter>,
|
|
)
|
|
}
|
|
|
|
describe('DashboardRoute', () => {
|
|
it('greets by first name and lists what the profile lacks', () => {
|
|
useAuthStore.setState({
|
|
status: 'signed_in',
|
|
user: fakeUser(),
|
|
profile: fakeProfile({ first_name: 'Alice' }),
|
|
roles: [],
|
|
})
|
|
mount()
|
|
expect(screen.getByRole('heading', { level: 1 })).toHaveTextContent('Bonjour Alice')
|
|
expect(screen.getByText(fr['dashboard.profile.incomplete'])).toBeInTheDocument()
|
|
expect(screen.getByText(fr['account.personal.last_name'], { exact: false })).toBeInTheDocument()
|
|
expect(
|
|
screen.getByRole('link', { name: fr['dashboard.profile.cta_complete'] }),
|
|
).toHaveAttribute('href', '/app/account')
|
|
expect(screen.getByText(fr['dashboard.account.verified'])).toBeInTheDocument()
|
|
expect(screen.getByText(fr['dashboard.account.no_roles'])).toBeInTheDocument()
|
|
})
|
|
|
|
it('switches to the complete state and shows roles', () => {
|
|
useAuthStore.setState({
|
|
status: 'signed_in',
|
|
user: fakeUser({ email_confirmed_at: undefined }),
|
|
profile: fakeProfile({
|
|
first_name: 'Alice',
|
|
last_name: 'Local',
|
|
professional_title: 'Ostéopathe',
|
|
practice_name: 'Cabinet',
|
|
}),
|
|
roles: ['admin'],
|
|
})
|
|
mount()
|
|
expect(screen.getByText(fr['dashboard.profile.complete'])).toBeInTheDocument()
|
|
expect(screen.getByRole('link', { name: fr['dashboard.profile.cta_view'] })).toBeInTheDocument()
|
|
expect(screen.getByText(fr['shell.role.admin'])).toBeInTheDocument()
|
|
expect(screen.getByText(fr['dashboard.account.unverified'])).toBeInTheDocument()
|
|
})
|
|
})
|