chartFooter.spec.tsx 3.9 KB

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