resultsChart.spec.tsx 2.9 KB

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