import { describe, expect, it } from 'vitest';
import { render, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import {
Dialog,
DialogClose,
DialogContent,
DialogDescription,
DialogHeader,
DialogTitle,
DialogTrigger,
} from './dialog';
import { Button } from '../button/button';
const Example = () => (
);
describe('Dialog', () => {
it('is closed until the trigger is activated', async () => {
render();
expect(screen.queryByRole('dialog')).not.toBeInTheDocument();
await userEvent.click(screen.getByRole('button', { name: 'Open' }));
expect(screen.getByRole('dialog')).toBeInTheDocument();
});
it('is named and described by its title and description', async () => {
render();
await userEvent.click(screen.getByRole('button', { name: 'Open' }));
expect(screen.getByRole('dialog', { name: 'Delete workspace' })).toHaveAccessibleDescription(
'This cannot be undone.'
);
});
it('closes on Escape', async () => {
render();
await userEvent.click(screen.getByRole('button', { name: 'Open' }));
await userEvent.keyboard('{Escape}');
expect(screen.queryByRole('dialog')).not.toBeInTheDocument();
});
it('closes through DialogClose', async () => {
render();
await userEvent.click(screen.getByRole('button', { name: 'Open' }));
await userEvent.click(screen.getByRole('button', { name: 'Cancel' }));
expect(screen.queryByRole('dialog')).not.toBeInTheDocument();
});
it('omits the close button when asked', async () => {
render(
);
expect(screen.queryByRole('button', { name: 'Close' })).not.toBeInTheDocument();
});
});