code.gitea.io/gitea@v1.21.7/web_src/js/webcomponents/GiteaOriginUrl.test.js (about) 1 import {toOriginUrl} from './GiteaOriginUrl.js'; 2 3 test('toOriginUrl', () => { 4 const oldLocation = window.location; 5 for (const origin of ['https://example.com', 'https://example.com:3000']) { 6 window.location = new URL(`${origin}/`); 7 expect(toOriginUrl('/')).toEqual(`${origin}/`); 8 expect(toOriginUrl('/org/repo.git')).toEqual(`${origin}/org/repo.git`); 9 expect(toOriginUrl('https://another.com')).toEqual(`${origin}/`); 10 expect(toOriginUrl('https://another.com/')).toEqual(`${origin}/`); 11 expect(toOriginUrl('https://another.com/org/repo.git')).toEqual(`${origin}/org/repo.git`); 12 expect(toOriginUrl('https://another.com:4000')).toEqual(`${origin}/`); 13 expect(toOriginUrl('https://another.com:4000/')).toEqual(`${origin}/`); 14 expect(toOriginUrl('https://another.com:4000/org/repo.git')).toEqual(`${origin}/org/repo.git`); 15 } 16 window.location = oldLocation; 17 });