2026-01-07 09:31:02 +00:00
|
|
|
import { render, screen, fireEvent } from '@testing-library/react';
|
|
|
|
|
import { describe, it, expect, vi } from 'vitest';
|
|
|
|
|
import { EmptyState } from './empty-state';
|
|
|
|
|
import { Music } from 'lucide-react';
|
|
|
|
|
|
|
|
|
|
describe('EmptyState Component', () => {
|
|
|
|
|
it('renders empty state with title and description', () => {
|
|
|
|
|
render(
|
|
|
|
|
<EmptyState
|
|
|
|
|
title="No tracks found"
|
|
|
|
|
description="You haven't uploaded any tracks yet."
|
2026-01-13 18:47:57 +00:00
|
|
|
/>,
|
2026-01-07 09:31:02 +00:00
|
|
|
);
|
2026-01-13 18:47:57 +00:00
|
|
|
|
|
|
|
|
expect(screen.getByText('No tracks found')).toBeInTheDocument();
|
|
|
|
|
expect(
|
|
|
|
|
screen.getByText("You haven't uploaded any tracks yet."),
|
|
|
|
|
).toBeInTheDocument();
|
2026-01-07 09:31:02 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('renders with icon', () => {
|
|
|
|
|
render(
|
|
|
|
|
<EmptyState
|
|
|
|
|
title="Empty"
|
|
|
|
|
description="No items"
|
|
|
|
|
icon={<Music data-testid="music-icon" />}
|
2026-01-13 18:47:57 +00:00
|
|
|
/>,
|
2026-01-07 09:31:02 +00:00
|
|
|
);
|
2026-01-13 18:47:57 +00:00
|
|
|
|
2026-01-07 09:31:02 +00:00
|
|
|
expect(screen.getByTestId('music-icon')).toBeInTheDocument();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('renders with action button', () => {
|
|
|
|
|
const handleAction = vi.fn();
|
|
|
|
|
render(
|
|
|
|
|
<EmptyState
|
|
|
|
|
title="Empty"
|
|
|
|
|
description="No items"
|
|
|
|
|
action={{
|
2026-01-13 18:47:57 +00:00
|
|
|
label: 'Add Item',
|
|
|
|
|
onClick: handleAction,
|
2026-01-07 09:31:02 +00:00
|
|
|
}}
|
2026-01-13 18:47:57 +00:00
|
|
|
/>,
|
2026-01-07 09:31:02 +00:00
|
|
|
);
|
2026-01-13 18:47:57 +00:00
|
|
|
|
2026-01-07 09:31:02 +00:00
|
|
|
const button = screen.getByText('Add Item');
|
|
|
|
|
expect(button).toBeInTheDocument();
|
2026-01-13 18:47:57 +00:00
|
|
|
|
2026-01-07 09:31:02 +00:00
|
|
|
fireEvent.click(button);
|
|
|
|
|
expect(handleAction).toHaveBeenCalledTimes(1);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('does not render action button when action is not provided', () => {
|
2026-01-13 18:47:57 +00:00
|
|
|
render(<EmptyState title="Empty" description="No items" />);
|
|
|
|
|
|
2026-01-07 09:31:02 +00:00
|
|
|
const button = screen.queryByText('Add Item');
|
|
|
|
|
expect(button).not.toBeInTheDocument();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('applies custom className', () => {
|
|
|
|
|
render(
|
|
|
|
|
<EmptyState
|
|
|
|
|
title="Empty"
|
|
|
|
|
description="No items"
|
|
|
|
|
className="custom-empty-state"
|
2026-01-13 18:47:57 +00:00
|
|
|
/>,
|
2026-01-07 09:31:02 +00:00
|
|
|
);
|
2026-01-13 18:47:57 +00:00
|
|
|
|
2026-01-07 09:31:02 +00:00
|
|
|
const emptyState = screen.getByText('Empty').closest('.custom-empty-state');
|
|
|
|
|
expect(emptyState).toBeInTheDocument();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('renders without description', () => {
|
|
|
|
|
render(<EmptyState title="Empty" />);
|
2026-01-13 18:47:57 +00:00
|
|
|
|
2026-01-07 09:31:02 +00:00
|
|
|
expect(screen.getByText('Empty')).toBeInTheDocument();
|
|
|
|
|
});
|
|
|
|
|
});
|