|
| 1 | +import { render, screen } from '@testing-library/react'; |
| 2 | + |
| 3 | +import { Card, CardAction, CardContent, CardDescription, CardFooter, CardHeader, CardTitle } from '../card'; |
| 4 | +import { Button } from '../button'; |
| 5 | + |
| 6 | +describe('Card component suite', () => { |
| 7 | + it('renders all structural slots with custom classNames', () => { |
| 8 | + render( |
| 9 | + <Card className="test-card" data-testid="card-root"> |
| 10 | + <CardHeader className="header-slot"> |
| 11 | + <CardTitle>Plan</CardTitle> |
| 12 | + <CardDescription>Choose the perfect plan</CardDescription> |
| 13 | + <CardAction> |
| 14 | + <Button>Primary action</Button> |
| 15 | + </CardAction> |
| 16 | + </CardHeader> |
| 17 | + <CardContent className="content-slot">Card body content</CardContent> |
| 18 | + <CardFooter className="footer-slot">Footer CTA</CardFooter> |
| 19 | + </Card> |
| 20 | + ); |
| 21 | + |
| 22 | + expect(screen.getByTestId('card-root')).toHaveClass('test-card'); |
| 23 | + expect(screen.getByText('Plan')).toHaveAttribute('data-slot', 'card-title'); |
| 24 | + expect(screen.getByText('Choose the perfect plan')).toHaveAttribute('data-slot', 'card-description'); |
| 25 | + expect(screen.getByRole('button', { name: /primary action/i })).toBeInTheDocument(); |
| 26 | + expect(screen.getByText('Card body content')).toHaveClass('content-slot'); |
| 27 | + expect(screen.getByText('Footer CTA')).toHaveClass('footer-slot'); |
| 28 | + }); |
| 29 | + |
| 30 | + it('forwards arbitrary props down to the DOM nodes', () => { |
| 31 | + render( |
| 32 | + <Card id="pricing-card" aria-label="Pricing overview"> |
| 33 | + <CardContent>Details</CardContent> |
| 34 | + </Card> |
| 35 | + ); |
| 36 | + |
| 37 | + const card = screen.getByLabelText('Pricing overview'); |
| 38 | + expect(card).toHaveAttribute('id', 'pricing-card'); |
| 39 | + }); |
| 40 | +}); |
0 commit comments