index.spec.tsx 6.3 KB

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