useGroupBys.spec.tsx 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. import {OrganizationFixture} from 'sentry-fixture/organization';
  2. import {act, render, waitFor} from 'sentry-test/reactTestingLibrary';
  3. import {DiscoverDatasets} from 'sentry/utils/discover/types';
  4. import {useGroupBys} from 'sentry/views/explore/hooks/useGroupBys';
  5. import {SpanTagsProvider} from '../contexts/spanTagsContext';
  6. describe('useGroupBys', function () {
  7. it('allows changing group bys', async function () {
  8. const organization = OrganizationFixture();
  9. const mockSpanTagsApiCall = MockApiClient.addMockResponse({
  10. url: `/organizations/${organization.slug}/spans/fields/`,
  11. method: 'GET',
  12. body: [
  13. {
  14. key: 'foo',
  15. name: 'Foo',
  16. },
  17. {
  18. key: 'bar',
  19. name: 'Bar',
  20. },
  21. ],
  22. });
  23. let groupBys, setGroupBys;
  24. function TestPage() {
  25. ({groupBys, setGroupBys} = useGroupBys());
  26. return null;
  27. }
  28. render(
  29. <SpanTagsProvider dataset={DiscoverDatasets.SPANS_EAP}>
  30. <TestPage />
  31. </SpanTagsProvider>,
  32. {disableRouterMocks: true}
  33. );
  34. await waitFor(() => expect(mockSpanTagsApiCall).toHaveBeenCalled());
  35. expect(groupBys).toEqual(['']); // default
  36. act(() => setGroupBys(['foo', 'bar']));
  37. expect(groupBys).toEqual(['foo', 'bar']);
  38. act(() => setGroupBys([]));
  39. expect(groupBys).toEqual(['']); // default
  40. });
  41. });