routeSource.spec.jsx 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import {mountWithTheme} from 'sentry-test/enzyme';
  2. import {initializeOrg} from 'sentry-test/initializeOrg';
  3. import {RouteSource} from 'sentry/components/search/sources/routeSource';
  4. describe('RouteSource', function () {
  5. let wrapper;
  6. it('can find a route', async function () {
  7. const mock = jest.fn().mockReturnValue(null);
  8. const {organization, project} = initializeOrg();
  9. wrapper = mountWithTheme(
  10. <RouteSource query="password" {...{organization, project}}>
  11. {mock}
  12. </RouteSource>
  13. );
  14. await tick();
  15. wrapper.update();
  16. const calls = mock.mock.calls;
  17. expect(calls[calls.length - 1][0].results[0].item).toEqual({
  18. description: 'Change your account password and/or two factor authentication',
  19. path: '/settings/account/security/',
  20. resultType: 'route',
  21. sourceType: 'route',
  22. title: 'Security',
  23. to: '/settings/account/security/',
  24. });
  25. });
  26. it('does not find any form field', async function () {
  27. const mock = jest.fn().mockReturnValue(null);
  28. const {organization, project} = initializeOrg();
  29. wrapper = mountWithTheme(
  30. <RouteSource query="invalid" {...{organization, project}}>
  31. {mock}
  32. </RouteSource>
  33. );
  34. await tick();
  35. wrapper.update();
  36. expect(mock).toHaveBeenCalledWith(
  37. expect.objectContaining({
  38. results: [],
  39. })
  40. );
  41. });
  42. });