|
| 1 | +import React from 'react'; |
| 2 | +import { render, screen } from '@testing-library/react'; |
| 3 | +import SmallCard from './SmallCard'; |
| 4 | +import '@testing-library/jest-dom'; |
| 5 | + |
| 6 | +describe('SmallCard component', () => { |
| 7 | + it('renders children content', () => { |
| 8 | + render(<SmallCard>Test content</SmallCard>); |
| 9 | + expect(screen.getByText('Test content')).toBeInTheDocument(); |
| 10 | + }); |
| 11 | + |
| 12 | + it('renders a header if provided', () => { |
| 13 | + render(<SmallCard header="Card Header">Body</SmallCard>); |
| 14 | + expect(screen.getByText('Card Header')).toBeInTheDocument(); |
| 15 | + expect(screen.getByText('Body')).toBeInTheDocument(); |
| 16 | + }); |
| 17 | + |
| 18 | + it('does not render header elements when header prop is not passed', () => { |
| 19 | + const { container } = render(<SmallCard>Only Body</SmallCard>); |
| 20 | + expect(container.querySelector('h6')).toBeNull(); |
| 21 | + expect(container.querySelector('hr')).toBeNull(); |
| 22 | + }); |
| 23 | + |
| 24 | + it('applies custom className when provided', () => { |
| 25 | + const { container } = render( |
| 26 | + <SmallCard className="custom-class">Styled</SmallCard> |
| 27 | + ); |
| 28 | + expect(container.firstChild).toHaveClass('custom-class'); |
| 29 | + }); |
| 30 | + |
| 31 | + it('applies default className when custom className is not provided', () => { |
| 32 | + const { container } = render(<SmallCard>Default Style</SmallCard>); |
| 33 | + expect(container.firstChild).toHaveClass('p-3', 'bg-white', 'rounded', 'shadow'); |
| 34 | + }); |
| 35 | + |
| 36 | +}); |
0 commit comments