findFirstRouteWithoutRouteParam.spec.tsx 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. import findFirstRouteWithoutRouteParam from 'sentry/views/settings/components/settingsBreadcrumb/findFirstRouteWithoutRouteParam';
  2. import {RouteWithName} from './types';
  3. describe('findFirstRouteWithoutRouteParam', function () {
  4. const routes: RouteWithName[] = [
  5. {path: '/'},
  6. {},
  7. {path: '/foo/'},
  8. {},
  9. {path: ':bar'},
  10. {path: '/settings/', name: 'Settings'},
  11. {name: 'Organizations', path: ':orgId/'},
  12. {},
  13. {path: 'api-keys/', name: 'API Key'},
  14. {path: ':apiKey/', name: 'API Key Details'},
  15. ];
  16. it('finds the first route', function () {
  17. expect(findFirstRouteWithoutRouteParam(routes)?.path).toBe('/');
  18. });
  19. it('finds the first route after the given route', function () {
  20. expect(findFirstRouteWithoutRouteParam(routes, routes[2])?.path).toBe('/foo/');
  21. expect(findFirstRouteWithoutRouteParam(routes, routes[6])?.path).toBe('api-keys/');
  22. expect(findFirstRouteWithoutRouteParam(routes, routes[8])?.path).toBe('api-keys/');
  23. });
  24. it('does not include routes that have any url parameters', function () {
  25. const r = [
  26. {path: '/settings/', name: 'Settings'},
  27. {name: 'Organizations', path: ':orgId/'},
  28. {path: 'api-keys/:apiKey/', name: 'API Key Details'},
  29. ];
  30. expect(findFirstRouteWithoutRouteParam(r, r[1])?.path).toBe(':orgId/');
  31. });
  32. });