gitea源码

url.test.ts 1.0KB

1234567891011121314151617181920212223
  1. import {pathEscapeSegments, toOriginUrl} from './url.ts';
  2. test('pathEscapeSegments', () => {
  3. expect(pathEscapeSegments('a/b/c')).toEqual('a/b/c');
  4. expect(pathEscapeSegments('a/b/ c')).toEqual('a/b/%20c');
  5. });
  6. test('toOriginUrl', () => {
  7. const oldLocation = String(window.location);
  8. for (const origin of ['https://example.com', 'https://example.com:3000']) {
  9. window.location.assign(`${origin}/`);
  10. expect(toOriginUrl('/')).toEqual(`${origin}/`);
  11. expect(toOriginUrl('/org/repo.git')).toEqual(`${origin}/org/repo.git`);
  12. expect(toOriginUrl('https://another.com')).toEqual(`${origin}/`);
  13. expect(toOriginUrl('https://another.com/')).toEqual(`${origin}/`);
  14. expect(toOriginUrl('https://another.com/org/repo.git')).toEqual(`${origin}/org/repo.git`);
  15. expect(toOriginUrl('https://another.com:4000')).toEqual(`${origin}/`);
  16. expect(toOriginUrl('https://another.com:4000/')).toEqual(`${origin}/`);
  17. expect(toOriginUrl('https://another.com:4000/org/repo.git')).toEqual(`${origin}/org/repo.git`);
  18. }
  19. window.location.assign(oldLocation);
  20. });