useResultsMode.spec.tsx 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. import {OrganizationFixture} from 'sentry-fixture/organization';
  2. import {act, render} from 'sentry-test/reactTestingLibrary';
  3. import {DiscoverDatasets} from 'sentry/utils/discover/types';
  4. import {useGroupBys} from 'sentry/views/explore/hooks/useGroupBys';
  5. import {useResultMode} from 'sentry/views/explore/hooks/useResultsMode';
  6. import {useSampleFields} from 'sentry/views/explore/hooks/useSampleFields';
  7. import {SpanTagsProvider} from '../contexts/spanTagsContext';
  8. describe('useResultMode', function () {
  9. it('allows changing results mode', function () {
  10. let resultMode, setResultMode;
  11. let sampleFields;
  12. let setGroupBys;
  13. const organization = OrganizationFixture();
  14. MockApiClient.addMockResponse({
  15. url: `/organizations/${organization.slug}/spans/fields/`,
  16. method: 'GET',
  17. body: [],
  18. });
  19. function TestPage() {
  20. [sampleFields] = useSampleFields();
  21. ({setGroupBys} = useGroupBys());
  22. [resultMode, setResultMode] = useResultMode();
  23. return null;
  24. }
  25. render(
  26. <SpanTagsProvider dataset={DiscoverDatasets.SPANS_EAP}>
  27. <TestPage />
  28. </SpanTagsProvider>,
  29. {disableRouterMocks: true}
  30. );
  31. expect(resultMode).toEqual('samples'); // default
  32. expect(sampleFields).toEqual([
  33. 'span_id',
  34. 'project',
  35. 'span.op',
  36. 'span.description',
  37. 'span.duration',
  38. 'timestamp',
  39. ]); // default
  40. act(() => setResultMode('aggregate'));
  41. expect(resultMode).toEqual('aggregate');
  42. act(() => setGroupBys(['release', '']));
  43. act(() => setResultMode('samples'));
  44. expect(resultMode).toEqual('samples');
  45. expect(sampleFields).toEqual([
  46. 'span_id',
  47. 'project',
  48. 'span.op',
  49. 'span.description',
  50. 'span.duration',
  51. 'timestamp',
  52. 'release',
  53. ]);
  54. });
  55. });