findFirstRouteWithoutRouteParam.spec.jsx 1.4 KB

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