1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- import {render, screen, userEvent} from 'sentry-test/reactTestingLibrary';
- import {ModalRenderProps} from 'sentry/actionCreators/modal';
- import OverwriteWidgetModal from 'sentry/components/modals/widgetBuilder/overwriteWidgetModal';
- import {DisplayType} from 'sentry/views/dashboardsV2/types';
- const stubEl = (props: {children?: React.ReactNode}) => <div>{props.children}</div>;
- describe('widget builder overwrite modal', () => {
- it('renders with the widget title and description', () => {
- const widget = {
- title: 'Test title',
- description: 'Test description',
- displayType: DisplayType.LINE,
- interval: '5m',
- queries: [],
- };
- render(
- <OverwriteWidgetModal
- Header={stubEl}
- Footer={stubEl as ModalRenderProps['Footer']}
- Body={stubEl as ModalRenderProps['Body']}
- CloseButton={stubEl}
- closeModal={() => undefined}
- iconColor="white"
- widget={widget}
- onConfirm={jest.fn()}
- />
- );
- expect(screen.getByText('Overwrite Widget')).toBeInTheDocument();
- expect(screen.getByText('Test title')).toBeInTheDocument();
- expect(screen.getByText('Test description')).toBeInTheDocument();
- });
- it('calls the confirm handler and closes the modal when confirmed', () => {
- const widget = {
- title: 'Test title',
- description: 'Test description',
- displayType: DisplayType.LINE,
- interval: '5m',
- queries: [],
- };
- const mockOnConfirm = jest.fn();
- const mockCloseModal = jest.fn();
- render(
- <OverwriteWidgetModal
- Header={stubEl}
- Footer={stubEl as ModalRenderProps['Footer']}
- Body={stubEl as ModalRenderProps['Body']}
- CloseButton={stubEl}
- closeModal={mockCloseModal}
- iconColor="white"
- widget={widget}
- onConfirm={mockOnConfirm}
- />
- );
- userEvent.click(screen.getByText('Confirm'));
- expect(mockOnConfirm).toHaveBeenCalled();
- // Modal should close after confirming
- expect(mockCloseModal).toHaveBeenCalled();
- });
- });
|