projectAnrScoreCard.spec.tsx 3.6 KB

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