widgetBuilderOverwriteModal.spec.tsx 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. import {render, screen, userEvent} from 'sentry-test/reactTestingLibrary';
  2. import {ModalRenderProps} from 'sentry/actionCreators/modal';
  3. import OverwriteWidgetModal from 'sentry/components/modals/widgetBuilder/overwriteWidgetModal';
  4. import {DisplayType} from 'sentry/views/dashboardsV2/types';
  5. const stubEl = (props: {children?: React.ReactNode}) => <div>{props.children}</div>;
  6. describe('widget builder overwrite modal', () => {
  7. it('renders with the widget title and description', () => {
  8. const widget = {
  9. title: 'Test title',
  10. description: 'Test description',
  11. displayType: DisplayType.LINE,
  12. interval: '5m',
  13. queries: [],
  14. };
  15. render(
  16. <OverwriteWidgetModal
  17. Header={stubEl}
  18. Footer={stubEl as ModalRenderProps['Footer']}
  19. Body={stubEl as ModalRenderProps['Body']}
  20. CloseButton={stubEl}
  21. closeModal={() => undefined}
  22. iconColor="white"
  23. widget={widget}
  24. onConfirm={jest.fn()}
  25. />
  26. );
  27. expect(screen.getByText('Overwrite Widget')).toBeInTheDocument();
  28. expect(screen.getByText('Test title')).toBeInTheDocument();
  29. expect(screen.getByText('Test description')).toBeInTheDocument();
  30. });
  31. it('calls the confirm handler and closes the modal when confirmed', () => {
  32. const widget = {
  33. title: 'Test title',
  34. description: 'Test description',
  35. displayType: DisplayType.LINE,
  36. interval: '5m',
  37. queries: [],
  38. };
  39. const mockOnConfirm = jest.fn();
  40. const mockCloseModal = jest.fn();
  41. render(
  42. <OverwriteWidgetModal
  43. Header={stubEl}
  44. Footer={stubEl as ModalRenderProps['Footer']}
  45. Body={stubEl as ModalRenderProps['Body']}
  46. CloseButton={stubEl}
  47. closeModal={mockCloseModal}
  48. iconColor="white"
  49. widget={widget}
  50. onConfirm={mockOnConfirm}
  51. />
  52. );
  53. userEvent.click(screen.getByText('Confirm'));
  54. expect(mockOnConfirm).toHaveBeenCalled();
  55. // Modal should close after confirming
  56. expect(mockCloseModal).toHaveBeenCalled();
  57. });
  58. });