index.spec.tsx 6.1 KB

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