projectAnrScoreCard.spec.tsx 3.7 KB

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