blob: ef2e5d779d83b4a7a64de8f0932ed7d56cc780ea (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
import { generateRefDestinationPath } from '~/pages/projects/find_file/ref_switcher/ref_switcher_utils';
import setWindowLocation from 'helpers/set_window_location_helper';
const projectRootPath = 'root/Project1';
const selectedRef = 'feature/test';
describe('generateRefDestinationPath', () => {
it.each`
currentPath | result
${`${projectRootPath}/-/find_file/flightjs/Flight`} | ${`http://test.host/${projectRootPath}/-/find_file/${selectedRef}`}
${`${projectRootPath}/-/find_file/test/test1?test=something`} | ${`http://test.host/${projectRootPath}/-/find_file/${selectedRef}?test=something`}
${`${projectRootPath}/-/find_file/simpletest?test=something&test=it`} | ${`http://test.host/${projectRootPath}/-/find_file/${selectedRef}?test=something&test=it`}
${`${projectRootPath}/-/find_file/some_random_char?test=something&test[]=it&test[]=is`} | ${`http://test.host/${projectRootPath}/-/find_file/${selectedRef}?test=something&test[]=it&test[]=is`}
`('generates the correct destination path for $currentPath', ({ currentPath, result }) => {
setWindowLocation(currentPath);
expect(generateRefDestinationPath(selectedRef, '/-/find_file')).toBe(result);
});
it("returns original url if it's missing selectedRef param", () => {
setWindowLocation(`${projectRootPath}/-/find_file/flightjs/Flight`);
expect(generateRefDestinationPath(undefined, '/-/find_file')).toBe(
`http://test.host/${projectRootPath}/-/find_file/flightjs/Flight`,
);
});
it("returns original url if it's missing namespace param", () => {
setWindowLocation(`${projectRootPath}/-/find_file/flightjs/Flight`);
expect(generateRefDestinationPath(selectedRef, undefined)).toBe(
`http://test.host/${projectRootPath}/-/find_file/flightjs/Flight`,
);
});
it("returns original url if it's missing namespace and selectedRef param", () => {
setWindowLocation(`${projectRootPath}/-/find_file/flightjs/Flight`);
expect(generateRefDestinationPath(undefined, undefined)).toBe(
`http://test.host/${projectRootPath}/-/find_file/flightjs/Flight`,
);
});
});
|