useResultsMode.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 {useResultMode} from 'sentry/views/explore/hooks/useResultsMode';
  4. import {RouteContext} from 'sentry/views/routeContext';
  5. describe('useResultMode', function () {
  6. it('allows changing results mode', function () {
  7. let resultMode, setResultMode;
  8. function TestPage() {
  9. [resultMode, setResultMode] = useResultMode();
  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(resultMode).toEqual('samples'); // default
  28. act(() => setResultMode('aggregate'));
  29. expect(resultMode).toEqual('aggregate');
  30. act(() => setResultMode('samples'));
  31. expect(resultMode).toEqual('samples');
  32. });
  33. });