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(
|
|
|
|
'merge_requests/merge_request_with_task_list.html.raw',
|
|
|
|
'merge_requests/diff_comment.html.raw',
|
|
|
|
);
|
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';
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2018-11-08 19:23:39 +05:30
|
|
|
beforeEach(function() {
|
|
|
|
loadFixtures('merge_requests/merge_request_with_task_list.html.raw');
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2018-11-08 19:23:39 +05:30
|
|
|
tabUrl = $('.commits-tab a').attr('href');
|
|
|
|
});
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2018-11-08 19:23:39 +05:30
|
|
|
describe('meta click', () => {
|
|
|
|
let metakeyEvent;
|
|
|
|
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);
|
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);
|
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
|
|
|
|
2018-11-08 19:23:39 +05:30
|
|
|
this.class.clickTab({
|
|
|
|
metaKey: false,
|
|
|
|
ctrlKey: true,
|
|
|
|
which: 1,
|
|
|
|
stopImmediatePropagation: function() {},
|
2016-09-13 17:45:13 +05:30
|
|
|
});
|
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
|
|
|
|
2018-11-08 19:23:39 +05:30
|
|
|
this.class.clickTab({
|
|
|
|
metaKey: true,
|
|
|
|
ctrlKey: false,
|
|
|
|
which: 1,
|
|
|
|
stopImmediatePropagation: function() {},
|
2016-09-13 17:45:13 +05:30
|
|
|
});
|
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
|
|
|
|
2018-11-08 19:23:39 +05:30
|
|
|
this.class.clickTab({
|
|
|
|
metaKey: false,
|
|
|
|
ctrlKey: false,
|
|
|
|
which: 2,
|
|
|
|
stopImmediatePropagation: function() {},
|
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
|
|
|
});
|
2018-11-08 19:23:39 +05:30
|
|
|
});
|