chartFooter.spec.tsx 3.9 KB

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