sampleDataAlert.spec.tsx 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. import {OrganizationFixture} 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: {...OrganizationFixture(), isDynamicallySampled: false},
  41. });
  42. expect(container).toBeEmptyDOMElement();
  43. });
  44. it("doesn't render when event.type:error", function () {
  45. const dismiss = jest.fn();
  46. mockUseDismissAlert.mockImplementation(() => {
  47. return {
  48. dismiss,
  49. isDismissed: false,
  50. };
  51. });
  52. const {container} = render(<SampleDataAlert query="event.type:error" />);
  53. expect(container).toBeEmptyDOMElement();
  54. });
  55. });