2017-01-10 23:02:20 +00:00
|
|
|
/* eslint-disable space-before-function-paren, max-len, no-var, one-var, one-var-declaration-per-line, no-unused-expressions, consistent-return, no-param-reassign, default-case, no-return-assign, comma-dangle, object-shorthand, prefer-template, quotes, new-parens, vars-on-top, new-cap, max-len */
|
2016-07-24 20:45:11 +00:00
|
|
|
|
|
|
|
/*= require gl_dropdown */
|
|
|
|
/*= require search_autocomplete */
|
|
|
|
/*= require jquery */
|
|
|
|
/*= require lib/utils/common_utils */
|
|
|
|
/*= require lib/utils/type_utility */
|
|
|
|
/*= require fuzzaldrin-plus */
|
2016-10-02 22:11:08 +00:00
|
|
|
/*= require turbolinks */
|
|
|
|
/*= require jquery.turbolinks */
|
2016-07-24 20:45:11 +00:00
|
|
|
|
|
|
|
(function() {
|
|
|
|
var addBodyAttributes, assertLinks, dashboardIssuesPath, dashboardMRsPath, groupIssuesPath, groupMRsPath, groupName, mockDashboardOptions, mockGroupOptions, mockProjectOptions, projectIssuesPath, projectMRsPath, projectName, userId, widget;
|
2016-12-15 14:34:34 +00:00
|
|
|
var userName = 'root';
|
2016-07-24 20:45:11 +00:00
|
|
|
|
|
|
|
widget = null;
|
|
|
|
|
|
|
|
userId = 1;
|
|
|
|
|
|
|
|
window.gon || (window.gon = {});
|
|
|
|
|
|
|
|
window.gon.current_user_id = userId;
|
2016-12-15 14:34:34 +00:00
|
|
|
window.gon.current_username = userName;
|
2016-07-24 20:45:11 +00:00
|
|
|
|
|
|
|
dashboardIssuesPath = '/dashboard/issues';
|
|
|
|
|
|
|
|
dashboardMRsPath = '/dashboard/merge_requests';
|
|
|
|
|
|
|
|
projectIssuesPath = '/gitlab-org/gitlab-ce/issues';
|
|
|
|
|
|
|
|
projectMRsPath = '/gitlab-org/gitlab-ce/merge_requests';
|
|
|
|
|
|
|
|
groupIssuesPath = '/groups/gitlab-org/issues';
|
|
|
|
|
|
|
|
groupMRsPath = '/groups/gitlab-org/merge_requests';
|
|
|
|
|
|
|
|
projectName = 'GitLab Community Edition';
|
|
|
|
|
|
|
|
groupName = 'Gitlab Org';
|
|
|
|
|
2016-07-27 03:32:10 +00:00
|
|
|
// Add required attributes to body before starting the test.
|
|
|
|
// section would be dashboard|group|project
|
2016-07-24 20:45:11 +00:00
|
|
|
addBodyAttributes = function(section) {
|
|
|
|
var $body;
|
|
|
|
if (section == null) {
|
|
|
|
section = 'dashboard';
|
|
|
|
}
|
|
|
|
$body = $('body');
|
|
|
|
$body.removeAttr('data-page');
|
|
|
|
$body.removeAttr('data-project');
|
|
|
|
$body.removeAttr('data-group');
|
|
|
|
switch (section) {
|
|
|
|
case 'dashboard':
|
|
|
|
return $body.data('page', 'root:index');
|
|
|
|
case 'group':
|
|
|
|
$body.data('page', 'groups:show');
|
|
|
|
return $body.data('group', 'gitlab-org');
|
|
|
|
case 'project':
|
|
|
|
$body.data('page', 'projects:show');
|
|
|
|
return $body.data('project', 'gitlab-ce');
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-07-27 03:32:10 +00:00
|
|
|
// Mock `gl` object in window for dashboard specific page. App code will need it.
|
2016-07-24 20:45:11 +00:00
|
|
|
mockDashboardOptions = function() {
|
|
|
|
window.gl || (window.gl = {});
|
|
|
|
return window.gl.dashboardOptions = {
|
|
|
|
issuesPath: dashboardIssuesPath,
|
|
|
|
mrPath: dashboardMRsPath
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2016-07-27 03:32:10 +00:00
|
|
|
// Mock `gl` object in window for project specific page. App code will need it.
|
2016-07-24 20:45:11 +00:00
|
|
|
mockProjectOptions = function() {
|
|
|
|
window.gl || (window.gl = {});
|
|
|
|
return window.gl.projectOptions = {
|
|
|
|
'gitlab-ce': {
|
|
|
|
issuesPath: projectIssuesPath,
|
|
|
|
mrPath: projectMRsPath,
|
|
|
|
projectName: projectName
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
mockGroupOptions = function() {
|
|
|
|
window.gl || (window.gl = {});
|
|
|
|
return window.gl.groupOptions = {
|
|
|
|
'gitlab-org': {
|
|
|
|
issuesPath: groupIssuesPath,
|
|
|
|
mrPath: groupMRsPath,
|
|
|
|
projectName: groupName
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
assertLinks = function(list, issuesPath, mrsPath) {
|
|
|
|
var a1, a2, a3, a4, issuesAssignedToMeLink, issuesIHaveCreatedLink, mrsAssignedToMeLink, mrsIHaveCreatedLink;
|
2016-12-15 14:34:34 +00:00
|
|
|
issuesAssignedToMeLink = issuesPath + "/?assignee_username=" + userName;
|
|
|
|
issuesIHaveCreatedLink = issuesPath + "/?author_username=" + userName;
|
2016-07-24 20:45:11 +00:00
|
|
|
mrsAssignedToMeLink = mrsPath + "/?assignee_id=" + userId;
|
|
|
|
mrsIHaveCreatedLink = mrsPath + "/?author_id=" + userId;
|
|
|
|
a1 = "a[href='" + issuesAssignedToMeLink + "']";
|
|
|
|
a2 = "a[href='" + issuesIHaveCreatedLink + "']";
|
|
|
|
a3 = "a[href='" + mrsAssignedToMeLink + "']";
|
|
|
|
a4 = "a[href='" + mrsIHaveCreatedLink + "']";
|
|
|
|
expect(list.find(a1).length).toBe(1);
|
2016-07-28 22:46:41 +00:00
|
|
|
expect(list.find(a1).text()).toBe('Issues assigned to me');
|
2016-07-24 20:45:11 +00:00
|
|
|
expect(list.find(a2).length).toBe(1);
|
2016-07-28 22:46:41 +00:00
|
|
|
expect(list.find(a2).text()).toBe("Issues I've created");
|
2016-07-24 20:45:11 +00:00
|
|
|
expect(list.find(a3).length).toBe(1);
|
2016-07-28 22:46:41 +00:00
|
|
|
expect(list.find(a3).text()).toBe('Merge requests assigned to me');
|
2016-07-24 20:45:11 +00:00
|
|
|
expect(list.find(a4).length).toBe(1);
|
2016-07-28 22:46:41 +00:00
|
|
|
return expect(list.find(a4).text()).toBe("Merge requests I've created");
|
2016-07-24 20:45:11 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
describe('Search autocomplete dropdown', function() {
|
2016-12-31 00:14:33 +00:00
|
|
|
preloadFixtures('static/search_autocomplete.html.raw');
|
2016-07-24 20:45:11 +00:00
|
|
|
beforeEach(function() {
|
2016-12-31 00:14:33 +00:00
|
|
|
loadFixtures('static/search_autocomplete.html.raw');
|
2016-09-27 10:47:58 +00:00
|
|
|
return widget = new gl.SearchAutocomplete;
|
2016-07-24 20:45:11 +00:00
|
|
|
});
|
|
|
|
it('should show Dashboard specific dropdown menu', function() {
|
|
|
|
var list;
|
|
|
|
addBodyAttributes();
|
|
|
|
mockDashboardOptions();
|
|
|
|
widget.searchInput.focus();
|
|
|
|
list = widget.wrap.find('.dropdown-menu').find('ul');
|
|
|
|
return assertLinks(list, dashboardIssuesPath, dashboardMRsPath);
|
|
|
|
});
|
|
|
|
it('should show Group specific dropdown menu', function() {
|
|
|
|
var list;
|
|
|
|
addBodyAttributes('group');
|
|
|
|
mockGroupOptions();
|
|
|
|
widget.searchInput.focus();
|
|
|
|
list = widget.wrap.find('.dropdown-menu').find('ul');
|
|
|
|
return assertLinks(list, groupIssuesPath, groupMRsPath);
|
|
|
|
});
|
|
|
|
it('should show Project specific dropdown menu', function() {
|
|
|
|
var list;
|
|
|
|
addBodyAttributes('project');
|
|
|
|
mockProjectOptions();
|
|
|
|
widget.searchInput.focus();
|
|
|
|
list = widget.wrap.find('.dropdown-menu').find('ul');
|
|
|
|
return assertLinks(list, projectIssuesPath, projectMRsPath);
|
|
|
|
});
|
2016-10-02 22:11:08 +00:00
|
|
|
it('should not show category related menu if there is text in the input', function() {
|
2016-07-24 20:45:11 +00:00
|
|
|
var link, list;
|
|
|
|
addBodyAttributes('project');
|
|
|
|
mockProjectOptions();
|
|
|
|
widget.searchInput.val('help');
|
|
|
|
widget.searchInput.focus();
|
|
|
|
list = widget.wrap.find('.dropdown-menu').find('ul');
|
|
|
|
link = "a[href='" + projectIssuesPath + "/?assignee_id=" + userId + "']";
|
|
|
|
return expect(list.find(link).length).toBe(0);
|
|
|
|
});
|
2016-10-02 22:11:08 +00:00
|
|
|
return it('should not submit the search form when selecting an autocomplete row with the keyboard', function() {
|
|
|
|
var ENTER = 13;
|
|
|
|
var DOWN = 40;
|
|
|
|
addBodyAttributes();
|
|
|
|
mockDashboardOptions(true);
|
|
|
|
var submitSpy = spyOnEvent('form', 'submit');
|
|
|
|
widget.searchInput.focus();
|
|
|
|
widget.wrap.trigger($.Event('keydown', { which: DOWN }));
|
|
|
|
var enterKeyEvent = $.Event('keydown', { which: ENTER });
|
|
|
|
widget.searchInput.trigger(enterKeyEvent);
|
|
|
|
// This does not currently catch failing behavior. For security reasons,
|
|
|
|
// browsers will not trigger default behavior (form submit, in this
|
|
|
|
// example) on JavaScript-created keypresses.
|
|
|
|
expect(submitSpy).not.toHaveBeenTriggered();
|
|
|
|
// Does a worse job at capturing the intent of the test, but works.
|
|
|
|
expect(enterKeyEvent.isDefaultPrevented()).toBe(true);
|
|
|
|
});
|
2016-07-24 20:45:11 +00:00
|
|
|
});
|
|
|
|
}).call(this);
|