useSampleFields.spec.tsx 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import {createMemoryHistory, Route, Router, RouterContext} from 'react-router';
  2. import {act, render} from 'sentry-test/reactTestingLibrary';
  3. import {useSampleFields} from 'sentry/views/explore/hooks/useSampleFields';
  4. import {RouteContext} from 'sentry/views/routeContext';
  5. describe('useSampleFields', function () {
  6. it('allows changing sample fields', function () {
  7. let sampleFields, setSampleFields;
  8. function TestPage() {
  9. [sampleFields, setSampleFields] = useSampleFields();
  10. return null;
  11. }
  12. const memoryHistory = createMemoryHistory();
  13. render(
  14. <Router
  15. history={memoryHistory}
  16. render={props => {
  17. return (
  18. <RouteContext.Provider value={props}>
  19. <RouterContext {...props} />
  20. </RouteContext.Provider>
  21. );
  22. }}
  23. >
  24. <Route path="/" component={TestPage} />
  25. </Router>
  26. );
  27. expect(sampleFields).toEqual([
  28. 'project',
  29. 'id',
  30. 'span.op',
  31. 'span.description',
  32. 'span.duration',
  33. 'timestamp',
  34. ]); // default
  35. act(() => setSampleFields(['foo', 'bar']));
  36. expect(sampleFields).toEqual(['foo', 'bar']);
  37. act(() => setSampleFields([]));
  38. expect(sampleFields).toEqual([
  39. 'project',
  40. 'id',
  41. 'span.op',
  42. 'span.description',
  43. 'span.duration',
  44. 'timestamp',
  45. ]); // default
  46. });
  47. });