2.4 KiB
2.4 KiB
Estratégia de Testes
Pirâmide de Testes
E2E (Playwright)
/ \
/ Integration \
/ \
/____________________\
Frontend Unit Backend Unit
(Vitest+RTL) (Vitest)
Organização de Testes
Testes Frontend
tests/
├── unit/
│ ├── components/
│ ├── hooks/
│ └── services/
└── integration/
Testes Backend
tests/
├── api/
│ ├── whatsapp/
│ └── google-calendar/
└── lib/
Testes E2E
e2e/
├── auth.spec.ts
├── whatsapp-management.spec.ts
└── google-calendar-oauth.spec.ts
Exemplos de Testes
Teste de Componente Frontend
// tests/unit/components/WhatsAppInstanceCard.test.tsx
import { render, screen, fireEvent } from '@testing-library/react';
import { describe, it, expect, vi } from 'vitest';
import { WhatsAppInstanceCard } from '@/components/whatsapp/WhatsAppInstanceCard';
describe('WhatsAppInstanceCard', () => {
it('renders instance name and status', () => {
const instance = { instanceName: 'test', status: 'connected' as const };
render(
<WhatsAppInstanceCard
instance={instance}
onGenerateQRCode={vi.fn()}
onDisconnect={vi.fn()}
/>
);
expect(screen.getByText('test')).toBeInTheDocument();
expect(screen.getByText('Conectado')).toBeInTheDocument();
});
});
Teste de API Backend
// tests/api/whatsapp/instances.test.ts
import { describe, it, expect, vi } from 'vitest';
import { GET } from '@/app/api/whatsapp/instances/route';
describe('GET /api/whatsapp/instances', () => {
it('returns instances with status', async () => {
const response = await GET(new Request('http://localhost/api/whatsapp/instances'));
const data = await response.json();
expect(response.status).toBe(200);
expect(Array.isArray(data)).toBe(true);
});
});
Teste E2E
// e2e/auth.spec.ts
import { test, expect } from '@playwright/test';
test('user can login', async ({ page }) => {
await page.goto('/login');
await page.fill('input[type="email"]', 'user@example.com');
await page.fill('input[type="password"]', 'password');
await page.click('button:has-text("Entrar")');
await expect(page).toHaveURL('/dashboard');
});