index.spec.tsx 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. import {Fragment} from 'react';
  2. import {initializeOrg} from 'sentry-test/initializeOrg';
  3. import {render, screen, userEvent} from 'sentry-test/reactTestingLibrary';
  4. import {textWithMarkupMatcher} from 'sentry-test/utils';
  5. import GlobalModal from 'sentry/components/globalModal';
  6. import {DataScrubbing} from 'sentry/views/settings/components/dataScrubbing';
  7. const relayPiiConfig = JSON.stringify(TestStubs.DataScrubbingRelayPiiConfig());
  8. describe('Data Scrubbing', function () {
  9. describe('Organization level', function () {
  10. const {organization} = initializeOrg();
  11. const additionalContext = 'These rules can be configured for each project.';
  12. const endpoint = `organization/${organization.slug}/`;
  13. it('default render', function () {
  14. render(
  15. <DataScrubbing
  16. additionalContext={additionalContext}
  17. endpoint={endpoint}
  18. relayPiiConfig={relayPiiConfig}
  19. organization={organization}
  20. onSubmitSuccess={jest.fn()}
  21. />
  22. );
  23. // Header
  24. expect(screen.getByText('Advanced Data Scrubbing')).toBeInTheDocument();
  25. // Alert
  26. expect(
  27. screen.getByText(
  28. textWithMarkupMatcher(
  29. `${additionalContext} The new rules will only apply to upcoming events. For more details, see full documentation on data scrubbing.`
  30. )
  31. )
  32. ).toBeInTheDocument();
  33. expect(
  34. screen.getByRole('link', {name: 'full documentation on data scrubbing'})
  35. ).toHaveAttribute(
  36. 'href',
  37. `https://docs.sentry.io/product/data-management-settings/scrubbing/advanced-datascrubbing/`
  38. );
  39. // Body
  40. expect(screen.getAllByRole('button', {name: 'Edit Rule'})).toHaveLength(3);
  41. // Actions
  42. expect(screen.getByRole('button', {name: 'Read Docs'})).toHaveAttribute(
  43. 'href',
  44. `https://docs.sentry.io/product/data-management-settings/scrubbing/advanced-datascrubbing/`
  45. );
  46. expect(screen.getByRole('button', {name: 'Add Rule'})).toBeEnabled();
  47. });
  48. it('render empty state', function () {
  49. render(
  50. <DataScrubbing
  51. endpoint={endpoint}
  52. relayPiiConfig={undefined}
  53. organization={organization}
  54. onSubmitSuccess={jest.fn()}
  55. />
  56. );
  57. expect(screen.getByText('You have no data scrubbing rules')).toBeInTheDocument();
  58. });
  59. it('render disabled actions', function () {
  60. render(
  61. <DataScrubbing
  62. additionalContext={additionalContext}
  63. endpoint={endpoint}
  64. relayPiiConfig={relayPiiConfig}
  65. organization={organization}
  66. onSubmitSuccess={jest.fn()}
  67. disabled
  68. />
  69. );
  70. // Read Docs is the only enabled action
  71. expect(screen.getByRole('button', {name: 'Read Docs'})).toBeEnabled();
  72. expect(screen.getByRole('button', {name: 'Add Rule'})).toBeDisabled();
  73. for (const index in JSON.parse(relayPiiConfig).rules) {
  74. expect(screen.getAllByRole('button', {name: 'Edit Rule'})[index]).toBeDisabled();
  75. expect(
  76. screen.getAllByRole('button', {name: 'Delete Rule'})[index]
  77. ).toBeDisabled();
  78. }
  79. });
  80. });
  81. describe('Project level', function () {
  82. it('default render', function () {
  83. const {organization, project} = initializeOrg();
  84. render(
  85. <DataScrubbing
  86. endpoint={`/projects/${organization.slug}/foo/`}
  87. relayPiiConfig={relayPiiConfig}
  88. organization={organization}
  89. onSubmitSuccess={jest.fn()}
  90. project={project}
  91. />
  92. );
  93. // Header
  94. expect(
  95. screen.getByText('There are no data scrubbing rules at the organization level')
  96. ).toBeInTheDocument();
  97. });
  98. it('OrganizationRules has content', function () {
  99. const {organization, project} = initializeOrg({
  100. ...initializeOrg(),
  101. organization: {
  102. ...initializeOrg().organization,
  103. relayPiiConfig,
  104. },
  105. });
  106. render(
  107. <DataScrubbing
  108. endpoint={`/projects/${organization.slug}/foo/`}
  109. relayPiiConfig={relayPiiConfig}
  110. organization={organization}
  111. onSubmitSuccess={jest.fn()}
  112. project={project}
  113. />,
  114. {organization}
  115. );
  116. // Organization Rules
  117. expect(screen.getByText('Organization Rules')).toBeInTheDocument();
  118. });
  119. it('Delete rule successfully', async function () {
  120. const {organization, project} = initializeOrg();
  121. render(
  122. <Fragment>
  123. <GlobalModal />
  124. <DataScrubbing
  125. endpoint={`/projects/${organization.slug}/foo/`}
  126. project={project}
  127. relayPiiConfig={relayPiiConfig}
  128. disabled={false}
  129. organization={organization}
  130. onSubmitSuccess={jest.fn()}
  131. />
  132. </Fragment>
  133. );
  134. userEvent.click(screen.getAllByLabelText('Delete Rule')[0]);
  135. expect(
  136. await screen.findByText('Are you sure you wish to delete this rule?')
  137. ).toBeInTheDocument();
  138. });
  139. it('Open Add Rule Modal', async function () {
  140. const {organization, project} = initializeOrg();
  141. render(
  142. <Fragment>
  143. <GlobalModal />
  144. <DataScrubbing
  145. endpoint={`/projects/${organization.slug}/foo/`}
  146. project={project}
  147. relayPiiConfig={relayPiiConfig}
  148. disabled={false}
  149. organization={organization}
  150. onSubmitSuccess={jest.fn()}
  151. />
  152. </Fragment>
  153. );
  154. userEvent.click(screen.getByRole('button', {name: 'Add Rule'}));
  155. expect(
  156. await screen.findByText('Add an advanced data scrubbing rule')
  157. ).toBeInTheDocument();
  158. });
  159. it('Open Edit Rule Modal', function () {
  160. const {organization, router, project} = initializeOrg();
  161. render(
  162. <Fragment>
  163. <GlobalModal />
  164. <DataScrubbing
  165. endpoint={`/projects/${organization.slug}/foo/`}
  166. project={project}
  167. relayPiiConfig={relayPiiConfig}
  168. disabled={false}
  169. organization={organization}
  170. onSubmitSuccess={jest.fn()}
  171. />
  172. </Fragment>,
  173. {router}
  174. );
  175. userEvent.click(screen.getAllByRole('button', {name: 'Edit Rule'})[0]);
  176. // Verify the router to open the modal was called
  177. expect(router.push).toHaveBeenCalledWith(
  178. expect.objectContaining({
  179. pathname: `/settings/${organization.slug}/projects/${project.slug}/security-and-privacy/advanced-data-scrubbing/0/`,
  180. })
  181. );
  182. });
  183. });
  184. });