import { render, screen } from '@testing-library/react'
import { DashboardSkeleton } from '../DashboardSkeleton'
import { TableSkeleton } from '../TableSkeleton'
// ---------------------------------------------------------------------------
// DashboardSkeleton
// ---------------------------------------------------------------------------
describe('DashboardSkeleton', () => {
it('renders 4 skeleton cards by default', () => {
const { container } = render()
// Each card is a direct child of the grid container
const grid = container.firstChild as HTMLElement
expect(grid.children).toHaveLength(4)
})
it('renders the specified number of cards', () => {
const { container } = render()
const grid = container.firstChild as HTMLElement
expect(grid.children).toHaveLength(3)
})
it('renders 0 cards when cards=0', () => {
const { container } = render()
const grid = container.firstChild as HTMLElement
expect(grid.children).toHaveLength(0)
})
it('renders animated pulse elements inside each card', () => {
const { container } = render()
const pulseEls = container.querySelectorAll('.animate-pulse')
// Each card has 4 pulse elements
expect(pulseEls.length).toBe(4)
})
it('applies custom className to the grid', () => {
const { container } = render()
expect(container.firstChild).toHaveClass('my-skeleton')
})
it('renders with 8 cards', () => {
const { container } = render()
const grid = container.firstChild as HTMLElement
expect(grid.children).toHaveLength(8)
})
})
// ---------------------------------------------------------------------------
// TableSkeleton
// ---------------------------------------------------------------------------
describe('TableSkeleton', () => {
it('renders a table', () => {
render()
expect(screen.getByRole('table')).toBeInTheDocument()
})
it('renders default 5 rows', () => {
render()
const rows = screen.getAllByRole('row')
// 1 header row + 5 body rows
expect(rows).toHaveLength(6)
})
it('renders the specified number of body rows', () => {
render()
const rows = screen.getAllByRole('row')
// 1 header row + 3 body rows
expect(rows).toHaveLength(4)
})
it('renders default 4 columns in the header', () => {
render()
const headerCells = screen.getAllByRole('columnheader')
expect(headerCells).toHaveLength(4)
})
it('renders the specified number of columns', () => {
render()
const headerCells = screen.getAllByRole('columnheader')
expect(headerCells).toHaveLength(6)
})
it('renders correct number of data cells (rows * columns)', () => {
render()
const cells = screen.getAllByRole('cell')
expect(cells).toHaveLength(6)
})
it('renders animated pulse elements in header cells', () => {
const { container } = render()
const headerPulse = container.querySelectorAll('thead .animate-pulse')
expect(headerPulse.length).toBe(2)
})
it('applies custom className to the container', () => {
const { container } = render()
expect(container.firstChild).toHaveClass('my-table-skeleton')
})
it('renders a header skeleton area above the table', () => {
const { container } = render()
// Header search/filter area has a border-b
const headerArea = container.querySelector('.p-4.border-b')
expect(headerArea).toBeInTheDocument()
})
it('renders a pagination skeleton area below the table', () => {
const { container } = render()
// Pagination area has border-t
const paginationArea = container.querySelector('.p-4.border-t')
expect(paginationArea).toBeInTheDocument()
})
})