import { describe, it, expect } from 'vitest'; import { render, screen } from '@testing-library/react'; import { LoadingState, LoadingStateWrapper } from './LoadingState'; describe('LoadingState', () => { describe('spinner variant (default)', () => { it('should render spinner when isLoading is true', () => { render(); expect(screen.getByRole('status')).toBeInTheDocument(); }); it('should render default text', () => { render(); expect(screen.getByText('Chargement...', { selector: 'p' })).toBeInTheDocument(); }); it('should render custom text', () => { render(); expect(screen.getByText('Loading data...', { selector: 'p' })).toBeInTheDocument(); }); it('should render children when isLoading is false', () => { render(
Content loaded
, ); expect(screen.getByText('Content loaded')).toBeInTheDocument(); expect(screen.queryByRole('status')).not.toBeInTheDocument(); }); }); describe('inline variant', () => { it('should render inline spinner with text', () => { render(); // The visible text span (not the sr-only from LoadingSpinner) expect(screen.getByText('Saving...', { selector: 'span:not(.sr-only)' })).toBeInTheDocument(); }); }); describe('skeleton variant', () => { it('should render skeleton placeholders', () => { const { container } = render(); expect(container.querySelector('.animate-pulse')).toBeInTheDocument(); }); it('should render children as skeleton content', () => { render(
Skeleton child
, ); expect(screen.getByTestId('skeleton-content')).toBeInTheDocument(); }); }); describe('minimal variant', () => { it('should render minimal spinner with role status', () => { render(); expect(screen.getByRole('status')).toBeInTheDocument(); }); }); describe('showSkeleton prop', () => { it('should show skeleton when showSkeleton is true', () => { const { container } = render(); expect(container.querySelector('.animate-pulse')).toBeInTheDocument(); }); }); it('should apply custom className', () => { const { container } = render( , ); expect(container.querySelector('.custom-class')).toBeInTheDocument(); }); }); describe('LoadingStateWrapper', () => { it('should show loading state when isLoading is true', () => { render(
Child content
, ); expect(screen.getByRole('status')).toBeInTheDocument(); expect(screen.queryByText('Child content')).not.toBeInTheDocument(); }); it('should show children when isLoading is false', () => { render(
Child content
, ); expect(screen.getByText('Child content')).toBeInTheDocument(); expect(screen.queryByRole('status')).not.toBeInTheDocument(); }); it('should support custom loading variant', () => { render(
Child
, ); expect(screen.getByText('Wait...', { selector: 'span:not(.sr-only)' })).toBeInTheDocument(); }); });