index.spec.tsx 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. import {browserHistory} from 'react-router';
  2. import {initializeOrg} from 'sentry-test/initializeOrg';
  3. import {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(3);
  34. // lazy way to make sure that all percentages are calculated correctly
  35. expect(
  36. screen.getByTestId('release-comparison-table').textContent
  37. ).toMatchInlineSnapshot(
  38. // eslint-disable-next-line no-irregular-whitespace
  39. `"DescriptionAll ReleasesThis ReleaseChangeCrash Free Session Rate 99.516%95.006%4.51% Crash Free User Rate 99.908%75%24.908% Session Duration p50 37s195ms—Show 2 Others"`
  40. );
  41. });
  42. it('can change chart by clicking on a row', () => {
  43. const {rerender} = render(
  44. <ReleaseComparisonChart
  45. release={release}
  46. releaseSessions={releaseSessions}
  47. allSessions={allSessions}
  48. platform="javascript"
  49. location={{...routerContext.location, query: {}}}
  50. loading={false}
  51. reloading={false}
  52. errored={false}
  53. project={project}
  54. organization={organization}
  55. api={api}
  56. hasHealthData
  57. />,
  58. {context: routerContext}
  59. );
  60. userEvent.click(screen.getByLabelText(/crash free user rate/i));
  61. expect(browserHistory.push).toHaveBeenCalledWith({query: {chart: 'crashFreeUsers'}});
  62. rerender(
  63. <ReleaseComparisonChart
  64. release={release}
  65. releaseSessions={releaseSessions}
  66. allSessions={allSessions}
  67. platform="javascript"
  68. location={{...routerContext.location, query: {chart: 'crashFreeUsers'}}}
  69. loading={false}
  70. reloading={false}
  71. errored={false}
  72. project={project}
  73. organization={organization}
  74. api={api}
  75. hasHealthData
  76. />
  77. );
  78. expect(screen.getByLabelText('Chart Title')).toHaveTextContent(
  79. 'Crash Free User Rate'
  80. );
  81. expect(screen.getByLabelText('Chart Value')).toHaveTextContent(/75% 24\.908%/);
  82. });
  83. it('can expand row to show more charts', () => {
  84. render(
  85. <ReleaseComparisonChart
  86. release={release}
  87. releaseSessions={releaseSessions}
  88. allSessions={allSessions}
  89. platform="javascript"
  90. location={{...routerContext.location, query: {}}}
  91. loading={false}
  92. reloading={false}
  93. errored={false}
  94. project={project}
  95. organization={organization}
  96. api={api}
  97. hasHealthData
  98. />,
  99. {context: routerContext}
  100. );
  101. screen.getAllByLabelText(/toggle chart/i).forEach(toggle => {
  102. userEvent.click(toggle);
  103. });
  104. userEvent.click(screen.getByLabelText(/toggle additional/i));
  105. expect(screen.getAllByRole('radio').length).toBe(13);
  106. // lazy way to make sure that all percentages are calculated correctly
  107. expect(
  108. screen.getByTestId('release-comparison-table').textContent
  109. ).toMatchInlineSnapshot(
  110. // eslint-disable-next-line no-irregular-whitespace
  111. `"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 Duration p50 37s195ms—Session Count 205k9.8k—User Count 100k361—Hide 2 Others"`
  112. );
  113. // toggle back
  114. screen.getAllByLabelText(/toggle chart/i).forEach(toggle => {
  115. userEvent.click(toggle);
  116. });
  117. userEvent.click(screen.getByLabelText(/toggle additional/i));
  118. expect(screen.getAllByRole('radio').length).toBe(3);
  119. });
  120. it('does not show expanders if there is no health data', () => {
  121. render(
  122. <ReleaseComparisonChart
  123. release={release}
  124. releaseSessions={null}
  125. allSessions={null}
  126. platform="javascript"
  127. location={{...routerContext.location, query: {}}}
  128. loading={false}
  129. reloading={false}
  130. errored={false}
  131. project={project}
  132. organization={{
  133. ...organization,
  134. features: [...organization.features, 'discover-basic'],
  135. }}
  136. api={api}
  137. hasHealthData={false}
  138. />,
  139. {context: routerContext}
  140. );
  141. expect(screen.getAllByRole('radio').length).toBe(1);
  142. expect(screen.queryByLabelText(/toggle chart/i)).not.toBeInTheDocument();
  143. expect(screen.queryByLabelText(/toggle additional/i)).not.toBeInTheDocument();
  144. });
  145. });