resultsChart.spec.tsx 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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 {DISPLAY_MODE_OPTIONS, DisplayModes} from 'sentry/utils/discover/types';
  5. import ResultsChart from 'sentry/views/discover/resultsChart';
  6. describe('Discover > ResultsChart', function () {
  7. const features = ['discover-basic'];
  8. const location = TestStubs.location({
  9. query: {query: 'tag:value'},
  10. pathname: '/',
  11. });
  12. const organization = TestStubs.Organization({
  13. features,
  14. projects: [TestStubs.Project()],
  15. });
  16. const initialData = initializeOrg({
  17. organization,
  18. router: {
  19. location,
  20. },
  21. project: 1,
  22. projects: [],
  23. });
  24. const eventView = EventView.fromSavedQueryOrLocation(undefined, location);
  25. beforeEach(() => {
  26. MockApiClient.addMockResponse({
  27. url: '/organizations/org-slug/releases/stats/',
  28. body: [],
  29. });
  30. MockApiClient.addMockResponse({
  31. url: '/organizations/org-slug/events-stats/',
  32. body: [],
  33. });
  34. });
  35. it('only allows default, daily, previous period, and bar display modes when multiple y axis are selected', async function () {
  36. render(
  37. <ResultsChart
  38. router={TestStubs.router()}
  39. organization={organization}
  40. eventView={eventView}
  41. location={location}
  42. onAxisChange={() => undefined}
  43. onIntervalChange={() => undefined}
  44. onDisplayChange={() => undefined}
  45. total={1}
  46. confirmedQuery
  47. yAxis={['count()', 'failure_count()']}
  48. onTopEventsChange={() => {}}
  49. />,
  50. {context: initialData.routerContext}
  51. );
  52. await userEvent.click(screen.getByText(/Display/));
  53. DISPLAY_MODE_OPTIONS.forEach(({value, label}) => {
  54. if (
  55. [
  56. DisplayModes.DEFAULT,
  57. DisplayModes.DAILY,
  58. DisplayModes.PREVIOUS,
  59. DisplayModes.BAR,
  60. ].includes(value as DisplayModes)
  61. ) {
  62. expect(screen.getByRole('option', {name: String(label)})).toBeEnabled();
  63. }
  64. });
  65. });
  66. it('does not display a chart if no y axis is selected', function () {
  67. render(
  68. <ResultsChart
  69. router={TestStubs.router()}
  70. organization={organization}
  71. eventView={eventView}
  72. location={location}
  73. onAxisChange={() => undefined}
  74. onDisplayChange={() => undefined}
  75. onIntervalChange={() => undefined}
  76. total={1}
  77. confirmedQuery
  78. yAxis={[]}
  79. onTopEventsChange={() => {}}
  80. />,
  81. {context: initialData.routerContext}
  82. );
  83. expect(screen.getByText(/No Y-Axis selected/)).toBeInTheDocument();
  84. });
  85. it('disables equation y-axis options when in World Map display mode', async function () {
  86. eventView.display = DisplayModes.WORLDMAP;
  87. eventView.fields = [
  88. {field: 'count()'},
  89. {field: 'count_unique(user)'},
  90. {field: 'equation|count() + 2'},
  91. ];
  92. MockApiClient.addMockResponse({
  93. url: `/organizations/${organization.slug}/events-geo/`,
  94. body: [],
  95. });
  96. render(
  97. <ResultsChart
  98. router={TestStubs.router()}
  99. organization={organization}
  100. eventView={eventView}
  101. location={location}
  102. onAxisChange={() => undefined}
  103. onDisplayChange={() => undefined}
  104. onIntervalChange={() => undefined}
  105. total={1}
  106. confirmedQuery
  107. yAxis={['count()']}
  108. onTopEventsChange={() => {}}
  109. />,
  110. {context: initialData.routerContext}
  111. );
  112. await userEvent.click(await screen.findByText(/Y-Axis/));
  113. expect(screen.getAllByRole('option')).toHaveLength(2);
  114. expect(screen.getByRole('option', {name: 'count()'})).toBeEnabled();
  115. expect(screen.getByRole('option', {name: 'count_unique(user)'})).toBeEnabled();
  116. });
  117. });