dynamicSampling.spec.tsx 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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 {OrganizationContext} from 'sentry/views/organizationContext';
  6. import DynamicSampling from '.';
  7. const ORG_FEATURES = [
  8. 'server-side-sampling',
  9. 'dynamic-sampling-deprecated',
  10. 'dynamic-sampling',
  11. ];
  12. const dynamicSamplingBiases = [
  13. {id: DynamicSamplingBiasType.BOOST_LATEST_RELEASES, active: true},
  14. {id: DynamicSamplingBiasType.BOOST_ENVIRONMENTS, 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(
  44. <OrganizationContext.Provider value={organization}>
  45. <DynamicSampling project={project} />
  46. </OrganizationContext.Provider>
  47. );
  48. expect(screen.getByRole('heading', {name: /Dynamic Sampling/})).toBeInTheDocument();
  49. expect(screen.getAllByRole('checkbox')).toHaveLength(3);
  50. expect(screen.queryByTestId('more-information')).not.toBeInTheDocument();
  51. const prioritizenewReleases = screen.getByRole('checkbox', {
  52. name: 'Prioritize new releases',
  53. });
  54. expect(prioritizenewReleases).toBeEnabled();
  55. expect(prioritizenewReleases).toBeChecked();
  56. const prioritizeDevEnvironments = screen.getByRole('checkbox', {
  57. name: 'Prioritize dev environments',
  58. });
  59. expect(prioritizeDevEnvironments).toBeEnabled();
  60. expect(prioritizeDevEnvironments).toBeChecked();
  61. const ignoreHealthChecks = screen.getByRole('checkbox', {
  62. name: 'Ignore health checks',
  63. });
  64. expect(ignoreHealthChecks).toBeEnabled();
  65. expect(ignoreHealthChecks).toBeChecked();
  66. });
  67. it('renders disabled default UI, when user has not permission to edit', function () {
  68. const {project, organization} = initializeOrg({
  69. ...initializeOrg(),
  70. projects: [
  71. TestStubs.Project({
  72. dynamicSamplingBiases,
  73. }),
  74. ],
  75. organization: {
  76. ...initializeOrg().organization,
  77. features: ORG_FEATURES,
  78. access: [],
  79. },
  80. });
  81. renderMockRequests(organization.slug, project.slug);
  82. render(
  83. <OrganizationContext.Provider value={organization}>
  84. <DynamicSampling project={project} />
  85. </OrganizationContext.Provider>
  86. );
  87. expect(
  88. screen.getByText(
  89. /These settings can only be edited by users with the organization owner, manager, or admin role/
  90. )
  91. ).toBeInTheDocument();
  92. expect(screen.getAllByTestId('more-information')).toHaveLength(3);
  93. const prioritizenewReleases = screen.getByRole('checkbox', {
  94. name: 'Prioritize new releases',
  95. });
  96. expect(prioritizenewReleases).toBeDisabled();
  97. expect(prioritizenewReleases).toBeChecked();
  98. const prioritizeDevEnvironments = screen.getByRole('checkbox', {
  99. name: 'Prioritize dev environments',
  100. });
  101. expect(prioritizeDevEnvironments).toBeDisabled();
  102. expect(prioritizeDevEnvironments).toBeChecked();
  103. const ignoreHealthChecks = screen.getByRole('checkbox', {
  104. name: 'Ignore health checks',
  105. });
  106. expect(ignoreHealthChecks).toBeDisabled();
  107. expect(ignoreHealthChecks).toBeChecked();
  108. });
  109. it('user can toggle option', function () {
  110. const {project, organization} = initializeOrg({
  111. ...initializeOrg(),
  112. projects: [
  113. TestStubs.Project({
  114. dynamicSamplingBiases,
  115. }),
  116. ],
  117. organization: {
  118. ...initializeOrg().organization,
  119. features: ORG_FEATURES,
  120. },
  121. });
  122. const mockRequests = renderMockRequests(organization.slug, project.slug);
  123. render(
  124. <OrganizationContext.Provider value={organization}>
  125. <DynamicSampling project={project} />
  126. </OrganizationContext.Provider>
  127. );
  128. userEvent.click(screen.getByRole('checkbox', {name: 'Prioritize new releases'}));
  129. expect(mockRequests.projectDetails).toHaveBeenCalledWith(
  130. `/projects/${organization.slug}/${project.slug}/`,
  131. expect.objectContaining({
  132. data: {
  133. dynamicSamplingBiases: [
  134. {id: DynamicSamplingBiasType.BOOST_LATEST_RELEASES, active: false},
  135. {id: DynamicSamplingBiasType.BOOST_ENVIRONMENTS, active: true},
  136. {id: DynamicSamplingBiasType.IGNORE_HEALTH_CHECKS, active: true},
  137. ],
  138. },
  139. })
  140. );
  141. });
  142. });