index.spec.tsx 5.9 KB

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