import { render } from '@testing-library/react'; import { describe, it, expect } from 'vitest'; import { Grid } from './Grid'; describe('Grid Component', () => { it('renders children', () => { const { getByText } = render(
Item 1
Item 2
, ); expect(getByText('Item 1')).toBeInTheDocument(); expect(getByText('Item 2')).toBeInTheDocument(); }); it('renders with default columns (3)', () => { const { container } = render(
Item
, ); const grid = container.firstChild; expect(grid).toHaveClass('grid-cols-3'); }); it('renders with custom number of columns', () => { const { container } = render(
Item
, ); const grid = container.firstChild; expect(grid).toHaveClass('grid-cols-4'); }); it('renders with default gap (4)', () => { const { container } = render(
Item
, ); const grid = container.firstChild; expect(grid).toHaveClass('gap-4'); }); it('renders with custom gap', () => { const { container } = render(
Item
, ); const grid = container.firstChild; expect(grid).toHaveClass('gap-6'); }); it('renders with rowGap and columnGap', () => { const { container } = render(
Item
, ); const grid = container.firstChild; expect(grid).toHaveClass('gap-y-2'); expect(grid).toHaveClass('gap-x-4'); }); it('renders with responsive breakpoints', () => { const { container } = render(
Item
, ); const grid = container.firstChild; expect(grid).toHaveClass('grid-cols-2'); expect(grid).toHaveClass('sm:grid-cols-2'); expect(grid).toHaveClass('md:grid-cols-3'); expect(grid).toHaveClass('lg:grid-cols-4'); expect(grid).toHaveClass('xl:grid-cols-5'); }); it('renders with 2xl breakpoint', () => { const { container } = render(
Item
, ); const grid = container.firstChild; expect(grid).toHaveClass('lg:grid-cols-4'); expect(grid).toHaveClass('xl:grid-cols-5'); expect(grid).toHaveClass('2xl:grid-cols-6'); }); it('renders with mobile first (1 column) when only larger breakpoints are specified', () => { const { container } = render(
Item
, ); const grid = container.firstChild; expect(grid).toHaveClass('grid-cols-1'); expect(grid).toHaveClass('md:grid-cols-3'); expect(grid).toHaveClass('lg:grid-cols-4'); }); it('applies custom className', () => { const { container } = render(
Item
, ); const grid = container.firstChild; expect(grid).toHaveClass('custom-grid'); }); it('always includes grid class', () => { const { container } = render(
Item
, ); const grid = container.firstChild; expect(grid).toHaveClass('grid'); }); it('renders with gap 0', () => { const { container } = render(
Item
, ); const grid = container.firstChild; expect(grid).toHaveClass('gap-0'); }); it('renders with large gap', () => { const { container } = render(
Item
, ); const grid = container.firstChild; expect(grid).toHaveClass('gap-12'); }); it('renders with single column', () => { const { container } = render(
Item
, ); const grid = container.firstChild; expect(grid).toHaveClass('grid-cols-1'); }); it('renders with 12 columns', () => { const { container } = render(
Item
, ); const grid = container.firstChild; expect(grid).toHaveClass('grid-cols-12'); }); it('prioritizes gap over rowGap and columnGap', () => { const { container } = render(
Item
, ); const grid = container.firstChild; expect(grid).toHaveClass('gap-8'); expect(grid).not.toHaveClass('gap-y-2'); expect(grid).not.toHaveClass('gap-x-4'); }); });