Commit 437b46b9 authored by Filipa Lacerda's avatar Filipa Lacerda

Merge branch '27343-autocomplete-post-to-wrong-url-when-not-hosting-in-root' into 'master'

Fix filtered search user autocomplete for gitlab instances that are hosted on a subdirectory

Closes #27343

See merge request !8891
parents f54917f1 e369323d
...@@ -8,7 +8,7 @@ require('./filtered_search_dropdown'); ...@@ -8,7 +8,7 @@ require('./filtered_search_dropdown');
super(droplab, dropdown, input, filter); super(droplab, dropdown, input, filter);
this.config = { this.config = {
droplabAjaxFilter: { droplabAjaxFilter: {
endpoint: '/autocomplete/users.json', endpoint: `${gon.relative_url_root || ''}/autocomplete/users.json`,
searchKey: 'search', searchKey: 'search',
params: { params: {
per_page: 20, per_page: 20,
......
---
title: Fix filtered search user autocomplete for gitlab instances that are hosted
on a subdirectory
merge_request: 8891
author:
...@@ -36,5 +36,40 @@ require('~/filtered_search/dropdown_user'); ...@@ -36,5 +36,40 @@ require('~/filtered_search/dropdown_user');
expect(dropdownUser.getSearchInput()).toBe('larry boy'); expect(dropdownUser.getSearchInput()).toBe('larry boy');
}); });
}); });
describe('config droplabAjaxFilter\'s endpoint', () => {
beforeEach(() => {
spyOn(gl.FilteredSearchDropdown.prototype, 'constructor').and.callFake(() => {});
spyOn(gl.DropdownUser.prototype, 'getProjectId').and.callFake(() => {});
});
it('should return endpoint', () => {
window.gon = {
relative_url_root: '',
};
const dropdown = new gl.DropdownUser();
expect(dropdown.config.droplabAjaxFilter.endpoint).toBe('/autocomplete/users.json');
});
it('should return endpoint when relative_url_root is undefined', () => {
const dropdown = new gl.DropdownUser();
expect(dropdown.config.droplabAjaxFilter.endpoint).toBe('/autocomplete/users.json');
});
it('should return endpoint with relative url when available', () => {
window.gon = {
relative_url_root: '/gitlab_directory',
};
const dropdown = new gl.DropdownUser();
expect(dropdown.config.droplabAjaxFilter.endpoint).toBe('/gitlab_directory/autocomplete/users.json');
});
afterEach(() => {
window.gon = {};
});
});
}); });
})(); })();
...@@ -9,19 +9,20 @@ require('~/project_select'); ...@@ -9,19 +9,20 @@ require('~/project_select');
require('~/project'); require('~/project');
(function() { (function() {
window.gon || (window.gon = {});
window.gon.api_version = 'v3';
describe('Project Title', function() { describe('Project Title', function() {
preloadFixtures('static/project_title.html.raw'); preloadFixtures('static/project_title.html.raw');
loadJSONFixtures('projects.json'); loadJSONFixtures('projects.json');
beforeEach(function() { beforeEach(function() {
loadFixtures('static/project_title.html.raw'); loadFixtures('static/project_title.html.raw');
window.gon = {};
window.gon.api_version = 'v3';
return this.project = new Project(); return this.project = new Project();
}); });
return describe('project list', function() {
describe('project list', function() {
var fakeAjaxResponse = function fakeAjaxResponse(req) { var fakeAjaxResponse = function fakeAjaxResponse(req) {
var d; var d;
expect(req.url).toBe('/api/v3/projects.json?simple=true'); expect(req.url).toBe('/api/v3/projects.json?simple=true');
...@@ -48,5 +49,9 @@ require('~/project'); ...@@ -48,5 +49,9 @@ require('~/project');
return expect($('.header-content').hasClass('open')).toBe(false); return expect($('.header-content').hasClass('open')).toBe(false);
}); });
}); });
afterEach(() => {
window.gon = {};
});
}); });
}).call(this); }).call(this);
...@@ -14,11 +14,6 @@ require('vendor/fuzzaldrin-plus'); ...@@ -14,11 +14,6 @@ require('vendor/fuzzaldrin-plus');
userId = 1; userId = 1;
window.gon || (window.gon = {});
window.gon.current_user_id = userId;
window.gon.current_username = userName;
dashboardIssuesPath = '/dashboard/issues'; dashboardIssuesPath = '/dashboard/issues';
dashboardMRsPath = '/dashboard/merge_requests'; dashboardMRsPath = '/dashboard/merge_requests';
...@@ -117,6 +112,16 @@ require('vendor/fuzzaldrin-plus'); ...@@ -117,6 +112,16 @@ require('vendor/fuzzaldrin-plus');
widget = new gl.SearchAutocomplete; widget = new gl.SearchAutocomplete;
// Prevent turbolinks from triggering within gl_dropdown // Prevent turbolinks from triggering within gl_dropdown
spyOn(window.gl.utils, 'visitUrl').and.returnValue(true); spyOn(window.gl.utils, 'visitUrl').and.returnValue(true);
window.gon = {};
window.gon.current_user_id = userId;
window.gon.current_username = userName;
return widget = new gl.SearchAutocomplete;
});
afterEach(function() {
window.gon = {};
}); });
it('should show Dashboard specific dropdown menu', function() { it('should show Dashboard specific dropdown menu', function() {
var list; var list;
......
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