test: smoke test do App com mock do supabase
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
acc305ff21
commit
4eafb0c5d0
25
src/__tests__/App.test.tsx
Normal file
25
src/__tests__/App.test.tsx
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
import { render, screen, waitFor } from '@testing-library/react'
|
||||||
|
import { describe, it, expect } from 'vitest'
|
||||||
|
import App from '@/App'
|
||||||
|
|
||||||
|
describe('App', () => {
|
||||||
|
it('renderiza título premium', () => {
|
||||||
|
render(<App />)
|
||||||
|
expect(screen.getByRole('heading', { name: /reserva rede 1001/i })).toBeInTheDocument()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('exibe marcas retornadas do supabase após carregar', async () => {
|
||||||
|
render(<App />)
|
||||||
|
await waitFor(() => {
|
||||||
|
expect(screen.getByText('Hotel 1001 Noites')).toBeInTheDocument()
|
||||||
|
expect(screen.getByText('Dolce Amore')).toBeInTheDocument()
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
it('não mostra estado de loading após fetch completar', async () => {
|
||||||
|
render(<App />)
|
||||||
|
await waitFor(() => {
|
||||||
|
expect(screen.queryByText(/carregando marcas/i)).not.toBeInTheDocument()
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
42
src/__tests__/setup.ts
Normal file
42
src/__tests__/setup.ts
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
import '@testing-library/jest-dom/vitest'
|
||||||
|
import { cleanup } from '@testing-library/react'
|
||||||
|
import { afterEach, vi } from 'vitest'
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
|
cleanup()
|
||||||
|
})
|
||||||
|
|
||||||
|
// Mock do Supabase client — imita from('marcas').select('*').eq('ativa', true).order('nome')
|
||||||
|
vi.mock('@/lib/supabase', () => {
|
||||||
|
const mockMarcas = [
|
||||||
|
{
|
||||||
|
id: '3fac5ed4-100f-4c0a-82ce-06110758b9c9',
|
||||||
|
nome: 'Hotel 1001 Noites',
|
||||||
|
categorias: ['Standard', 'Superior', 'Luxo'],
|
||||||
|
permanencias: ['3hrs', '6hrs', 'Pernoite'],
|
||||||
|
descricao: null,
|
||||||
|
ativa: true,
|
||||||
|
created_at: '2026-04-13T00:00:00Z',
|
||||||
|
updated_at: '2026-04-13T00:00:00Z',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: '11111111-1111-1111-1111-111111111111',
|
||||||
|
nome: 'Dolce Amore',
|
||||||
|
categorias: ['Suite Master', 'Apartamento'],
|
||||||
|
permanencias: ['3hrs', '4hrs'],
|
||||||
|
descricao: null,
|
||||||
|
ativa: true,
|
||||||
|
created_at: '2026-04-13T00:00:00Z',
|
||||||
|
updated_at: '2026-04-13T00:00:00Z',
|
||||||
|
},
|
||||||
|
]
|
||||||
|
|
||||||
|
const orderFn = vi.fn(() => Promise.resolve({ data: mockMarcas, error: null }))
|
||||||
|
const eqFn = vi.fn(() => ({ order: orderFn }))
|
||||||
|
const selectFn = vi.fn(() => ({ eq: eqFn, order: orderFn }))
|
||||||
|
const fromFn = vi.fn(() => ({ select: selectFn }))
|
||||||
|
|
||||||
|
return {
|
||||||
|
supabase: { from: fromFn },
|
||||||
|
}
|
||||||
|
})
|
||||||
Loading…
Reference in New Issue
Block a user