resultsChart.spec.tsx 3.7 KB

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