mirror of
https://github.com/hanzoai/sentinel.git
synced 2026-09-29 22:34:33 +00:00
66 lines
2.0 KiB
TypeScript
66 lines
2.0 KiB
TypeScript
import {render, screen, userEvent} from 'sentry-test/reactTestingLibrary';
|
|
|
|
import type {ModalRenderProps} from 'sentry/actionCreators/modal';
|
|
import OverwriteWidgetModal from 'sentry/components/modals/widgetBuilder/overwriteWidgetModal';
|
|
import {DisplayType} from 'sentry/views/dashboards/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', async () => {
|
|
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}
|
|
/>
|
|
);
|
|
|
|
await userEvent.click(screen.getByText('Confirm'));
|
|
expect(mockOnConfirm).toHaveBeenCalled();
|
|
|
|
// Modal should close after confirming
|
|
expect(mockCloseModal).toHaveBeenCalled();
|
|
});
|
|
});
|