dynamicSampling.spec.tsx 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. import {initializeOrg} from 'sentry-test/initializeOrg';
  2. import {render, screen, userEvent} from 'sentry-test/reactTestingLibrary';
  3. import {Organization, Project} from 'sentry/types';
  4. import {DynamicSamplingBiasType} from 'sentry/types/sampling';
  5. import DynamicSampling from '.';
  6. const ORG_FEATURES = [
  7. 'server-side-sampling',
  8. 'dynamic-sampling-deprecated',
  9. 'dynamic-sampling',
  10. ];
  11. const dynamicSamplingBiases = [
  12. {id: DynamicSamplingBiasType.BOOST_LATEST_RELEASES, active: true},
  13. {id: DynamicSamplingBiasType.BOOST_ENVIRONMENTS, active: true},
  14. {id: DynamicSamplingBiasType.BOOST_KEY_TRANSACTIONS, active: true},
  15. {id: DynamicSamplingBiasType.IGNORE_HEALTH_CHECKS, active: true},
  16. ];
  17. function renderMockRequests(
  18. organizationSlug: Organization['slug'],
  19. projectSlug: Project['slug']
  20. ) {
  21. const projectDetails = MockApiClient.addMockResponse({
  22. url: `/projects/${organizationSlug}/${projectSlug}/`,
  23. method: 'PUT',
  24. body: {},
  25. });
  26. return {projectDetails};
  27. }
  28. describe('Dynamic Sampling', function () {
  29. it('renders default ui', function () {
  30. const {project, organization} = initializeOrg({
  31. ...initializeOrg(),
  32. projects: [
  33. TestStubs.Project({
  34. dynamicSamplingBiases,
  35. }),
  36. ],
  37. organization: {
  38. ...initializeOrg().organization,
  39. features: ORG_FEATURES,
  40. },
  41. });
  42. renderMockRequests(organization.slug, project.slug);
  43. render(<DynamicSampling project={project} />, {organization});
  44. expect(screen.getByRole('heading', {name: /Dynamic Sampling/})).toBeInTheDocument();
  45. expect(screen.getAllByRole('checkbox')).toHaveLength(4);
  46. expect(screen.queryByTestId('more-information')).not.toBeInTheDocument();
  47. const prioritizenewReleases = screen.getByRole('checkbox', {
  48. name: 'Prioritize new releases',
  49. });
  50. expect(prioritizenewReleases).toBeEnabled();
  51. expect(prioritizenewReleases).toBeChecked();
  52. const prioritizeDevEnvironments = screen.getByRole('checkbox', {
  53. name: 'Prioritize dev environments',
  54. });
  55. expect(prioritizeDevEnvironments).toBeEnabled();
  56. expect(prioritizeDevEnvironments).toBeChecked();
  57. const prioritizeKeyTransactions = screen.getByRole('checkbox', {
  58. name: 'Prioritize key transactions',
  59. });
  60. expect(prioritizeKeyTransactions).toBeEnabled();
  61. expect(prioritizeKeyTransactions).toBeChecked();
  62. const ignoreHealthChecks = screen.getByRole('checkbox', {
  63. name: 'Ignore health checks',
  64. });
  65. expect(ignoreHealthChecks).toBeEnabled();
  66. expect(ignoreHealthChecks).toBeChecked();
  67. });
  68. it('renders disabled default UI, when user has not permission to edit', async function () {
  69. const {project, organization} = initializeOrg({
  70. ...initializeOrg(),
  71. projects: [
  72. TestStubs.Project({
  73. dynamicSamplingBiases,
  74. }),
  75. ],
  76. organization: {
  77. ...initializeOrg().organization,
  78. features: ORG_FEATURES,
  79. access: [],
  80. },
  81. });
  82. renderMockRequests(organization.slug, project.slug);
  83. render(<DynamicSampling project={project} />, {organization});
  84. expect(
  85. screen.getByText(
  86. /These settings can only be edited by users with the organization owner, manager, or admin role/
  87. )
  88. ).toBeInTheDocument();
  89. const prioritizenewReleases = screen.getByRole('checkbox', {
  90. name: 'Prioritize new releases',
  91. });
  92. expect(prioritizenewReleases).toBeDisabled();
  93. expect(prioritizenewReleases).toBeChecked();
  94. userEvent.hover(prioritizenewReleases);
  95. expect(
  96. await screen.findByText('You do not have permission to edit this setting')
  97. ).toBeInTheDocument();
  98. const prioritizeDevEnvironments = screen.getByRole('checkbox', {
  99. name: 'Prioritize dev environments',
  100. });
  101. expect(prioritizeDevEnvironments).toBeDisabled();
  102. expect(prioritizeDevEnvironments).toBeChecked();
  103. const prioritizeKeyTransactions = screen.getByRole('checkbox', {
  104. name: 'Prioritize key transactions',
  105. });
  106. expect(prioritizeKeyTransactions).toBeDisabled();
  107. expect(prioritizeKeyTransactions).toBeChecked();
  108. const ignoreHealthChecks = screen.getByRole('checkbox', {
  109. name: 'Ignore health checks',
  110. });
  111. expect(ignoreHealthChecks).toBeDisabled();
  112. expect(ignoreHealthChecks).toBeChecked();
  113. });
  114. it('user can toggle option', function () {
  115. const {project, organization} = initializeOrg({
  116. ...initializeOrg(),
  117. projects: [
  118. TestStubs.Project({
  119. dynamicSamplingBiases,
  120. }),
  121. ],
  122. organization: {
  123. ...initializeOrg().organization,
  124. features: ORG_FEATURES,
  125. },
  126. });
  127. const mockRequests = renderMockRequests(organization.slug, project.slug);
  128. render(<DynamicSampling project={project} />, {organization});
  129. userEvent.click(screen.getByRole('checkbox', {name: 'Prioritize new releases'}));
  130. expect(mockRequests.projectDetails).toHaveBeenCalledWith(
  131. `/projects/${organization.slug}/${project.slug}/`,
  132. expect.objectContaining({
  133. data: {
  134. dynamicSamplingBiases: [
  135. {id: DynamicSamplingBiasType.BOOST_LATEST_RELEASES, active: false},
  136. {id: DynamicSamplingBiasType.BOOST_ENVIRONMENTS, active: true},
  137. {id: DynamicSamplingBiasType.BOOST_KEY_TRANSACTIONS, active: true},
  138. {id: DynamicSamplingBiasType.IGNORE_HEALTH_CHECKS, active: true},
  139. ],
  140. },
  141. })
  142. );
  143. });
  144. });