projectAnrScoreCard.spec.tsx 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. import {initializeOrg} from 'sentry-test/initializeOrg';
  2. import {render, screen, waitFor} from 'sentry-test/reactTestingLibrary';
  3. import type {PageFilters} from 'sentry/types/core';
  4. import {ProjectAnrScoreCard} from 'sentry/views/projectDetail/projectScoreCards/projectAnrScoreCard';
  5. describe('ProjectDetail > ProjectAnr', function () {
  6. let endpointMock: jest.Mock;
  7. let endpointMockPreviousPeriod: jest.Mock;
  8. const {organization, router} = initializeOrg({
  9. router: {
  10. location: {
  11. query: {project: '1', statsPeriod: '7d'},
  12. },
  13. },
  14. });
  15. const selection = {
  16. projects: [1],
  17. environments: [],
  18. datetime: {
  19. period: '7d',
  20. start: null,
  21. end: null,
  22. utc: false,
  23. },
  24. } as PageFilters;
  25. beforeEach(function () {
  26. endpointMock = MockApiClient.addMockResponse({
  27. url: `/organizations/${organization.slug}/sessions/`,
  28. match: [MockApiClient.matchQuery({statsPeriod: '7d'})],
  29. body: {
  30. groups: [
  31. {
  32. by: {},
  33. totals: {
  34. 'anr_rate()': 0.11561866125760649,
  35. },
  36. },
  37. ],
  38. },
  39. status: 200,
  40. });
  41. endpointMockPreviousPeriod = MockApiClient.addMockResponse({
  42. url: `/organizations/${organization.slug}/sessions/`,
  43. match: [MockApiClient.matchQuery({start: '2017-10-03T02:41:20.000'})], // setup mocks a constant current date, so this works
  44. body: {
  45. groups: [
  46. {
  47. by: {},
  48. totals: {
  49. 'anr_rate()': 0.08558558558558559,
  50. },
  51. },
  52. ],
  53. },
  54. status: 200,
  55. });
  56. });
  57. afterEach(function () {
  58. MockApiClient.clearMockResponses();
  59. });
  60. it('calls api with anr rate', async function () {
  61. render(
  62. <ProjectAnrScoreCard
  63. organization={{...organization}}
  64. selection={selection}
  65. isProjectStabilized
  66. query="release:abc"
  67. location={router.location}
  68. />
  69. );
  70. expect(endpointMock).toHaveBeenCalledWith(
  71. `/organizations/${organization.slug}/sessions/`,
  72. expect.objectContaining({
  73. query: {
  74. environment: [],
  75. field: ['anr_rate()'],
  76. includeSeries: '0',
  77. includeTotals: '1',
  78. interval: '1h',
  79. project: [1],
  80. query: 'release:abc',
  81. statsPeriod: '7d',
  82. },
  83. })
  84. );
  85. expect(endpointMockPreviousPeriod).toHaveBeenCalledWith(
  86. `/organizations/${organization.slug}/sessions/`,
  87. expect.objectContaining({
  88. query: {
  89. end: '2017-10-10T02:41:20.000',
  90. environment: [],
  91. field: ['anr_rate()'],
  92. includeSeries: '0',
  93. includeTotals: '1',
  94. interval: '1h',
  95. project: [1],
  96. query: 'release:abc',
  97. start: '2017-10-03T02:41:20.000',
  98. },
  99. })
  100. );
  101. await waitFor(() => expect(screen.getByText('11.56%')).toBeInTheDocument());
  102. await waitFor(() => expect(screen.getByText('3%')).toBeInTheDocument());
  103. });
  104. it('renders open in issues CTA', async function () {
  105. organization.features = ['discover-basic'];
  106. render(
  107. <ProjectAnrScoreCard
  108. organization={{...organization}}
  109. selection={selection}
  110. isProjectStabilized
  111. query="release:abc"
  112. location={router.location}
  113. />,
  114. {
  115. router,
  116. }
  117. );
  118. await waitFor(() => expect(screen.getByText('11.56%')).toBeInTheDocument());
  119. expect(screen.getByRole('button', {name: 'View Issues'})).toHaveAttribute(
  120. 'href',
  121. '/organizations/org-slug/issues/?project=1&query=mechanism%3A%5BANR%2CAppExitInfo%5D%20release%3Aabc&sort=freq&statsPeriod=7d'
  122. );
  123. });
  124. });