veza/apps/web/src/components/ui/button-loading.test.tsx
senke 37981c2c17 chore(refactor/sumi-migration): commit pending changes — tests, stream server, dist_verification
- apps/web: test updates (Vitest/setup), playbackAnalyticsService, TrackGrid, serviceErrorHandler
- veza-common: logging, metrics, traits, validation, random
- veza-stream-server: audio pipeline, codecs, cache, monitoring, routes
- apps/web/dist_verification: refresh build assets (content-hashed filenames)

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-13 19:39:18 +01:00

64 lines
2 KiB
TypeScript

import { render, screen } from '@testing-library/react';
import { describe, it, expect } from 'vitest';
import { ButtonLoading } from './button-loading';
describe('ButtonLoading Component', () => {
it('renders button with children', () => {
render(<ButtonLoading>Click me</ButtonLoading>);
expect(screen.getByText('Click me')).toBeInTheDocument();
});
it('shows loading spinner when isLoading is true', () => {
const { container } = render(<ButtonLoading isLoading={true}>Click me</ButtonLoading>);
// The Loader2 icon has aria-hidden="true" and animates with animate-spin class
const spinner = container.querySelector('.animate-spin');
expect(spinner).toBeInTheDocument();
});
it('shows loading text when provided', () => {
render(
<ButtonLoading isLoading={true} loadingText="Loading...">
Click me
</ButtonLoading>,
);
expect(screen.getByText('Loading...')).toBeInTheDocument();
expect(screen.queryByText('Click me')).not.toBeInTheDocument();
});
it('disables button when isLoading is true', () => {
render(<ButtonLoading isLoading={true}>Click me</ButtonLoading>);
const button = screen.getByRole('button');
expect(button).toBeDisabled();
});
it('disables button when disabled prop is true', () => {
render(<ButtonLoading disabled={true}>Click me</ButtonLoading>);
const button = screen.getByRole('button');
expect(button).toBeDisabled();
});
it('disables button when both isLoading and disabled are true', () => {
render(
<ButtonLoading isLoading={true} disabled={true}>
Click me
</ButtonLoading>,
);
const button = screen.getByRole('button');
expect(button).toBeDisabled();
});
it('applies custom className', () => {
const { container } = render(
<ButtonLoading className="custom-class">Click me</ButtonLoading>,
);
const button = container.querySelector('button');
expect(button).toHaveClass('custom-class');
});
});