2026-01-07 09:31:02 +00:00
|
|
|
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>);
|
2026-01-13 18:47:57 +00:00
|
|
|
|
2026-01-07 09:31:02 +00:00
|
|
|
expect(screen.getByText('Click me')).toBeInTheDocument();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('shows loading spinner when isLoading is true', () => {
|
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 18:39:18 +00:00
|
|
|
const { container } = render(<ButtonLoading isLoading={true}>Click me</ButtonLoading>);
|
2026-01-13 18:47:57 +00:00
|
|
|
|
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 18:39:18 +00:00
|
|
|
// The Loader2 icon has aria-hidden="true" and animates with animate-spin class
|
|
|
|
|
const spinner = container.querySelector('.animate-spin');
|
2026-01-07 09:31:02 +00:00
|
|
|
expect(spinner).toBeInTheDocument();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('shows loading text when provided', () => {
|
|
|
|
|
render(
|
|
|
|
|
<ButtonLoading isLoading={true} loadingText="Loading...">
|
|
|
|
|
Click me
|
2026-01-13 18:47:57 +00:00
|
|
|
</ButtonLoading>,
|
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.getByText('Loading...')).toBeInTheDocument();
|
|
|
|
|
expect(screen.queryByText('Click me')).not.toBeInTheDocument();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('disables button when isLoading is true', () => {
|
|
|
|
|
render(<ButtonLoading isLoading={true}>Click me</ButtonLoading>);
|
2026-01-13 18:47:57 +00:00
|
|
|
|
2026-01-07 09:31:02 +00:00
|
|
|
const button = screen.getByRole('button');
|
|
|
|
|
expect(button).toBeDisabled();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('disables button when disabled prop is true', () => {
|
|
|
|
|
render(<ButtonLoading disabled={true}>Click me</ButtonLoading>);
|
2026-01-13 18:47:57 +00:00
|
|
|
|
2026-01-07 09:31:02 +00:00
|
|
|
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
|
2026-01-13 18:47:57 +00:00
|
|
|
</ButtonLoading>,
|
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.getByRole('button');
|
|
|
|
|
expect(button).toBeDisabled();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('applies custom className', () => {
|
|
|
|
|
const { container } = render(
|
2026-01-13 18:47:57 +00:00
|
|
|
<ButtonLoading className="custom-class">Click me</ButtonLoading>,
|
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 = container.querySelector('button');
|
|
|
|
|
expect(button).toHaveClass('custom-class');
|
|
|
|
|
});
|
|
|
|
|
});
|