/**
* Component: Confirm Dialog Tests
* Documentation: documentation/frontend/components.md
*/
// @vitest-environment jsdom
import React from 'react';
import { fireEvent, render, screen } from '@testing-library/react';
import { describe, expect, it, vi } from 'vitest';
import { ConfirmDialog } from '@/app/admin/components/ConfirmDialog';
describe('ConfirmDialog', () => {
it('renders nothing when closed', () => {
render(
);
expect(screen.queryByText('Delete')).not.toBeInTheDocument();
});
it('invokes confirm and cancel actions', () => {
const onConfirm = vi.fn();
const onCancel = vi.fn();
const { container } = render(
);
fireEvent.click(screen.getByRole('button', { name: 'Confirm' }));
expect(onConfirm).toHaveBeenCalledTimes(1);
fireEvent.click(screen.getByRole('button', { name: 'Cancel' }));
expect(onCancel).toHaveBeenCalledTimes(1);
const backdrop = container.querySelector('[aria-hidden="true"]');
expect(backdrop).not.toBeNull();
if (backdrop) {
fireEvent.click(backdrop);
}
expect(onCancel).toHaveBeenCalledTimes(2);
});
});