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}) =>
{props.children}
;
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(
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(
);
userEvent.click(screen.getByText('Confirm'));
expect(mockOnConfirm).toHaveBeenCalled();
// Modal should close after confirming
expect(mockCloseModal).toHaveBeenCalled();
});
});