/**
* Tests for the EmptyState component
* @jest-environment jsdom
*/
import React from 'react';
import { render, screen, fireEvent } from '@testing-library/react';
import { EmptyState } from '@/components/ui/EmptyState';
describe('EmptyState', () => {
it('should render message', () => {
render();
expect(screen.getByText('No items found')).toBeInTheDocument();
});
it('should render default icon', () => {
render();
expect(screen.getByText('📝')).toBeInTheDocument();
});
it('should render custom icon', () => {
render();
expect(screen.getByText('🔍')).toBeInTheDocument();
});
it('should render title when provided', () => {
render();
expect(screen.getByText('Empty List')).toBeInTheDocument();
});
it('should not render title when not provided', () => {
render();
expect(screen.queryByRole('heading')).not.toBeInTheDocument();
});
it('should render action button when action is provided', () => {
const mockClick = jest.fn();
render(
);
expect(screen.getByText('Add Item')).toBeInTheDocument();
});
it('should call action onClick when button is clicked', () => {
const mockClick = jest.fn();
render(
);
fireEvent.click(screen.getByText('Add Item'));
expect(mockClick).toHaveBeenCalledTimes(1);
});
it('should not render action button when action is not provided', () => {
render();
expect(screen.queryByRole('button')).not.toBeInTheDocument();
});
it('should have centered layout', () => {
const { container } = render();
expect(container.firstChild).toHaveClass('text-center');
expect(container.firstChild).toHaveClass('py-16');
});
it('should style title correctly', () => {
render();
const title = screen.getByText('Empty');
expect(title).toHaveClass('text-lg');
expect(title).toHaveClass('font-semibold');
});
it('should style message correctly', () => {
render();
const message = screen.getByText('No items found');
expect(message).toHaveClass('text-gray-600');
});
it('should style action button correctly', () => {
const mockClick = jest.fn();
render(
);
const button = screen.getByText('Click Me');
expect(button).toHaveClass('bg-blue-600');
expect(button).toHaveClass('text-white');
});
});