|
| 1 | +import React from 'react'; |
| 2 | +import { render } from '@testing-library/react'; |
| 3 | +import { describe, it, expect } from 'vitest'; |
| 4 | +import '@testing-library/jest-dom'; |
| 5 | +import { Grid } from '../'; |
| 6 | + |
| 7 | +describe('Grid component', () => { |
| 8 | + it('should match snapshot', () => { |
| 9 | + const { container } = render(<Grid>Snapshot Test</Grid>); |
| 10 | + expect(container).toMatchSnapshot(); |
| 11 | + }); |
| 12 | + |
| 13 | + it('should render children correctly', () => { |
| 14 | + const { getByText } = render( |
| 15 | + <Grid> |
| 16 | + <div>Item 1</div> |
| 17 | + <div>Item 2</div> |
| 18 | + </Grid> |
| 19 | + ); |
| 20 | + |
| 21 | + expect(getByText('Item 1')).toBeInTheDocument(); |
| 22 | + expect(getByText('Item 2')).toBeInTheDocument(); |
| 23 | + }); |
| 24 | + |
| 25 | + it('should apply the default grid classes', () => { |
| 26 | + const { container } = render(<Grid>Test</Grid>); |
| 27 | + const gridDiv = container.firstChild as HTMLElement; |
| 28 | + |
| 29 | + expect(gridDiv).toHaveClass('grid'); |
| 30 | + expect(gridDiv).toHaveClass('min-w-full'); |
| 31 | + expect(gridDiv).toHaveClass('auto-rows-min'); |
| 32 | + expect(gridDiv).toHaveClass('grid-cols-2'); |
| 33 | + }); |
| 34 | + |
| 35 | + it('should append custom className to the wrapper', () => { |
| 36 | + const { container } = render(<Grid className="custom-class">Test</Grid>); |
| 37 | + const gridDiv = container.firstChild as HTMLElement; |
| 38 | + |
| 39 | + expect(gridDiv).toHaveClass('custom-class'); |
| 40 | + expect(gridDiv).toHaveClass('grid'); |
| 41 | + }); |
| 42 | + |
| 43 | + it('should assign id and data-cy correctly', () => { |
| 44 | + const { container } = render(<Grid id="grid-id" dataCy="grid-data-cy">Test</Grid>); |
| 45 | + const gridDiv = container.firstChild as HTMLElement; |
| 46 | + |
| 47 | + expect(gridDiv).toHaveAttribute('id', 'grid-id'); |
| 48 | + expect(gridDiv).toHaveAttribute('data-cy', 'grid-data-cy'); |
| 49 | + }); |
| 50 | +}); |
0 commit comments