sampleDataAlert.spec.tsx 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. import {Organization} from 'sentry-fixture/organization';
  2. import {render, screen, userEvent} from 'sentry-test/reactTestingLibrary';
  3. import useDismissAlert from 'sentry/utils/useDismissAlert';
  4. import {SampleDataAlert} from './sampleDataAlert';
  5. jest.mock('sentry/utils/useDismissAlert');
  6. const mockUseDismissAlert = jest.mocked(useDismissAlert);
  7. describe('SampleDataAlert', function () {
  8. it('renders if not dismissed', async function () {
  9. const dismiss = jest.fn();
  10. mockUseDismissAlert.mockImplementation(() => {
  11. return {
  12. dismiss,
  13. isDismissed: false,
  14. };
  15. });
  16. render(<SampleDataAlert />);
  17. expect(screen.getByText(/Based on your search criteria/)).toBeInTheDocument();
  18. await userEvent.click(screen.getByLabelText('Dismiss Alert'));
  19. expect(dismiss).toHaveBeenCalled();
  20. });
  21. it("doesn't render when dismissed", function () {
  22. mockUseDismissAlert.mockImplementation(() => {
  23. return {
  24. dismiss: jest.fn(),
  25. isDismissed: true,
  26. };
  27. });
  28. const {container} = render(<SampleDataAlert />);
  29. expect(container).toBeEmptyDOMElement();
  30. });
  31. it("doesn't render when there's no dynamic sampling", function () {
  32. const dismiss = jest.fn();
  33. mockUseDismissAlert.mockImplementation(() => {
  34. return {
  35. dismiss,
  36. isDismissed: false,
  37. };
  38. });
  39. const {container} = render(<SampleDataAlert />, {
  40. organization: {...Organization, isDynamicallySampled: false},
  41. });
  42. expect(container).toBeEmptyDOMElement();
  43. });
  44. });