resultsChart.spec.tsx 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. });