resultsChart.spec.tsx 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. import {LocationFixture} from 'sentry-fixture/locationFixture';
  2. import {OrganizationFixture} from 'sentry-fixture/organization';
  3. import {RouterFixture} from 'sentry-fixture/routerFixture';
  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 = OrganizationFixture({features});
  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={RouterFixture()}
  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. {router: initialData.router}
  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', async function () {
  66. render(
  67. <ResultsChart
  68. router={RouterFixture()}
  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. {router: initialData.router}
  81. );
  82. expect(await screen.findByText(/No Y-Axis selected/)).toBeInTheDocument();
  83. });
  84. });