dynamicSamplingMetricsAccuracyAlert.spec.tsx 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. import {QueryClient, QueryClientProvider} from '@tanstack/react-query';
  2. import {initializeOrg} from 'sentry-test/initializeOrg';
  3. import {render, screen} from 'sentry-test/reactTestingLibrary';
  4. import {
  5. DynamicSamplingMetricsAccuracyAlert,
  6. dynamicSamplingMetricsAccuracyMessage,
  7. } from './dynamicSamplingMetricsAccuracyAlert';
  8. function ComponentProviders({children}: {children: React.ReactNode}) {
  9. const client = new QueryClient();
  10. return <QueryClientProvider client={client}>{children}</QueryClientProvider>;
  11. }
  12. describe('Dynamic Sampling Alert', function () {
  13. it('does not render if requirements are not met', function () {
  14. const {organization, project} = initializeOrg();
  15. const {rerender} = render(
  16. <ComponentProviders>
  17. <DynamicSamplingMetricsAccuracyAlert
  18. organization={organization}
  19. selectedProject={project}
  20. />
  21. </ComponentProviders>
  22. );
  23. expect(
  24. screen.queryByText(dynamicSamplingMetricsAccuracyMessage)
  25. ).not.toBeInTheDocument(); // required feature flags are not enabled
  26. rerender(
  27. <ComponentProviders>
  28. <DynamicSamplingMetricsAccuracyAlert
  29. organization={{
  30. ...organization,
  31. features: [
  32. 'server-side-sampling',
  33. 'server-side-sampling-ui',
  34. 'dynamic-sampling-performance-cta',
  35. ],
  36. }}
  37. selectedProject={undefined}
  38. />
  39. </ComponentProviders>
  40. );
  41. expect(
  42. screen.queryByText(dynamicSamplingMetricsAccuracyMessage)
  43. ).not.toBeInTheDocument(); // project is undefined
  44. });
  45. it('renders if requirements are met', async function () {
  46. const {organization, project} = initializeOrg();
  47. const statsV2Mock = MockApiClient.addMockResponse({
  48. url: `/organizations/${organization.slug}/stats_v2/`,
  49. method: 'GET',
  50. body: TestStubs.OutcomesWithLowProcessedEvents(),
  51. });
  52. render(
  53. <ComponentProviders>
  54. <DynamicSamplingMetricsAccuracyAlert
  55. organization={{
  56. ...organization,
  57. features: [
  58. 'server-side-sampling',
  59. 'server-side-sampling-ui',
  60. 'dynamic-sampling-performance-cta',
  61. ],
  62. }}
  63. selectedProject={project}
  64. />
  65. </ComponentProviders>
  66. );
  67. expect(
  68. await screen.findByText(dynamicSamplingMetricsAccuracyMessage)
  69. ).toBeInTheDocument();
  70. expect(screen.getByRole('button', {name: 'Adjust Sample Rates'})).toHaveAttribute(
  71. 'href',
  72. `/settings/${organization.slug}/projects/${project.slug}/dynamic-sampling/rules/uniform/?referrer=performance.rate-alert`
  73. );
  74. expect(statsV2Mock).toHaveBeenCalledTimes(1);
  75. });
  76. });