resultsChart.spec.tsx 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. import LocationFixture from 'sentry-fixture/locationFixture';
  2. import {Organization} from 'sentry-fixture/organization';
  3. import {Project as ProjectFixture} from 'sentry-fixture/project';
  4. import {initializeOrg} from 'sentry-test/initializeOrg';
  5. import {render, screen, userEvent} from 'sentry-test/reactTestingLibrary';
  6. import EventView from 'sentry/utils/discover/eventView';
  7. import {DISPLAY_MODE_OPTIONS, DisplayModes} from 'sentry/utils/discover/types';
  8. import ResultsChart from 'sentry/views/discover/resultsChart';
  9. describe('Discover > ResultsChart', function () {
  10. const features = ['discover-basic'];
  11. const location = LocationFixture({
  12. query: {query: 'tag:value'},
  13. pathname: '/',
  14. });
  15. const organization = Organization({
  16. features,
  17. projects: [ProjectFixture()],
  18. });
  19. const initialData = initializeOrg({
  20. organization,
  21. router: {
  22. location,
  23. },
  24. projects: [],
  25. });
  26. const eventView = EventView.fromSavedQueryOrLocation(undefined, location);
  27. beforeEach(() => {
  28. MockApiClient.addMockResponse({
  29. url: '/organizations/org-slug/releases/stats/',
  30. body: [],
  31. });
  32. MockApiClient.addMockResponse({
  33. url: '/organizations/org-slug/events-stats/',
  34. body: [],
  35. });
  36. });
  37. it('only allows default, daily, previous period, and bar display modes when multiple y axis are selected', async function () {
  38. render(
  39. <ResultsChart
  40. router={TestStubs.router()}
  41. organization={organization}
  42. eventView={eventView}
  43. location={location}
  44. onAxisChange={() => undefined}
  45. onIntervalChange={() => undefined}
  46. onDisplayChange={() => undefined}
  47. total={1}
  48. confirmedQuery
  49. yAxis={['count()', 'failure_count()']}
  50. onTopEventsChange={() => {}}
  51. />,
  52. {context: initialData.routerContext}
  53. );
  54. await userEvent.click(screen.getByText(/Display/));
  55. DISPLAY_MODE_OPTIONS.forEach(({value, label}) => {
  56. if (
  57. [
  58. DisplayModes.DEFAULT,
  59. DisplayModes.DAILY,
  60. DisplayModes.PREVIOUS,
  61. DisplayModes.BAR,
  62. ].includes(value as DisplayModes)
  63. ) {
  64. expect(screen.getByRole('option', {name: String(label)})).toBeEnabled();
  65. }
  66. });
  67. });
  68. it('does not display a chart if no y axis is selected', function () {
  69. render(
  70. <ResultsChart
  71. router={TestStubs.router()}
  72. organization={organization}
  73. eventView={eventView}
  74. location={location}
  75. onAxisChange={() => undefined}
  76. onDisplayChange={() => undefined}
  77. onIntervalChange={() => undefined}
  78. total={1}
  79. confirmedQuery
  80. yAxis={[]}
  81. onTopEventsChange={() => {}}
  82. />,
  83. {context: initialData.routerContext}
  84. );
  85. expect(screen.getByText(/No Y-Axis selected/)).toBeInTheDocument();
  86. });
  87. });