useVisualize.spec.tsx 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import {createMemoryHistory, Route, Router, RouterContext} from 'react-router';
  2. import {act, render} from 'sentry-test/reactTestingLibrary';
  3. import {useVisualize} from 'sentry/views/explore/hooks/useVisualize';
  4. import {RouteContext} from 'sentry/views/routeContext';
  5. describe('useVisualize', function () {
  6. it('allows changing results mode', function () {
  7. let visualize, setVisualize;
  8. function TestPage() {
  9. [visualize, setVisualize] = useVisualize();
  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(visualize).toEqual('count(span.duration)'); // default
  28. act(() => setVisualize('p75(span.duration)'));
  29. expect(visualize).toEqual('p75(span.duration)');
  30. act(() => setVisualize('count(span.duration)'));
  31. expect(visualize).toEqual('count(span.duration)');
  32. });
  33. });