sampleDataAlert.spec.tsx 1.5 KB

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