sampleDataAlert.spec.tsx 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. import {render, screen, userEvent} from 'sentry-test/reactTestingLibrary';
  2. import useDismissAlert from 'sentry/utils/useDismissAlert';
  3. import {SampleDataAlert} from './sampleDataAlert';
  4. jest.mock('sentry/utils/useDismissAlert');
  5. const mockUseDismissAlert = useDismissAlert as jest.MockedFunction<
  6. typeof useDismissAlert
  7. >;
  8. describe('SampleDataAlert', function () {
  9. it('renders if not dismissed', async function () {
  10. const dismiss = jest.fn();
  11. mockUseDismissAlert.mockImplementation(() => {
  12. return {
  13. dismiss,
  14. isDismissed: false,
  15. };
  16. });
  17. render(<SampleDataAlert />);
  18. expect(screen.getByText(/Based on your search criteria/)).toBeInTheDocument();
  19. await userEvent.click(screen.getByLabelText('Dismiss Alert'));
  20. expect(dismiss).toHaveBeenCalled();
  21. });
  22. it("doesn't render when dismissed", function () {
  23. mockUseDismissAlert.mockImplementation(() => {
  24. return {
  25. dismiss: jest.fn(),
  26. isDismissed: true,
  27. };
  28. });
  29. const {container} = render(<SampleDataAlert />);
  30. expect(container).toBeEmptyDOMElement();
  31. });
  32. });