2018-11-08 19:23:39 +05:30
|
|
|
/* eslint-disable no-var, object-shorthand */
|
2018-05-09 12:01:36 +05:30
|
|
|
import $ from 'jquery';
|
2018-03-17 18:26:18 +05:30
|
|
|
import MockAdapter from 'axios-mock-adapter';
|
|
|
|
import axios from '~/lib/utils/axios_utils';
|
|
|
|
import MergeRequestTabs from '~/merge_request_tabs';
|
2017-09-10 17:25:29 +05:30
|
|
|
import '~/commit/pipelines/pipelines_bundle';
|
|
|
|
import '~/breakpoints';
|
|
|
|
import '~/lib/utils/common_utils';
|
|
|
|
import 'vendor/jquery.scrollTo';
|
2018-11-08 19:23:39 +05:30
|
|
|
import initMrPage from './helpers/init_vue_mr_page_helper';
|
|
|
|
|
|
|
|
describe('MergeRequestTabs', function() {
|
|
|
|
let mrPageMock;
|
|
|
|
var stubLocation = {};
|
|
|
|
var setLocation = function(stubs) {
|
|
|
|
var defaults = {
|
|
|
|
pathname: '',
|
|
|
|
search: '',
|
|
|
|
hash: '',
|
2016-09-13 17:45:13 +05:30
|
|
|
};
|
2018-11-08 19:23:39 +05:30
|
|
|
$.extend(stubLocation, defaults, stubs || {});
|
|
|
|
};
|
2017-09-10 17:25:29 +05:30
|
|
|
|
2018-11-08 19:23:39 +05:30
|
|
|
preloadFixtures(
|
2019-07-07 11:18:12 +05:30
|
|
|
'merge_requests/merge_request_with_task_list.html',
|
|
|
|
'merge_requests/diff_comment.html',
|
2018-11-08 19:23:39 +05:30
|
|
|
);
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2018-11-08 19:23:39 +05:30
|
|
|
beforeEach(function() {
|
|
|
|
mrPageMock = initMrPage();
|
|
|
|
this.class = new MergeRequestTabs({ stubLocation: stubLocation });
|
|
|
|
setLocation();
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2018-11-08 19:23:39 +05:30
|
|
|
this.spies = {
|
|
|
|
history: spyOn(window.history, 'replaceState').and.callFake(function() {}),
|
|
|
|
};
|
|
|
|
});
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2018-11-08 19:23:39 +05:30
|
|
|
afterEach(function() {
|
|
|
|
this.class.unbindEvents();
|
|
|
|
this.class.destroyPipelinesView();
|
|
|
|
mrPageMock.restore();
|
|
|
|
$('.js-merge-request-test').remove();
|
|
|
|
});
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2018-11-08 19:23:39 +05:30
|
|
|
describe('opensInNewTab', function() {
|
|
|
|
var tabUrl;
|
|
|
|
var windowTarget = '_blank';
|
2019-09-04 21:01:54 +05:30
|
|
|
let clickTabParams;
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2018-11-08 19:23:39 +05:30
|
|
|
beforeEach(function() {
|
2019-07-07 11:18:12 +05:30
|
|
|
loadFixtures('merge_requests/merge_request_with_task_list.html');
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2018-11-08 19:23:39 +05:30
|
|
|
tabUrl = $('.commits-tab a').attr('href');
|
2019-09-04 21:01:54 +05:30
|
|
|
|
|
|
|
clickTabParams = {
|
|
|
|
metaKey: false,
|
|
|
|
ctrlKey: false,
|
|
|
|
which: 1,
|
|
|
|
stopImmediatePropagation: function() {},
|
|
|
|
preventDefault: function() {},
|
|
|
|
currentTarget: {
|
|
|
|
getAttribute: function(attr) {
|
|
|
|
return attr === 'href' ? tabUrl : null;
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
2018-11-08 19:23:39 +05:30
|
|
|
});
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2018-11-08 19:23:39 +05:30
|
|
|
describe('meta click', () => {
|
|
|
|
let metakeyEvent;
|
2019-09-04 21:01:54 +05:30
|
|
|
|
2018-11-08 19:23:39 +05:30
|
|
|
beforeEach(function() {
|
|
|
|
metakeyEvent = $.Event('click', { keyCode: 91, ctrlKey: true });
|
2017-08-17 22:00:37 +05:30
|
|
|
});
|
|
|
|
|
2018-11-08 19:23:39 +05:30
|
|
|
it('opens page when commits link is clicked', function() {
|
|
|
|
spyOn(window, 'open').and.callFake(function(url, name) {
|
2017-08-17 22:00:37 +05:30
|
|
|
expect(url).toEqual(tabUrl);
|
|
|
|
expect(name).toEqual(windowTarget);
|
|
|
|
});
|
|
|
|
|
2018-11-08 19:23:39 +05:30
|
|
|
this.class.bindEvents();
|
|
|
|
$('.merge-request-tabs .commits-tab a').trigger(metakeyEvent);
|
2019-09-04 21:01:54 +05:30
|
|
|
|
|
|
|
expect(window.open).toHaveBeenCalled();
|
2017-08-17 22:00:37 +05:30
|
|
|
});
|
|
|
|
|
2018-11-08 19:23:39 +05:30
|
|
|
it('opens page when commits badge is clicked', function() {
|
|
|
|
spyOn(window, 'open').and.callFake(function(url, name) {
|
2017-08-17 22:00:37 +05:30
|
|
|
expect(url).toEqual(tabUrl);
|
|
|
|
expect(name).toEqual(windowTarget);
|
|
|
|
});
|
|
|
|
|
2018-11-08 19:23:39 +05:30
|
|
|
this.class.bindEvents();
|
|
|
|
$('.merge-request-tabs .commits-tab a .badge').trigger(metakeyEvent);
|
2019-09-04 21:01:54 +05:30
|
|
|
|
|
|
|
expect(window.open).toHaveBeenCalled();
|
2017-08-17 22:00:37 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-11-08 19:23:39 +05:30
|
|
|
it('opens page tab in a new browser tab with Ctrl+Click - Windows/Linux', function() {
|
|
|
|
spyOn(window, 'open').and.callFake(function(url, name) {
|
|
|
|
expect(url).toEqual(tabUrl);
|
|
|
|
expect(name).toEqual(windowTarget);
|
2016-09-13 17:45:13 +05:30
|
|
|
});
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2019-09-04 21:01:54 +05:30
|
|
|
this.class.clickTab({ ...clickTabParams, metaKey: true });
|
|
|
|
|
|
|
|
expect(window.open).toHaveBeenCalled();
|
2018-11-08 19:23:39 +05:30
|
|
|
});
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2018-11-08 19:23:39 +05:30
|
|
|
it('opens page tab in a new browser tab with Cmd+Click - Mac', function() {
|
|
|
|
spyOn(window, 'open').and.callFake(function(url, name) {
|
|
|
|
expect(url).toEqual(tabUrl);
|
|
|
|
expect(name).toEqual(windowTarget);
|
2016-09-13 17:45:13 +05:30
|
|
|
});
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2019-09-04 21:01:54 +05:30
|
|
|
this.class.clickTab({ ...clickTabParams, ctrlKey: true });
|
|
|
|
|
|
|
|
expect(window.open).toHaveBeenCalled();
|
2018-11-08 19:23:39 +05:30
|
|
|
});
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2018-11-08 19:23:39 +05:30
|
|
|
it('opens page tab in a new browser tab with Middle-click - Mac/PC', function() {
|
|
|
|
spyOn(window, 'open').and.callFake(function(url, name) {
|
|
|
|
expect(url).toEqual(tabUrl);
|
|
|
|
expect(name).toEqual(windowTarget);
|
2016-09-13 17:45:13 +05:30
|
|
|
});
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2019-09-04 21:01:54 +05:30
|
|
|
this.class.clickTab({ ...clickTabParams, which: 2 });
|
|
|
|
|
|
|
|
expect(window.open).toHaveBeenCalled();
|
2016-09-13 17:45:13 +05:30
|
|
|
});
|
2018-11-08 19:23:39 +05:30
|
|
|
});
|
2016-09-13 17:45:13 +05:30
|
|
|
|
2018-11-08 19:23:39 +05:30
|
|
|
describe('setCurrentAction', function() {
|
|
|
|
let mock;
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2018-11-08 19:23:39 +05:30
|
|
|
beforeEach(function() {
|
|
|
|
mock = new MockAdapter(axios);
|
|
|
|
mock.onAny().reply({ data: {} });
|
|
|
|
this.subject = this.class.setCurrentAction;
|
|
|
|
});
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2018-11-08 19:23:39 +05:30
|
|
|
afterEach(() => {
|
|
|
|
mock.restore();
|
|
|
|
});
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2018-11-08 19:23:39 +05:30
|
|
|
it('changes from commits', function() {
|
|
|
|
setLocation({
|
|
|
|
pathname: '/foo/bar/merge_requests/1/commits',
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
|
|
|
|
2018-11-08 19:23:39 +05:30
|
|
|
expect(this.subject('show')).toBe('/foo/bar/merge_requests/1');
|
|
|
|
expect(this.subject('diffs')).toBe('/foo/bar/merge_requests/1/diffs');
|
2017-08-17 22:00:37 +05:30
|
|
|
});
|
|
|
|
|
2018-11-08 19:23:39 +05:30
|
|
|
it('changes from diffs', function() {
|
|
|
|
setLocation({
|
|
|
|
pathname: '/foo/bar/merge_requests/1/diffs',
|
2017-09-10 17:25:29 +05:30
|
|
|
});
|
|
|
|
|
2018-11-08 19:23:39 +05:30
|
|
|
expect(this.subject('show')).toBe('/foo/bar/merge_requests/1');
|
|
|
|
expect(this.subject('commits')).toBe('/foo/bar/merge_requests/1/commits');
|
|
|
|
});
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2018-11-08 19:23:39 +05:30
|
|
|
it('changes from diffs.html', function() {
|
|
|
|
setLocation({
|
|
|
|
pathname: '/foo/bar/merge_requests/1/diffs.html',
|
2017-09-10 17:25:29 +05:30
|
|
|
});
|
|
|
|
|
2018-11-08 19:23:39 +05:30
|
|
|
expect(this.subject('show')).toBe('/foo/bar/merge_requests/1');
|
|
|
|
expect(this.subject('commits')).toBe('/foo/bar/merge_requests/1/commits');
|
|
|
|
});
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2018-11-08 19:23:39 +05:30
|
|
|
it('changes from notes', function() {
|
|
|
|
setLocation({
|
|
|
|
pathname: '/foo/bar/merge_requests/1',
|
2017-08-17 22:00:37 +05:30
|
|
|
});
|
|
|
|
|
2018-11-08 19:23:39 +05:30
|
|
|
expect(this.subject('diffs')).toBe('/foo/bar/merge_requests/1/diffs');
|
|
|
|
expect(this.subject('commits')).toBe('/foo/bar/merge_requests/1/commits');
|
|
|
|
});
|
2017-09-10 17:25:29 +05:30
|
|
|
|
2018-11-08 19:23:39 +05:30
|
|
|
it('includes search parameters and hash string', function() {
|
|
|
|
setLocation({
|
|
|
|
pathname: '/foo/bar/merge_requests/1/diffs',
|
|
|
|
search: '?view=parallel',
|
|
|
|
hash: '#L15-35',
|
2017-09-10 17:25:29 +05:30
|
|
|
});
|
|
|
|
|
2018-11-08 19:23:39 +05:30
|
|
|
expect(this.subject('show')).toBe('/foo/bar/merge_requests/1?view=parallel#L15-35');
|
|
|
|
});
|
2017-09-10 17:25:29 +05:30
|
|
|
|
2018-11-08 19:23:39 +05:30
|
|
|
it('replaces the current history state', function() {
|
|
|
|
var newState;
|
|
|
|
setLocation({
|
|
|
|
pathname: '/foo/bar/merge_requests/1',
|
2017-09-10 17:25:29 +05:30
|
|
|
});
|
2018-11-08 19:23:39 +05:30
|
|
|
newState = this.subject('commits');
|
2017-09-10 17:25:29 +05:30
|
|
|
|
2018-11-08 19:23:39 +05:30
|
|
|
expect(this.spies.history).toHaveBeenCalledWith(
|
|
|
|
{
|
|
|
|
url: newState,
|
|
|
|
},
|
|
|
|
document.title,
|
|
|
|
newState,
|
|
|
|
);
|
|
|
|
});
|
2017-09-10 17:25:29 +05:30
|
|
|
|
2018-11-08 19:23:39 +05:30
|
|
|
it('treats "show" like "notes"', function() {
|
|
|
|
setLocation({
|
|
|
|
pathname: '/foo/bar/merge_requests/1/commits',
|
2017-08-17 22:00:37 +05:30
|
|
|
});
|
2018-11-08 19:23:39 +05:30
|
|
|
|
|
|
|
expect(this.subject('show')).toBe('/foo/bar/merge_requests/1');
|
2017-08-17 22:00:37 +05:30
|
|
|
});
|
2018-11-08 19:23:39 +05:30
|
|
|
});
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2018-11-08 19:23:39 +05:30
|
|
|
describe('expandViewContainer', function() {
|
|
|
|
beforeEach(() => {
|
|
|
|
$('body').append(
|
|
|
|
'<div class="content-wrapper"><div class="container-fluid container-limited"></div></div>',
|
|
|
|
);
|
|
|
|
});
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2018-11-08 19:23:39 +05:30
|
|
|
afterEach(() => {
|
|
|
|
$('.content-wrapper').remove();
|
|
|
|
});
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2018-11-08 19:23:39 +05:30
|
|
|
it('removes container-limited from containers', function() {
|
|
|
|
this.class.expandViewContainer();
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2018-11-08 19:23:39 +05:30
|
|
|
expect($('.content-wrapper')).not.toContainElement('.container-limited');
|
|
|
|
});
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2018-12-05 23:21:45 +05:30
|
|
|
it('does not add container-limited when fluid layout is prefered', function() {
|
|
|
|
$('.content-wrapper .container-fluid').removeClass('container-limited');
|
|
|
|
|
|
|
|
this.class.expandViewContainer(false);
|
|
|
|
|
|
|
|
expect($('.content-wrapper')).not.toContainElement('.container-limited');
|
|
|
|
});
|
|
|
|
|
2018-11-08 19:23:39 +05:30
|
|
|
it('does remove container-limited from breadcrumbs', function() {
|
|
|
|
$('.container-limited').addClass('breadcrumbs');
|
|
|
|
this.class.expandViewContainer();
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2018-11-08 19:23:39 +05:30
|
|
|
expect($('.content-wrapper')).toContainElement('.container-limited');
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
2017-08-17 22:00:37 +05:30
|
|
|
});
|
2019-02-15 15:39:39 +05:30
|
|
|
|
|
|
|
describe('tabShown', function() {
|
|
|
|
const mainContent = document.createElement('div');
|
|
|
|
const tabContent = document.createElement('div');
|
|
|
|
|
|
|
|
beforeEach(function() {
|
|
|
|
spyOn(mainContent, 'getBoundingClientRect').and.returnValue({ top: 10 });
|
|
|
|
spyOn(tabContent, 'getBoundingClientRect').and.returnValue({ top: 100 });
|
|
|
|
spyOn(document, 'querySelector').and.callFake(function(selector) {
|
|
|
|
return selector === '.content-wrapper' ? mainContent : tabContent;
|
|
|
|
});
|
|
|
|
this.class.currentAction = 'commits';
|
|
|
|
});
|
|
|
|
|
|
|
|
it('calls window scrollTo with options if document has scrollBehavior', function() {
|
|
|
|
document.documentElement.style.scrollBehavior = '';
|
|
|
|
|
|
|
|
spyOn(window, 'scrollTo');
|
|
|
|
|
|
|
|
this.class.tabShown('commits', 'foobar');
|
|
|
|
|
|
|
|
expect(window.scrollTo.calls.first().args[0]).toEqual({ top: 39, behavior: 'smooth' });
|
|
|
|
});
|
|
|
|
|
|
|
|
it('calls window scrollTo with two args if document does not have scrollBehavior', function() {
|
|
|
|
spyOnProperty(document.documentElement, 'style', 'get').and.returnValue({});
|
|
|
|
|
|
|
|
spyOn(window, 'scrollTo');
|
|
|
|
|
|
|
|
this.class.tabShown('commits', 'foobar');
|
|
|
|
|
|
|
|
expect(window.scrollTo.calls.first().args).toEqual([0, 39]);
|
|
|
|
});
|
|
|
|
});
|
2018-11-08 19:23:39 +05:30
|
|
|
});
|