resultsChart.spec.tsx 4.0 KB

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