resultsChart.spec.tsx 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. import {mountWithTheme} from 'sentry-test/enzyme';
  2. import {initializeOrg} from 'sentry-test/initializeOrg';
  3. import {act} from 'sentry-test/reactTestingLibrary';
  4. import {t} from 'sentry/locale';
  5. import EventView from 'sentry/utils/discover/eventView';
  6. import {DisplayModes} from 'sentry/utils/discover/types';
  7. import ResultsChart from 'sentry/views/eventsV2/resultsChart';
  8. describe('EventsV2 > ResultsChart', function () {
  9. const features = ['discover-basic'];
  10. const location = TestStubs.location({
  11. query: {query: 'tag:value'},
  12. pathname: '/',
  13. });
  14. let organization, eventView, initialData;
  15. beforeEach(() => {
  16. organization = TestStubs.Organization({
  17. features,
  18. projects: [TestStubs.Project()],
  19. });
  20. initialData = initializeOrg({
  21. organization,
  22. router: {
  23. location,
  24. },
  25. project: 1,
  26. projects: [],
  27. });
  28. eventView = EventView.fromSavedQueryOrLocation(undefined, location);
  29. MockApiClient.addMockResponse({
  30. url: '/organizations/org-slug/releases/stats/',
  31. body: [],
  32. });
  33. MockApiClient.addMockResponse({
  34. url: '/organizations/org-slug/events-stats/',
  35. body: [],
  36. });
  37. });
  38. it('only allows default, daily, previous period, and bar display modes when multiple y axis are selected', function () {
  39. const wrapper = mountWithTheme(
  40. <ResultsChart
  41. router={TestStubs.router()}
  42. disableProcessedBaselineToggle
  43. setShowBaseline={() => undefined}
  44. showBaseline
  45. organization={organization}
  46. eventView={eventView}
  47. location={location}
  48. onAxisChange={() => undefined}
  49. onIntervalChange={() => undefined}
  50. onDisplayChange={() => undefined}
  51. total={1}
  52. confirmedQuery
  53. yAxis={['count()', 'failure_count()']}
  54. onTopEventsChange={() => {}}
  55. />,
  56. initialData.routerContext
  57. );
  58. const displayOptions = wrapper.find('ChartFooter').props().displayOptions;
  59. displayOptions.forEach(({value, disabled}) => {
  60. if (
  61. ![
  62. DisplayModes.DEFAULT,
  63. DisplayModes.DAILY,
  64. DisplayModes.PREVIOUS,
  65. DisplayModes.BAR,
  66. ].includes(value)
  67. ) {
  68. expect(disabled).toBe(true);
  69. }
  70. });
  71. });
  72. it('does not display a chart if no y axis is selected', function () {
  73. const wrapper = mountWithTheme(
  74. <ResultsChart
  75. router={TestStubs.router()}
  76. disableProcessedBaselineToggle
  77. setShowBaseline={() => undefined}
  78. showBaseline
  79. organization={organization}
  80. eventView={eventView}
  81. location={location}
  82. onAxisChange={() => undefined}
  83. onDisplayChange={() => undefined}
  84. onIntervalChange={() => undefined}
  85. total={1}
  86. confirmedQuery
  87. yAxis={[]}
  88. onTopEventsChange={() => {}}
  89. />,
  90. initialData.routerContext
  91. );
  92. expect(wrapper.find('NoChartContainer').children().children().html()).toEqual(
  93. t('No Y-Axis selected.')
  94. );
  95. });
  96. it('disables equation y-axis options when in World Map display mode', async function () {
  97. eventView.display = DisplayModes.WORLDMAP;
  98. eventView.fields = [
  99. {field: 'count()'},
  100. {field: 'count_unique(user)'},
  101. {field: 'equation|count() + 2'},
  102. ];
  103. MockApiClient.addMockResponse({
  104. url: `/organizations/${organization.slug}/events-geo/`,
  105. body: [],
  106. });
  107. const wrapper = mountWithTheme(
  108. <ResultsChart
  109. router={TestStubs.router()}
  110. disableProcessedBaselineToggle
  111. setShowBaseline={() => undefined}
  112. showBaseline
  113. organization={organization}
  114. eventView={eventView}
  115. location={location}
  116. onAxisChange={() => undefined}
  117. onDisplayChange={() => undefined}
  118. onIntervalChange={() => undefined}
  119. total={1}
  120. confirmedQuery
  121. yAxis={['count()']}
  122. onTopEventsChange={() => {}}
  123. />,
  124. initialData.routerContext
  125. );
  126. const yAxisOptions = wrapper.find('ChartFooter').props().yAxisOptions;
  127. expect(yAxisOptions.length).toEqual(2);
  128. expect(yAxisOptions[0].value).toEqual('count()');
  129. expect(yAxisOptions[1].value).toEqual('count_unique(user)');
  130. // Wait for event geo request results to preopgate to update
  131. await act(tick);
  132. });
  133. });