mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
* add modal scaffolding * add some unit tests * remove dummy api, add some TODO comments * small test refactor * another small test refactor * fix unit tests due to aria-label/data-testid change
73 lines
2.3 KiB
TypeScript
73 lines
2.3 KiB
TypeScript
import { render, screen } from '@testing-library/react';
|
|
import userEvent from '@testing-library/user-event';
|
|
import React from 'react';
|
|
|
|
import { DeleteModal, Props } from './DeleteModal';
|
|
|
|
describe('browse-dashboards DeleteModal', () => {
|
|
const mockOnDismiss = jest.fn();
|
|
const mockOnConfirm = jest.fn();
|
|
|
|
const defaultProps: Props = {
|
|
isOpen: true,
|
|
onConfirm: mockOnConfirm,
|
|
onDismiss: mockOnDismiss,
|
|
selectedItems: {
|
|
folder: {},
|
|
dashboard: {},
|
|
panel: {},
|
|
},
|
|
};
|
|
|
|
it('renders a dialog with the correct title', async () => {
|
|
render(<DeleteModal {...defaultProps} />);
|
|
|
|
expect(await screen.findByRole('dialog', { name: 'Delete Compute Resources' })).toBeInTheDocument();
|
|
});
|
|
|
|
it('displays a `Delete` button', async () => {
|
|
render(<DeleteModal {...defaultProps} />);
|
|
|
|
expect(await screen.findByRole('button', { name: 'Delete' })).toBeInTheDocument();
|
|
});
|
|
|
|
it('displays a `Cancel` button', async () => {
|
|
render(<DeleteModal {...defaultProps} />);
|
|
|
|
expect(await screen.findByRole('button', { name: 'Cancel' })).toBeInTheDocument();
|
|
});
|
|
|
|
it('only enables the `Delete` button if the confirmation text is typed', async () => {
|
|
render(<DeleteModal {...defaultProps} />);
|
|
|
|
const confirmationInput = await screen.findByPlaceholderText('Type Delete to confirm');
|
|
await userEvent.type(confirmationInput, 'Delete');
|
|
|
|
expect(await screen.findByRole('button', { name: 'Delete' })).toBeEnabled();
|
|
});
|
|
|
|
it('calls onConfirm when clicking the `Delete` button', async () => {
|
|
render(<DeleteModal {...defaultProps} />);
|
|
|
|
const confirmationInput = await screen.findByPlaceholderText('Type Delete to confirm');
|
|
await userEvent.type(confirmationInput, 'Delete');
|
|
|
|
await userEvent.click(await screen.findByRole('button', { name: 'Delete' }));
|
|
expect(mockOnConfirm).toHaveBeenCalled();
|
|
});
|
|
|
|
it('calls onDismiss when clicking the `Cancel` button', async () => {
|
|
render(<DeleteModal {...defaultProps} />);
|
|
|
|
await userEvent.click(await screen.findByRole('button', { name: 'Cancel' }));
|
|
expect(mockOnDismiss).toHaveBeenCalled();
|
|
});
|
|
|
|
it('calls onDismiss when clicking the X', async () => {
|
|
render(<DeleteModal {...defaultProps} />);
|
|
|
|
await userEvent.click(await screen.findByRole('button', { name: 'Close dialog' }));
|
|
expect(mockOnDismiss).toHaveBeenCalled();
|
|
});
|
|
});
|