dataConsentModal.spec.tsx 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. import {OrganizationFixture} from 'sentry-fixture/organization';
  2. import {render, screen, userEvent} from 'sentry-test/reactTestingLibrary';
  3. import {
  4. makeClosableHeader,
  5. makeCloseButton,
  6. ModalBody,
  7. ModalFooter,
  8. } from 'sentry/components/globalModal/components';
  9. import DataConsentModal from 'getsentry/components/dataConsentModal';
  10. describe('Data Consent Modal', function () {
  11. const closeModal = jest.fn();
  12. const organization = OrganizationFixture();
  13. it('renders modal', async function () {
  14. render(
  15. <DataConsentModal
  16. closeModal={closeModal}
  17. Body={ModalBody}
  18. CloseButton={makeCloseButton(jest.fn())}
  19. Header={makeClosableHeader(jest.fn())}
  20. Footer={ModalFooter}
  21. />
  22. );
  23. expect(
  24. await screen.findByText('Help Sentry be more opinionated')
  25. ).toBeInTheDocument();
  26. });
  27. it('agree button work correctly', async function () {
  28. const request = MockApiClient.addMockResponse({
  29. url: `/organizations/${organization.slug}/data-consent/`,
  30. method: 'PUT',
  31. body: {aggregatedDataConsent: true},
  32. });
  33. render(
  34. <DataConsentModal
  35. closeModal={closeModal}
  36. Body={ModalBody}
  37. CloseButton={makeCloseButton(jest.fn())}
  38. Header={makeClosableHeader(jest.fn())}
  39. Footer={ModalFooter}
  40. />
  41. );
  42. expect(await screen.findByText('I agree')).toBeInTheDocument();
  43. await userEvent.click(screen.getByRole('button', {name: 'I agree'}));
  44. expect(closeModal).toHaveBeenCalled();
  45. expect(request).toHaveBeenCalledTimes(1);
  46. });
  47. it('maybe later button work correctly', async function () {
  48. render(
  49. <DataConsentModal
  50. closeModal={closeModal}
  51. Body={ModalBody}
  52. CloseButton={makeCloseButton(jest.fn())}
  53. Header={makeClosableHeader(jest.fn())}
  54. Footer={ModalFooter}
  55. />
  56. );
  57. expect(await screen.findByText('Maybe later')).toBeInTheDocument();
  58. await userEvent.click(screen.getByRole('button', {name: 'Maybe later'}));
  59. expect(closeModal).toHaveBeenCalled();
  60. });
  61. });