index.spec.tsx 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. import {InjectedRouter} from 'react-router';
  2. import {Location} from 'history';
  3. import {initializeOrg} from 'sentry-test/initializeOrg';
  4. import {render, screen} from 'sentry-test/reactTestingLibrary';
  5. import {Organization} from 'sentry/types';
  6. import {OrganizationContext} from 'sentry/views/organizationContext';
  7. import {RouteContext} from 'sentry/views/routeContext';
  8. import ProjectSecurityAndPrivacy from 'sentry/views/settings/projectSecurityAndPrivacy';
  9. function ComponentProviders({
  10. router,
  11. location,
  12. organization,
  13. children,
  14. }: {
  15. children: React.ReactNode;
  16. location: Location;
  17. organization: Organization;
  18. router: InjectedRouter;
  19. }) {
  20. return (
  21. <OrganizationContext.Provider value={organization}>
  22. <RouteContext.Provider
  23. value={{
  24. router,
  25. location,
  26. params: {},
  27. routes: [],
  28. }}
  29. >
  30. {children}
  31. </RouteContext.Provider>
  32. </OrganizationContext.Provider>
  33. );
  34. }
  35. describe('projectSecurityAndPrivacy', function () {
  36. it('renders form fields', function () {
  37. const {organization, router} = initializeOrg();
  38. const project = TestStubs.ProjectDetails();
  39. render(
  40. <ComponentProviders
  41. organization={organization}
  42. router={router}
  43. location={router.location}
  44. >
  45. <ProjectSecurityAndPrivacy project={project} organization={organization} />
  46. </ComponentProviders>
  47. );
  48. expect(
  49. screen.getByRole('checkbox', {
  50. name: 'Enable server-side data scrubbing',
  51. })
  52. ).not.toBeChecked();
  53. expect(
  54. screen.getByRole('checkbox', {
  55. name: 'Enable to apply default scrubbers to prevent things like passwords and credit cards from being stored',
  56. })
  57. ).not.toBeChecked();
  58. expect(
  59. screen.getByRole('checkbox', {
  60. name: 'Enable to prevent IP addresses from being stored for new events',
  61. })
  62. ).not.toBeChecked();
  63. expect(
  64. screen.getByRole('textbox', {
  65. name: 'Enter field names which data scrubbers should ignore. Separate multiple entries with a newline',
  66. })
  67. ).toHaveValue('business-email\ncompany');
  68. expect(
  69. screen.getByRole('textbox', {
  70. name: 'Enter additional field names to match against when scrubbing data. Separate multiple entries with a newline',
  71. })
  72. ).toHaveValue('creditcard\nssn');
  73. expect(
  74. screen.getByRole('textbox', {
  75. name: 'Enter additional field names to match against when scrubbing data. Separate multiple entries with a newline',
  76. })
  77. ).toHaveValue('creditcard\nssn');
  78. });
  79. it('disables field when equivalent org setting is true', function () {
  80. const {organization, router} = initializeOrg();
  81. const project = TestStubs.ProjectDetails();
  82. organization.dataScrubber = true;
  83. organization.scrubIPAddresses = false;
  84. MockApiClient.addMockResponse({
  85. url: `/projects/${organization.slug}/${project.slug}/`,
  86. method: 'GET',
  87. body: project,
  88. });
  89. render(
  90. <ComponentProviders
  91. organization={organization}
  92. router={router}
  93. location={router.location}
  94. >
  95. <ProjectSecurityAndPrivacy project={project} organization={organization} />
  96. </ComponentProviders>
  97. );
  98. expect(
  99. screen.getByRole('checkbox', {
  100. name: 'Enable to prevent IP addresses from being stored for new events',
  101. })
  102. ).toBeEnabled();
  103. expect(
  104. screen.getByRole('checkbox', {
  105. name: 'Enable to prevent IP addresses from being stored for new events',
  106. })
  107. ).not.toBeChecked();
  108. expect(
  109. screen.getByRole('checkbox', {name: 'Enable server-side data scrubbing'})
  110. ).toBeDisabled();
  111. expect(
  112. screen.getByRole('checkbox', {name: 'Enable server-side data scrubbing'})
  113. ).toBeChecked();
  114. });
  115. });