projectStabilityScoreCard.spec.tsx 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. import {OrganizationFixture} from 'sentry-fixture/organization';
  2. import {render, screen} from 'sentry-test/reactTestingLibrary';
  3. import {SessionFieldWithOperation} from 'sentry/types';
  4. import ProjectStabilityScoreCard from 'sentry/views/projectDetail/projectScoreCards/projectStabilityScoreCard';
  5. describe('ProjectDetail > ProjectStability', function () {
  6. const organization = OrganizationFixture();
  7. const selection = {
  8. projects: [1],
  9. environments: [],
  10. datetime: {
  11. start: null,
  12. end: null,
  13. period: '14d',
  14. utc: null,
  15. },
  16. };
  17. afterEach(function () {
  18. MockApiClient.clearMockResponses();
  19. });
  20. it('renders crash free users', async function () {
  21. const endpointMock = MockApiClient.addMockResponse({
  22. url: `/organizations/${organization.slug}/sessions/`,
  23. body: {
  24. groups: [
  25. {
  26. totals: {
  27. [SessionFieldWithOperation.CRASH_FREE_RATE_USERS]: 0.99,
  28. },
  29. },
  30. ],
  31. },
  32. status: 200,
  33. });
  34. render(
  35. <ProjectStabilityScoreCard
  36. field={SessionFieldWithOperation.CRASH_FREE_RATE_USERS}
  37. hasSessions
  38. selection={selection}
  39. isProjectStabilized
  40. query="test-query"
  41. />
  42. );
  43. expect(await screen.findByText('Crash Free Users')).toBeInTheDocument();
  44. expect(await screen.findByText('99%')).toBeInTheDocument();
  45. expect(endpointMock).toHaveBeenNthCalledWith(
  46. 1,
  47. `/organizations/${organization.slug}/sessions/`,
  48. expect.objectContaining({
  49. query: {
  50. environment: [],
  51. field: SessionFieldWithOperation.CRASH_FREE_RATE_USERS,
  52. project: 1,
  53. interval: '1d',
  54. statsPeriod: '14d',
  55. query: 'test-query',
  56. },
  57. })
  58. );
  59. });
  60. it('renders crash free sessions', async function () {
  61. const endpointMock = MockApiClient.addMockResponse({
  62. url: `/organizations/${organization.slug}/sessions/`,
  63. body: {
  64. groups: [
  65. {
  66. totals: {
  67. [SessionFieldWithOperation.CRASH_FREE_RATE_SESSIONS]: 0.99,
  68. },
  69. },
  70. ],
  71. },
  72. status: 200,
  73. });
  74. render(
  75. <ProjectStabilityScoreCard
  76. field={SessionFieldWithOperation.CRASH_FREE_RATE_SESSIONS}
  77. hasSessions
  78. selection={selection}
  79. isProjectStabilized
  80. query="test-query"
  81. />
  82. );
  83. expect(await screen.findByText('Crash Free Sessions')).toBeInTheDocument();
  84. expect(await screen.findByText('99%')).toBeInTheDocument();
  85. expect(endpointMock).toHaveBeenNthCalledWith(
  86. 1,
  87. `/organizations/${organization.slug}/sessions/`,
  88. expect.objectContaining({
  89. query: {
  90. environment: [],
  91. field: SessionFieldWithOperation.CRASH_FREE_RATE_SESSIONS,
  92. project: 1,
  93. interval: '1d',
  94. statsPeriod: '14d',
  95. query: 'test-query',
  96. },
  97. })
  98. );
  99. });
  100. it('renders without sessions', async function () {
  101. const endpointMock = MockApiClient.addMockResponse({
  102. url: `/organizations/${organization.slug}/sessions/`,
  103. body: {
  104. detail: 'test error',
  105. },
  106. status: 404,
  107. });
  108. render(
  109. <ProjectStabilityScoreCard
  110. field={SessionFieldWithOperation.CRASH_FREE_RATE_SESSIONS}
  111. hasSessions={false}
  112. selection={selection}
  113. isProjectStabilized
  114. query="test-query"
  115. />
  116. );
  117. expect(await screen.findByText('Crash Free Sessions')).toBeInTheDocument();
  118. expect(await screen.findByText('Start Setup')).toBeInTheDocument();
  119. expect(endpointMock).not.toHaveBeenCalled();
  120. });
  121. });