resultsChart.spec.tsx 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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 {DISPLAY_MODE_OPTIONS, DisplayModes} from 'sentry/utils/discover/types';
  6. import ResultsChart from 'sentry/views/discover/resultsChart';
  7. describe('Discover > ResultsChart', function () {
  8. const features = ['discover-basic'];
  9. const location = TestStubs.location({
  10. query: {query: 'tag:value'},
  11. pathname: '/',
  12. });
  13. const organization = Organization({
  14. features,
  15. projects: [TestStubs.Project()],
  16. });
  17. const initialData = initializeOrg({
  18. organization,
  19. router: {
  20. location,
  21. },
  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. });