index.spec.tsx 6.0 KB

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