2026-01-07 09:31:02 +00:00
|
|
|
import { render, screen, fireEvent } from '@testing-library/react';
|
|
|
|
|
import { describe, it, expect, vi } from 'vitest';
|
|
|
|
|
import { ConfirmationDialog } from './confirmation-dialog';
|
|
|
|
|
|
|
|
|
|
describe('ConfirmationDialog Component', () => {
|
|
|
|
|
const mockOnClose = vi.fn();
|
|
|
|
|
const mockOnConfirm = vi.fn();
|
|
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
|
vi.clearAllMocks();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('renders when open', () => {
|
|
|
|
|
render(
|
|
|
|
|
<ConfirmationDialog
|
|
|
|
|
open={true}
|
|
|
|
|
onClose={mockOnClose}
|
|
|
|
|
onConfirm={mockOnConfirm}
|
|
|
|
|
title="Confirm Action"
|
|
|
|
|
description="Are you sure?"
|
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.getByText('Confirm Action')).toBeInTheDocument();
|
|
|
|
|
expect(screen.getByText('Are you sure?')).toBeInTheDocument();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('does not render when closed', () => {
|
|
|
|
|
render(
|
|
|
|
|
<ConfirmationDialog
|
|
|
|
|
open={false}
|
|
|
|
|
onClose={mockOnClose}
|
|
|
|
|
onConfirm={mockOnConfirm}
|
|
|
|
|
title="Confirm Action"
|
|
|
|
|
description="Are you sure?"
|
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.queryByText('Confirm Action')).not.toBeInTheDocument();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('calls onConfirm when confirm button is clicked', () => {
|
|
|
|
|
render(
|
|
|
|
|
<ConfirmationDialog
|
|
|
|
|
open={true}
|
|
|
|
|
onClose={mockOnClose}
|
|
|
|
|
onConfirm={mockOnConfirm}
|
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
|
|
|
title="Delete Item"
|
2026-01-07 09:31:02 +00:00
|
|
|
description="Test"
|
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
|
|
|
confirmLabel="Confirm"
|
2026-01-13 18:47:57 +00:00
|
|
|
/>,
|
2026-01-07 09:31:02 +00:00
|
|
|
);
|
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
|
|
|
const confirmButton = screen.getByRole('button', { name: 'Confirm' });
|
2026-01-07 09:31:02 +00:00
|
|
|
fireEvent.click(confirmButton);
|
2026-01-13 18:47:57 +00:00
|
|
|
|
2026-01-07 09:31:02 +00:00
|
|
|
expect(mockOnConfirm).toHaveBeenCalled();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('calls onClose when cancel button is clicked', () => {
|
|
|
|
|
render(
|
|
|
|
|
<ConfirmationDialog
|
|
|
|
|
open={true}
|
|
|
|
|
onClose={mockOnClose}
|
|
|
|
|
onConfirm={mockOnConfirm}
|
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
|
|
|
title="Delete Item"
|
2026-01-07 09:31:02 +00:00
|
|
|
description="Test"
|
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 cancelButton = screen.getByText('Cancel');
|
|
|
|
|
fireEvent.click(cancelButton);
|
2026-01-13 18:47:57 +00:00
|
|
|
|
2026-01-07 09:31:02 +00:00
|
|
|
expect(mockOnClose).toHaveBeenCalled();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('shows loading text when isLoading is true', () => {
|
|
|
|
|
render(
|
|
|
|
|
<ConfirmationDialog
|
|
|
|
|
open={true}
|
|
|
|
|
onClose={mockOnClose}
|
|
|
|
|
onConfirm={mockOnConfirm}
|
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
|
|
|
title="Delete Item"
|
2026-01-07 09:31:02 +00:00
|
|
|
description="Test"
|
|
|
|
|
isLoading={true}
|
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.getByText('Processing...')).toBeInTheDocument();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('does not call onConfirm when isLoading is true', () => {
|
|
|
|
|
render(
|
|
|
|
|
<ConfirmationDialog
|
|
|
|
|
open={true}
|
|
|
|
|
onClose={mockOnClose}
|
|
|
|
|
onConfirm={mockOnConfirm}
|
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
|
|
|
title="Delete Item"
|
2026-01-07 09:31:02 +00:00
|
|
|
description="Test"
|
|
|
|
|
isLoading={true}
|
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 confirmButton = screen.getByText('Processing...');
|
|
|
|
|
fireEvent.click(confirmButton);
|
2026-01-13 18:47:57 +00:00
|
|
|
|
2026-01-07 09:31:02 +00:00
|
|
|
// onConfirm should not be called when loading
|
|
|
|
|
expect(mockOnConfirm).not.toHaveBeenCalled();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('uses custom confirm label', () => {
|
|
|
|
|
render(
|
|
|
|
|
<ConfirmationDialog
|
|
|
|
|
open={true}
|
|
|
|
|
onClose={mockOnClose}
|
|
|
|
|
onConfirm={mockOnConfirm}
|
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
|
|
|
title="Delete Item"
|
2026-01-07 09:31:02 +00:00
|
|
|
description="Test"
|
|
|
|
|
confirmLabel="Delete"
|
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.getByText('Delete')).toBeInTheDocument();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('shows destructive variant icon', () => {
|
|
|
|
|
render(
|
|
|
|
|
<ConfirmationDialog
|
|
|
|
|
open={true}
|
|
|
|
|
onClose={mockOnClose}
|
|
|
|
|
onConfirm={mockOnConfirm}
|
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
|
|
|
title="Delete Item"
|
2026-01-07 09:31:02 +00:00
|
|
|
description="Test"
|
|
|
|
|
variant="destructive"
|
2026-01-13 18:47:57 +00:00
|
|
|
/>,
|
2026-01-07 09:31:02 +00:00
|
|
|
);
|
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 AlertTriangle icon is an SVG (rendered via portal in document.body)
|
|
|
|
|
const icon = document.body.querySelector('svg');
|
2026-01-07 09:31:02 +00:00
|
|
|
expect(icon).toBeInTheDocument();
|
|
|
|
|
});
|
|
|
|
|
});
|