2018-11-30 04:49:22 -05:00
|
|
|
import { webIDEUrl, mergeUrlParams } from '~/lib/utils/url_utility';
|
2018-06-07 09:47:09 -04:00
|
|
|
|
|
|
|
describe('URL utility', () => {
|
|
|
|
describe('webIDEUrl', () => {
|
2018-06-07 10:11:10 -04:00
|
|
|
afterEach(() => {
|
|
|
|
gon.relative_url_root = '';
|
|
|
|
});
|
|
|
|
|
2018-06-07 09:47:09 -04:00
|
|
|
describe('without relative_url_root', () => {
|
|
|
|
it('returns IDE path with route', () => {
|
|
|
|
expect(webIDEUrl('/gitlab-org/gitlab-ce/merge_requests/1')).toBe(
|
|
|
|
'/-/ide/project/gitlab-org/gitlab-ce/merge_requests/1',
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('with relative_url_root', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
gon.relative_url_root = '/gitlab';
|
|
|
|
});
|
|
|
|
|
|
|
|
it('returns IDE path with route', () => {
|
|
|
|
expect(webIDEUrl('/gitlab/gitlab-org/gitlab-ce/merge_requests/1')).toBe(
|
|
|
|
'/gitlab/-/ide/project/gitlab-org/gitlab-ce/merge_requests/1',
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2018-11-30 04:49:22 -05:00
|
|
|
|
|
|
|
describe('mergeUrlParams', () => {
|
|
|
|
it('adds w', () => {
|
|
|
|
expect(mergeUrlParams({ w: 1 }, '#frag')).toBe('?w=1#frag');
|
|
|
|
expect(mergeUrlParams({ w: 1 }, '/path#frag')).toBe('/path?w=1#frag');
|
|
|
|
expect(mergeUrlParams({ w: 1 }, 'https://host/path')).toBe('https://host/path?w=1');
|
|
|
|
expect(mergeUrlParams({ w: 1 }, 'https://host/path#frag')).toBe('https://host/path?w=1#frag');
|
|
|
|
expect(mergeUrlParams({ w: 1 }, 'https://h/p?k1=v1#frag')).toBe('https://h/p?k1=v1&w=1#frag');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('updates w', () => {
|
|
|
|
expect(mergeUrlParams({ w: 1 }, '?k1=v1&w=0#frag')).toBe('?k1=v1&w=1#frag');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('adds multiple params', () => {
|
|
|
|
expect(mergeUrlParams({ a: 1, b: 2, c: 3 }, '#frag')).toBe('?a=1&b=2&c=3#frag');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('adds and updates encoded params', () => {
|
|
|
|
expect(mergeUrlParams({ a: '&', q: '?' }, '?a=%23#frag')).toBe('?a=%26&q=%3F#frag');
|
|
|
|
});
|
|
|
|
});
|
2018-06-07 09:47:09 -04:00
|
|
|
});
|