projectAnrScoreCard.spec.tsx 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. import {render, screen, waitFor} from 'sentry-test/reactTestingLibrary';
  2. import {PageFilters} from 'sentry/types';
  3. import {ProjectAnrScoreCard} from 'sentry/views/projectDetail/projectScoreCards/projectAnrScoreCard';
  4. describe('ProjectDetail > ProjectAnr', function () {
  5. let endpointMock, endpointMockPreviousPeriod;
  6. const organization = TestStubs.Organization();
  7. const selection = {
  8. projects: [1],
  9. environments: [],
  10. datetime: {
  11. period: '7d',
  12. start: null,
  13. end: null,
  14. utc: false,
  15. },
  16. } as PageFilters;
  17. beforeEach(function () {
  18. endpointMock = MockApiClient.addMockResponse({
  19. url: `/organizations/${organization.slug}/sessions/`,
  20. match: [MockApiClient.matchQuery({statsPeriod: '7d'})],
  21. body: {
  22. groups: [
  23. {
  24. by: {},
  25. totals: {
  26. 'foreground_anr_rate()': 0.11561866125760649,
  27. },
  28. },
  29. ],
  30. },
  31. status: 200,
  32. });
  33. endpointMockPreviousPeriod = MockApiClient.addMockResponse({
  34. url: `/organizations/${organization.slug}/sessions/`,
  35. match: [MockApiClient.matchQuery({start: '2017-10-03T02:41:20.000'})], // setup mocks a constant current date, so this works
  36. body: {
  37. groups: [
  38. {
  39. by: {},
  40. totals: {
  41. 'foreground_anr_rate()': 0.08558558558558559,
  42. },
  43. },
  44. ],
  45. },
  46. status: 200,
  47. });
  48. });
  49. afterEach(function () {
  50. MockApiClient.clearMockResponses();
  51. });
  52. it('calls api with anr rate', async function () {
  53. render(
  54. <ProjectAnrScoreCard
  55. organization={{...organization}}
  56. selection={selection}
  57. isProjectStabilized
  58. query="release:abc"
  59. />
  60. );
  61. expect(endpointMock).toHaveBeenCalledWith(
  62. `/organizations/${organization.slug}/sessions/`,
  63. expect.objectContaining({
  64. query: {
  65. environment: [],
  66. field: ['foreground_anr_rate()'],
  67. includeSeries: '0',
  68. includeTotals: '1',
  69. interval: '1h',
  70. project: [1],
  71. query: 'release:abc',
  72. statsPeriod: '7d',
  73. },
  74. })
  75. );
  76. expect(endpointMockPreviousPeriod).toHaveBeenCalledWith(
  77. `/organizations/${organization.slug}/sessions/`,
  78. expect.objectContaining({
  79. query: {
  80. end: '2017-10-10T02:41:20.000',
  81. environment: [],
  82. field: ['foreground_anr_rate()'],
  83. includeSeries: '0',
  84. includeTotals: '1',
  85. interval: '1h',
  86. project: [1],
  87. query: 'release:abc',
  88. start: '2017-10-03T02:41:20.000',
  89. },
  90. })
  91. );
  92. await waitFor(() => expect(screen.getByText('11.562%')).toBeInTheDocument());
  93. await waitFor(() => expect(screen.getByText('0.03%')).toBeInTheDocument());
  94. });
  95. });