2026-08-29 19:50:10 +02:00
|
|
|
import { describe, it, expect, vi, beforeEach } from 'vitest'
|
|
|
|
|
import { render, screen, waitFor } from '@testing-library/react'
|
2026-08-29 19:26:10 +02:00
|
|
|
import App from '../src/App'
|
|
|
|
|
|
2026-08-29 19:50:10 +02:00
|
|
|
const fetchMock = vi.fn()
|
|
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
|
fetchMock.mockReset()
|
|
|
|
|
vi.stubGlobal('fetch', fetchMock)
|
|
|
|
|
window.history.replaceState(null, '', '/')
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
function json(status: number, body: unknown) {
|
|
|
|
|
return new Response(JSON.stringify(body), {
|
|
|
|
|
status,
|
|
|
|
|
headers: { 'content-type': 'application/json' },
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
2026-08-29 19:26:10 +02:00
|
|
|
describe('App', () => {
|
2026-08-29 19:50:10 +02:00
|
|
|
it('renders the app title', async () => {
|
|
|
|
|
fetchMock.mockImplementation((url: string) => {
|
|
|
|
|
if (url === '/api/setup') return Promise.resolve(json(200, { needed: false }))
|
|
|
|
|
if (url === '/api/me')
|
|
|
|
|
return Promise.resolve(json(200, { user: { id: 1, username: 'sam', isAdmin: true } }))
|
|
|
|
|
return Promise.resolve(json(404, {}))
|
|
|
|
|
})
|
2026-08-29 19:26:10 +02:00
|
|
|
render(<App />)
|
2026-08-29 19:50:10 +02:00
|
|
|
await waitFor(() => expect(screen.getByRole('heading', { name: 'record-shop' })).toBeTruthy())
|
2026-08-29 19:26:10 +02:00
|
|
|
})
|
|
|
|
|
})
|