1 import { replaceLocalURL } from './replaceLocalURL';
3 const replaceLocation = (href: string) => {
4 window = Object.create(window);
6 const url = new URL(href);
8 Object.defineProperty(window, 'location', {
10 hostname: url.hostname,
13 writable: true, // possibility to override
17 describe('replaceLocalURL', () => {
18 const realLocation = window.location;
21 window.location = realLocation;
24 describe('localhost', () => {
26 replaceLocation('https://localhost:8080/u/0');
29 it('should not replace local URLs', () => {
30 const url = 'https://drive-api.proton.me/test';
32 expect(replaceLocalURL(url)).toBe(url);
36 describe('proton.me', () => {
38 replaceLocation('https://drive.proton.me/u/0');
41 it('should not replace local URLs', () => {
42 const url = 'https://drive-api.proton.me/test';
44 expect(replaceLocalURL(url)).toBe(url);
48 describe('proton.local', () => {
50 replaceLocation('https://drive.proton.local/u/0');
54 ['https://drive.proton.black/test', 'https://drive.proton.local/test'],
55 ['https://drive.env.proton.black/test', 'https://drive.proton.local/test'],
56 ['https://drive-api.proton.black/test', 'https://drive-api.proton.local/test'],
57 ['https://drive-api.env.proton.black/test', 'https://drive-api.proton.local/test'],
59 const input = item[0];
60 const output = item[1];
62 it(`${input} => ${output}`, () => {
63 expect(replaceLocalURL(input)).toBe(output);
68 describe('proton.local:8888', () => {
70 replaceLocation('https://drive.proton.local:8888/u/0');
74 ['https://drive.proton.black/test', 'https://drive.proton.local:8888/test'],
75 ['https://drive.env.proton.black/test', 'https://drive.proton.local:8888/test'],
76 ['https://drive-api.proton.black/test', 'https://drive-api.proton.local:8888/test'],
77 ['https://drive-api.env.proton.black/test', 'https://drive-api.proton.local:8888/test'],
79 const input = item[0];
80 const output = item[1];
82 it(`${input} => ${output}`, () => {
83 expect(replaceLocalURL(input)).toBe(output);