resultsChart.spec.tsx 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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. });
  29. it('only allows default, daily, previous period, and bar display modes when multiple y axis are selected', function () {
  30. const wrapper = mountWithTheme(
  31. <ResultsChart
  32. router={TestStubs.router()}
  33. organization={organization}
  34. eventView={eventView}
  35. location={location}
  36. onAxisChange={() => undefined}
  37. onDisplayChange={() => undefined}
  38. total={1}
  39. confirmedQuery
  40. yAxis={['count()', 'failure_count()']}
  41. onTopEventsChange={() => {}}
  42. />,
  43. initialData.routerContext
  44. );
  45. const displayOptions = wrapper.find('ChartFooter').props().displayOptions;
  46. displayOptions.forEach(({value, disabled}) => {
  47. if (
  48. ![
  49. DisplayModes.DEFAULT,
  50. DisplayModes.DAILY,
  51. DisplayModes.PREVIOUS,
  52. DisplayModes.BAR,
  53. ].includes(value)
  54. ) {
  55. expect(disabled).toBe(true);
  56. }
  57. });
  58. });
  59. it('does not display a chart if no y axis is selected', function () {
  60. const wrapper = mountWithTheme(
  61. <ResultsChart
  62. router={TestStubs.router()}
  63. organization={organization}
  64. eventView={eventView}
  65. location={location}
  66. onAxisChange={() => undefined}
  67. onDisplayChange={() => undefined}
  68. total={1}
  69. confirmedQuery
  70. yAxis={[]}
  71. onTopEventsChange={() => {}}
  72. />,
  73. initialData.routerContext
  74. );
  75. expect(wrapper.find('NoChartContainer').children().children().html()).toEqual(
  76. t('No Y-Axis selected.')
  77. );
  78. });
  79. it('disables equation y-axis options when in World Map display mode', function () {
  80. eventView.display = DisplayModes.WORLDMAP;
  81. eventView.fields = [
  82. {field: 'count()'},
  83. {field: 'count_unique(user)'},
  84. {field: 'equation|count() + 2'},
  85. ];
  86. const wrapper = mountWithTheme(
  87. <ResultsChart
  88. router={TestStubs.router()}
  89. organization={organization}
  90. eventView={eventView}
  91. location={location}
  92. onAxisChange={() => undefined}
  93. onDisplayChange={() => undefined}
  94. total={1}
  95. confirmedQuery
  96. yAxis={['count()']}
  97. onTopEventsChange={() => {}}
  98. />,
  99. initialData.routerContext
  100. );
  101. const yAxisOptions = wrapper.find('ChartFooter').props().yAxisOptions;
  102. expect(yAxisOptions.length).toEqual(2);
  103. expect(yAxisOptions[0].value).toEqual('count()');
  104. expect(yAxisOptions[1].value).toEqual('count_unique(user)');
  105. });
  106. });