chartFooter.spec.tsx 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. import {mountWithTheme} from 'sentry-test/enzyme';
  2. import {initializeOrg} from 'sentry-test/initializeOrg';
  3. import {render, screen, userEvent} 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 ChartFooter from 'sentry/views/eventsV2/chartFooter';
  8. describe('EventsV2 > ChartFooter', function () {
  9. const features = ['discover-basic'];
  10. const yAxisValue = ['count()', 'failure_count()'];
  11. const yAxisOptions = [
  12. {label: 'count()', value: 'count()'},
  13. {label: 'failure_count()', value: 'failure_count()'},
  14. ];
  15. const project = TestStubs.Project();
  16. const eventView = EventView.fromSavedQuery({
  17. id: '',
  18. name: 'test query',
  19. version: 2,
  20. fields: ['transaction', 'count()'],
  21. projects: [project.id],
  22. });
  23. afterEach(function () {});
  24. it('renders yAxis option using OptionCheckboxSelector using entire yAxisValue', function () {
  25. const organization = TestStubs.Organization({
  26. features: [...features],
  27. });
  28. // Start off with an invalid view (empty is invalid)
  29. const initialData = initializeOrg({
  30. organization,
  31. router: {
  32. location: {query: {query: 'tag:value'}},
  33. },
  34. project: 1,
  35. projects: [],
  36. });
  37. const chartFooter = (
  38. <ChartFooter
  39. organization={organization}
  40. total={100}
  41. yAxisValue={yAxisValue}
  42. yAxisOptions={yAxisOptions}
  43. onAxisChange={() => undefined}
  44. displayMode={DisplayModes.DEFAULT}
  45. displayOptions={[{label: DisplayModes.DEFAULT, value: DisplayModes.DEFAULT}]}
  46. onDisplayChange={() => undefined}
  47. onTopEventsChange={() => undefined}
  48. onIntervalChange={() => undefined}
  49. topEvents="5"
  50. showBaseline={false}
  51. setShowBaseline={() => undefined}
  52. eventView={eventView}
  53. />
  54. );
  55. const wrapper = mountWithTheme(chartFooter, initialData.routerContext);
  56. wrapper.update();
  57. const optionCheckboxSelector = wrapper.find('OptionSelector').last();
  58. expect(optionCheckboxSelector.props().title).toEqual(t('Y-Axis'));
  59. expect(optionCheckboxSelector.props().selected).toEqual(yAxisValue);
  60. });
  61. it('renders display limits with default limit when top 5 mode is selected', async function () {
  62. const organization = TestStubs.Organization({
  63. features,
  64. });
  65. // Start off with an invalid view (empty is invalid)
  66. const initialData = initializeOrg({
  67. organization,
  68. router: {
  69. location: {query: {query: 'tag:value'}},
  70. },
  71. project: 1,
  72. projects: [],
  73. });
  74. const chartFooter = (
  75. <ChartFooter
  76. organization={organization}
  77. total={100}
  78. yAxisValue={yAxisValue}
  79. yAxisOptions={yAxisOptions}
  80. onAxisChange={() => undefined}
  81. displayMode={DisplayModes.TOP5}
  82. displayOptions={[{label: DisplayModes.DEFAULT, value: DisplayModes.DEFAULT}]}
  83. onDisplayChange={() => undefined}
  84. onTopEventsChange={() => undefined}
  85. onIntervalChange={() => undefined}
  86. topEvents="5"
  87. showBaseline={false}
  88. setShowBaseline={() => undefined}
  89. eventView={eventView}
  90. />
  91. );
  92. const wrapper = mountWithTheme(chartFooter, initialData.routerContext);
  93. await tick();
  94. wrapper.update();
  95. const optionSelector = wrapper.find('OptionSelector[title="Limit"]');
  96. expect(optionSelector.props().selected).toEqual('5');
  97. });
  98. it('renders multi value y-axis dropdown selector on a non-Top display', function () {
  99. const organization = TestStubs.Organization({
  100. features,
  101. });
  102. let yAxis = ['count()'];
  103. const chartFooter = (
  104. <ChartFooter
  105. organization={organization}
  106. total={100}
  107. yAxisValue={yAxis}
  108. yAxisOptions={yAxisOptions}
  109. onAxisChange={newYAxis => (yAxis = newYAxis)}
  110. displayMode={DisplayModes.DEFAULT}
  111. displayOptions={[{label: DisplayModes.DEFAULT, value: DisplayModes.DEFAULT}]}
  112. onDisplayChange={() => undefined}
  113. onTopEventsChange={() => undefined}
  114. onIntervalChange={() => undefined}
  115. topEvents="5"
  116. showBaseline={false}
  117. setShowBaseline={() => undefined}
  118. eventView={eventView}
  119. />
  120. );
  121. render(chartFooter);
  122. userEvent.click(screen.getByText('count()'));
  123. userEvent.click(screen.getByText('failure_count()'));
  124. expect(yAxis).toEqual(['count()', 'failure_count()']);
  125. });
  126. });