dynamicSampling.spec.tsx 4.7 KB

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