chartFooter.spec.tsx 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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/discover/chartFooter';
  6. describe('Discover > 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. projects: [],
  33. });
  34. const chartFooter = (
  35. <ChartFooter
  36. total={100}
  37. yAxisValue={yAxisValue}
  38. yAxisOptions={yAxisOptions}
  39. onAxisChange={() => undefined}
  40. displayMode={DisplayModes.DEFAULT}
  41. displayOptions={[{label: DisplayModes.DEFAULT, value: DisplayModes.DEFAULT}]}
  42. onDisplayChange={() => undefined}
  43. onTopEventsChange={() => undefined}
  44. onIntervalChange={() => undefined}
  45. topEvents="5"
  46. eventView={eventView}
  47. />
  48. );
  49. render(chartFooter, {context: initialData.routerContext});
  50. expect(
  51. screen.getByRole('button', {
  52. name: `Y-Axis ${yAxisValue[0]} +${
  53. yAxisValue.filter(v => v !== yAxisValue[0]).length
  54. }`,
  55. })
  56. ).toBeInTheDocument();
  57. });
  58. it('renders display limits with default limit when top 5 mode is selected', function () {
  59. const organization = TestStubs.Organization({
  60. features,
  61. });
  62. // Start off with an invalid view (empty is invalid)
  63. const initialData = initializeOrg({
  64. organization,
  65. router: {
  66. location: {query: {query: 'tag:value'}},
  67. },
  68. projects: [],
  69. });
  70. const limit = '5';
  71. const chartFooter = (
  72. <ChartFooter
  73. total={100}
  74. yAxisValue={yAxisValue}
  75. yAxisOptions={yAxisOptions}
  76. onAxisChange={() => undefined}
  77. displayMode={DisplayModes.TOP5}
  78. displayOptions={[{label: DisplayModes.DEFAULT, value: DisplayModes.DEFAULT}]}
  79. onDisplayChange={() => undefined}
  80. onTopEventsChange={() => undefined}
  81. onIntervalChange={() => undefined}
  82. topEvents={limit}
  83. eventView={eventView}
  84. />
  85. );
  86. render(chartFooter, {context: initialData.routerContext});
  87. expect(screen.getByRole('button', {name: `Limit ${limit}`})).toBeInTheDocument();
  88. });
  89. it('renders multi value y-axis dropdown selector on a non-Top display', async function () {
  90. let yAxis = ['count()'];
  91. const chartFooter = (
  92. <ChartFooter
  93. total={100}
  94. yAxisValue={yAxis}
  95. yAxisOptions={yAxisOptions}
  96. onAxisChange={newYAxis => (yAxis = newYAxis)}
  97. displayMode={DisplayModes.DEFAULT}
  98. displayOptions={[{label: DisplayModes.DEFAULT, value: DisplayModes.DEFAULT}]}
  99. onDisplayChange={() => undefined}
  100. onTopEventsChange={() => undefined}
  101. onIntervalChange={() => undefined}
  102. topEvents="5"
  103. eventView={eventView}
  104. />
  105. );
  106. render(chartFooter);
  107. await userEvent.click(screen.getByText('count()'));
  108. await userEvent.click(screen.getByText('failure_count()'));
  109. expect(yAxis).toEqual(['count()', 'failure_count()']);
  110. });
  111. });