Commit 3b3b705a authored by Filipa Lacerda's avatar Filipa Lacerda

Merge branch 'ide-url-util-relative-url-fix' into 'master'

Fixes IDE button on merge requests not working with relative URL config

Closes #46438

See merge request gitlab-org/gitlab-ce!19546
parents 570c4928 cb6a16a2
...@@ -85,9 +85,9 @@ export function redirectTo(url) { ...@@ -85,9 +85,9 @@ export function redirectTo(url) {
} }
export function webIDEUrl(route = undefined) { export function webIDEUrl(route = undefined) {
let returnUrl = `${gon.relative_url_root}/-/ide/`; let returnUrl = `${gon.relative_url_root || ''}/-/ide/`;
if (route) { if (route) {
returnUrl += `project${route}`; returnUrl += `project${route.replace(new RegExp(`^${gon.relative_url_root || ''}`), '')}`;
} }
return returnUrl; return returnUrl;
} }
---
title: Fixes Web IDE button on merge requests when GitLab is installed with relative
URL
merge_request:
author:
type: fixed
import { webIDEUrl } from '~/lib/utils/url_utility';
describe('URL utility', () => {
describe('webIDEUrl', () => {
afterEach(() => {
gon.relative_url_root = '';
});
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',
);
});
});
});
});
...@@ -12,6 +12,7 @@ describe('MRWidgetHeader', () => { ...@@ -12,6 +12,7 @@ describe('MRWidgetHeader', () => {
afterEach(() => { afterEach(() => {
vm.$destroy(); vm.$destroy();
gon.relative_url_root = '';
}); });
describe('computed', () => { describe('computed', () => {
...@@ -145,7 +146,16 @@ describe('MRWidgetHeader', () => { ...@@ -145,7 +146,16 @@ describe('MRWidgetHeader', () => {
const button = vm.$el.querySelector('.js-web-ide'); const button = vm.$el.querySelector('.js-web-ide');
expect(button.textContent.trim()).toEqual('Web IDE'); expect(button.textContent.trim()).toEqual('Web IDE');
expect(button.getAttribute('href')).toEqual('undefined/-/ide/projectabc'); expect(button.getAttribute('href')).toEqual('/-/ide/projectabc');
});
it('renders web ide button with relative URL', () => {
gon.relative_url_root = '/gitlab';
const button = vm.$el.querySelector('.js-web-ide');
expect(button.textContent.trim()).toEqual('Web IDE');
expect(button.getAttribute('href')).toEqual('/-/ide/projectabc');
}); });
it('renders download dropdown with links', () => { it('renders download dropdown with links', () => {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment