chartFooter.spec.tsx 4.2 KB

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