useUserQuery.spec.tsx 1021 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. import {createMemoryHistory, Route, Router, RouterContext} from 'react-router';
  2. import {act, render} from 'sentry-test/reactTestingLibrary';
  3. import {useUserQuery} from 'sentry/views/explore/hooks/useUserQuery';
  4. import {RouteContext} from 'sentry/views/routeContext';
  5. describe('useUserQuery', function () {
  6. it('allows changing user query', function () {
  7. let userQuery, setUserQuery;
  8. function TestPage() {
  9. [userQuery, setUserQuery] = useUserQuery();
  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(userQuery).toEqual(''); // default
  28. act(() => setUserQuery('foo:bar'));
  29. expect(userQuery).toEqual('foo:bar');
  30. });
  31. });