index.spec.tsx 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. import {browserHistory} from 'react-router';
  2. import {ReleaseFixture} from 'sentry-fixture/release';
  3. import {
  4. SessionUserCountByStatus2Fixture,
  5. SessionUserCountByStatusFixture,
  6. } from 'sentry-fixture/sessions';
  7. import {initializeOrg} from 'sentry-test/initializeOrg';
  8. import {act, render, screen, userEvent} from 'sentry-test/reactTestingLibrary';
  9. import type {ReleaseProject} from 'sentry/types';
  10. import ReleaseComparisonChart from 'sentry/views/releases/detail/overview/releaseComparisonChart';
  11. describe('Releases > Detail > Overview > ReleaseComparison', () => {
  12. const {routerContext, 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={{...routerContext.location, query: {}}}
  32. loading={false}
  33. reloading={false}
  34. errored={false}
  35. project={project}
  36. organization={organization}
  37. api={api}
  38. hasHealthData
  39. />,
  40. {context: routerContext}
  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={{...routerContext.location, query: {}}}
  62. loading={false}
  63. reloading={false}
  64. errored={false}
  65. project={project}
  66. organization={organization}
  67. api={api}
  68. hasHealthData
  69. />,
  70. {context: routerContext}
  71. );
  72. await userEvent.click(screen.getByLabelText(/crash free user rate/i));
  73. expect(browserHistory.push).toHaveBeenCalledWith({query: {chart: 'crashFreeUsers'}});
  74. rerender(
  75. <ReleaseComparisonChart
  76. release={release}
  77. releaseSessions={releaseSessions}
  78. allSessions={allSessions}
  79. platform="javascript"
  80. location={{...routerContext.location, query: {chart: 'crashFreeUsers'}}}
  81. loading={false}
  82. reloading={false}
  83. errored={false}
  84. project={project}
  85. organization={organization}
  86. api={api}
  87. hasHealthData
  88. />
  89. );
  90. expect(screen.getByLabelText('Chart Title')).toHaveTextContent(
  91. 'Crash Free User Rate'
  92. );
  93. expect(screen.getByLabelText('Chart Value')).toHaveTextContent(/75% 24\.908%/);
  94. });
  95. it('can expand row to show more charts', async () => {
  96. render(
  97. <ReleaseComparisonChart
  98. release={release}
  99. releaseSessions={releaseSessions}
  100. allSessions={allSessions}
  101. platform="javascript"
  102. location={{...routerContext.location, query: {}}}
  103. loading={false}
  104. reloading={false}
  105. errored={false}
  106. project={project}
  107. organization={organization}
  108. api={api}
  109. hasHealthData
  110. />,
  111. {context: routerContext}
  112. );
  113. for (const toggle of screen.getAllByLabelText(/toggle chart/i)) {
  114. await userEvent.click(toggle);
  115. }
  116. await userEvent.click(screen.getByLabelText(/toggle additional/i));
  117. expect(screen.getAllByRole('radio').length).toBe(12);
  118. // lazy way to make sure that all percentages are calculated correctly
  119. expect(
  120. screen.getByTestId('release-comparison-table').textContent
  121. ).toMatchInlineSnapshot(
  122. `"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
  123. );
  124. // toggle back
  125. for (const toggle of screen.getAllByLabelText(/toggle chart/i)) {
  126. await userEvent.click(toggle);
  127. }
  128. await userEvent.click(screen.getByLabelText(/toggle additional/i));
  129. expect(screen.getAllByRole('radio').length).toBe(2);
  130. });
  131. it('does not show expanders if there is no health data', async () => {
  132. MockApiClient.addMockResponse({
  133. url: `/organizations/${organization.slug}/events-stats/`,
  134. body: [],
  135. });
  136. MockApiClient.addMockResponse({
  137. url: `/organizations/${organization.slug}/events/`,
  138. body: [],
  139. });
  140. MockApiClient.addMockResponse({
  141. url: `/organizations/${organization.slug}/issues-count/`,
  142. body: 0,
  143. });
  144. render(
  145. <ReleaseComparisonChart
  146. release={release}
  147. releaseSessions={null}
  148. allSessions={null}
  149. platform="javascript"
  150. location={{...routerContext.location, query: {}}}
  151. loading={false}
  152. reloading={false}
  153. errored={false}
  154. project={project}
  155. organization={{
  156. ...organization,
  157. features: [...organization.features, 'discover-basic'],
  158. }}
  159. api={api}
  160. hasHealthData={false}
  161. />,
  162. {context: routerContext}
  163. );
  164. expect(screen.getAllByRole('radio').length).toBe(1);
  165. expect(screen.queryByLabelText(/toggle chart/i)).not.toBeInTheDocument();
  166. expect(screen.queryByLabelText(/toggle additional/i)).not.toBeInTheDocument();
  167. // Wait for api requests to propegate
  168. await act(tick);
  169. });
  170. });