index.spec.tsx 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. import {ReleaseFixture} from 'sentry-fixture/release';
  2. import {
  3. SessionUserCountByStatus2Fixture,
  4. SessionUserCountByStatusFixture,
  5. } from 'sentry-fixture/sessions';
  6. import {initializeOrg} from 'sentry-test/initializeOrg';
  7. import {act, render, screen, userEvent} from 'sentry-test/reactTestingLibrary';
  8. import type {ReleaseProject} from 'sentry/types/release';
  9. import ReleaseComparisonChart from 'sentry/views/releases/detail/overview/releaseComparisonChart';
  10. describe('Releases > Detail > Overview > ReleaseComparison', () => {
  11. const {router, organization, project: rawProject} = initializeOrg();
  12. const api = new MockApiClient();
  13. const release = ReleaseFixture();
  14. const releaseSessions = SessionUserCountByStatusFixture();
  15. const allSessions = SessionUserCountByStatus2Fixture();
  16. const project: ReleaseProject = {
  17. ...rawProject,
  18. id: parseInt(rawProject.id, 10),
  19. newGroups: 0,
  20. platform: 'java',
  21. platforms: ['java'],
  22. };
  23. it('displays correct all/release/change data', () => {
  24. render(
  25. <ReleaseComparisonChart
  26. release={release}
  27. releaseSessions={releaseSessions}
  28. allSessions={allSessions}
  29. platform="javascript"
  30. location={{...router.location, query: {}}}
  31. loading={false}
  32. reloading={false}
  33. errored={false}
  34. project={project}
  35. organization={organization}
  36. api={api}
  37. hasHealthData
  38. />,
  39. {router}
  40. );
  41. expect(screen.getByLabelText('Chart Title')).toHaveTextContent(
  42. 'Crash Free Session Rate'
  43. );
  44. expect(screen.getByLabelText('Chart Value')).toHaveTextContent(/95\.006% 4\.51%/);
  45. expect(screen.getAllByRole('radio')).toHaveLength(2);
  46. // lazy way to make sure that all percentages are calculated correctly
  47. expect(
  48. screen.getByTestId('release-comparison-table').textContent
  49. ).toMatchInlineSnapshot(
  50. `"DescriptionAll ReleasesThis ReleaseChangeCrash Free Session Rate 99.516%95.006%4.51% Crash Free User Rate 99.908%75%24.908% Show 2 Others"` // eslint-disable-line no-irregular-whitespace
  51. );
  52. });
  53. it('can change chart by clicking on a row', async () => {
  54. const {rerender} = render(
  55. <ReleaseComparisonChart
  56. release={release}
  57. releaseSessions={releaseSessions}
  58. allSessions={allSessions}
  59. platform="javascript"
  60. location={{...router.location, query: {}}}
  61. loading={false}
  62. reloading={false}
  63. errored={false}
  64. project={project}
  65. organization={organization}
  66. api={api}
  67. hasHealthData
  68. />,
  69. {router}
  70. );
  71. await userEvent.click(screen.getByLabelText(/crash free user rate/i));
  72. expect(router.push).toHaveBeenCalledWith(
  73. expect.objectContaining({query: {chart: 'crashFreeUsers'}})
  74. );
  75. rerender(
  76. <ReleaseComparisonChart
  77. release={release}
  78. releaseSessions={releaseSessions}
  79. allSessions={allSessions}
  80. platform="javascript"
  81. location={{...router.location, query: {chart: 'crashFreeUsers'}}}
  82. loading={false}
  83. reloading={false}
  84. errored={false}
  85. project={project}
  86. organization={organization}
  87. api={api}
  88. hasHealthData
  89. />
  90. );
  91. expect(screen.getByLabelText('Chart Title')).toHaveTextContent(
  92. 'Crash Free User Rate'
  93. );
  94. expect(screen.getByLabelText('Chart Value')).toHaveTextContent(/75% 24\.908%/);
  95. });
  96. it('can expand row to show more charts', async () => {
  97. render(
  98. <ReleaseComparisonChart
  99. release={release}
  100. releaseSessions={releaseSessions}
  101. allSessions={allSessions}
  102. platform="javascript"
  103. location={{...router.location, query: {}}}
  104. loading={false}
  105. reloading={false}
  106. errored={false}
  107. project={project}
  108. organization={organization}
  109. api={api}
  110. hasHealthData
  111. />,
  112. {router}
  113. );
  114. for (const toggle of screen.getAllByLabelText(/toggle chart/i)) {
  115. await userEvent.click(toggle);
  116. }
  117. await userEvent.click(screen.getByLabelText(/toggle additional/i));
  118. expect(screen.getAllByRole('radio')).toHaveLength(12);
  119. // lazy way to make sure that all percentages are calculated correctly
  120. expect(
  121. screen.getByTestId('release-comparison-table').textContent
  122. ).toMatchInlineSnapshot(
  123. `"DescriptionAll ReleasesThis ReleaseChangeCrash Free Session Rate 99.516%95.006%4.51% Healthy 98.564%94.001%4.563% Abnormal 0%0%0% Errored 0.953%1.005%0.052% Crashed Session Rate 0.484%4.994%4.511% Crash Free User Rate 99.908%75%24.908% Healthy 98.994%72.022%26.972% Abnormal 0%0%0% Errored 0.914%2.493%1.579% Crashed User Rate 0.092%25.485%25.393% Session Count 205k9.8k—User Count 100k361—Hide 2 Others"` // eslint-disable-line no-irregular-whitespace
  124. );
  125. // toggle back
  126. for (const toggle of screen.getAllByLabelText(/toggle chart/i)) {
  127. await userEvent.click(toggle);
  128. }
  129. await userEvent.click(screen.getByLabelText(/toggle additional/i));
  130. expect(screen.getAllByRole('radio')).toHaveLength(2);
  131. });
  132. it('does not show expanders if there is no health data', async () => {
  133. MockApiClient.addMockResponse({
  134. url: `/organizations/${organization.slug}/events-stats/`,
  135. body: [],
  136. });
  137. MockApiClient.addMockResponse({
  138. url: `/organizations/${organization.slug}/events/`,
  139. body: [],
  140. });
  141. MockApiClient.addMockResponse({
  142. url: `/organizations/${organization.slug}/issues-count/`,
  143. body: 0,
  144. });
  145. render(
  146. <ReleaseComparisonChart
  147. release={release}
  148. releaseSessions={null}
  149. allSessions={null}
  150. platform="javascript"
  151. location={{...router.location, query: {}}}
  152. loading={false}
  153. reloading={false}
  154. errored={false}
  155. project={project}
  156. organization={{
  157. ...organization,
  158. features: [...organization.features, 'discover-basic'],
  159. }}
  160. api={api}
  161. hasHealthData={false}
  162. />,
  163. {router}
  164. );
  165. expect(screen.getAllByRole('radio')).toHaveLength(1);
  166. expect(screen.queryByLabelText(/toggle chart/i)).not.toBeInTheDocument();
  167. expect(screen.queryByLabelText(/toggle additional/i)).not.toBeInTheDocument();
  168. // Wait for api requests to propegate
  169. await act(tick);
  170. });
  171. });