replaceRouterParams.spec.tsx 1.0 KB

12345678910111213141516171819202122232425262728293031323334
  1. import replaceRouterParams from 'sentry/utils/replaceRouterParams';
  2. const params = {
  3. orgId: 'org-slug',
  4. projectId: 'project-slug',
  5. project: 1234,
  6. };
  7. describe('replaceRouterParams', function () {
  8. it('replaces parameters in a path', function () {
  9. expect(replaceRouterParams('/path/to/:orgId/test', params)).toBe(
  10. '/path/to/org-slug/test'
  11. );
  12. expect(replaceRouterParams('/path/to/:orgId/test/:projectId', params)).toBe(
  13. '/path/to/org-slug/test/project-slug'
  14. );
  15. expect(replaceRouterParams('/path/to/:orgId/test/:project/:projectId', params)).toBe(
  16. '/path/to/org-slug/test/1234/project-slug'
  17. );
  18. });
  19. it('does not replace a path param if it doesnt exist in params object', function () {
  20. expect(replaceRouterParams('/path/to/:invalidId/test/', params)).toBe(
  21. '/path/to/:invalidId/test/'
  22. );
  23. });
  24. it('requires `:` prefix in route path', function () {
  25. expect(replaceRouterParams('/path/to/orgId/test/', params)).toBe(
  26. '/path/to/orgId/test/'
  27. );
  28. });
  29. });