- Complete project structure with Next.js frontend - GraphQL API backend with Apollo Server - Portal application with NextAuth - Crossplane Proxmox provider - GitOps configurations - CI/CD pipelines - Testing infrastructure (Vitest, Jest, Go tests) - Error handling and monitoring - Security hardening - UI component library - Documentation
59 lines
1.9 KiB
TypeScript
59 lines
1.9 KiB
TypeScript
import { describe, it, expect, vi } from 'vitest'
|
|
import { render, screen } from '@/lib/test-utils'
|
|
import userEvent from '@testing-library/user-event'
|
|
import { Button } from './button'
|
|
|
|
describe('Button Component', () => {
|
|
it('should render button with text', () => {
|
|
render(<Button>Click me</Button>)
|
|
expect(screen.getByRole('button', { name: /click me/i })).toBeInTheDocument()
|
|
})
|
|
|
|
it('should handle click events', async () => {
|
|
const handleClick = vi.fn()
|
|
const user = userEvent.setup()
|
|
render(<Button onClick={handleClick}>Click me</Button>)
|
|
|
|
await user.click(screen.getByRole('button'))
|
|
expect(handleClick).toHaveBeenCalledTimes(1)
|
|
})
|
|
|
|
it('should apply variant classes', () => {
|
|
const { rerender } = render(<Button variant="phoenix">Phoenix</Button>)
|
|
expect(screen.getByRole('button')).toHaveClass('bg-phoenix-fire')
|
|
|
|
rerender(<Button variant="sankofa">Sankofa</Button>)
|
|
expect(screen.getByRole('button')).toHaveClass('bg-sankofa-gold')
|
|
|
|
rerender(<Button variant="outline">Outline</Button>)
|
|
expect(screen.getByRole('button')).toHaveClass('border')
|
|
})
|
|
|
|
it('should apply size classes', () => {
|
|
const { rerender } = render(<Button size="sm">Small</Button>)
|
|
expect(screen.getByRole('button')).toHaveClass('h-8')
|
|
|
|
rerender(<Button size="lg">Large</Button>)
|
|
expect(screen.getByRole('button')).toHaveClass('h-12')
|
|
})
|
|
|
|
it('should be disabled when disabled prop is true', () => {
|
|
render(<Button disabled>Disabled</Button>)
|
|
expect(screen.getByRole('button')).toBeDisabled()
|
|
})
|
|
|
|
it('should not call onClick when disabled', async () => {
|
|
const handleClick = vi.fn()
|
|
const user = userEvent.setup()
|
|
render(
|
|
<Button disabled onClick={handleClick}>
|
|
Disabled
|
|
</Button>
|
|
)
|
|
|
|
await user.click(screen.getByRole('button'))
|
|
expect(handleClick).not.toHaveBeenCalled()
|
|
})
|
|
})
|
|
|