2018-06-21 08:22:40 -04:00
|
|
|
/* eslint-disable no-var, object-shorthand */
|
2018-03-09 15:18:59 -05:00
|
|
|
import $ from 'jquery';
|
2018-01-31 04:27:30 -05:00
|
|
|
import MockAdapter from 'axios-mock-adapter';
|
2018-01-30 12:23:27 -05:00
|
|
|
import axios from '~/lib/utils/axios_utils';
|
2017-12-15 04:31:58 -05:00
|
|
|
import MergeRequestTabs from '~/merge_request_tabs';
|
2017-05-16 17:57:05 -04:00
|
|
|
import '~/commit/pipelines/pipelines_bundle';
|
2017-05-16 17:01:51 -04:00
|
|
|
import '~/breakpoints';
|
|
|
|
import '~/lib/utils/common_utils';
|
|
|
|
import 'vendor/jquery.scrollTo';
|
2018-06-21 08:22:40 -04:00
|
|
|
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-07-24 16:45:11 -04:00
|
|
|
};
|
2018-06-21 08:22:40 -04:00
|
|
|
$.extend(stubLocation, defaults, stubs || {});
|
|
|
|
};
|
2017-06-21 02:36:08 -04:00
|
|
|
|
2018-06-21 08:22:40 -04:00
|
|
|
preloadFixtures(
|
|
|
|
'merge_requests/merge_request_with_task_list.html.raw',
|
|
|
|
'merge_requests/diff_comment.html.raw',
|
|
|
|
);
|
2017-02-06 05:06:57 -05:00
|
|
|
|
2018-06-21 08:22:40 -04:00
|
|
|
beforeEach(function() {
|
|
|
|
mrPageMock = initMrPage();
|
|
|
|
this.class = new MergeRequestTabs({ stubLocation: stubLocation });
|
|
|
|
setLocation();
|
2017-02-09 17:19:12 -05:00
|
|
|
|
2018-06-21 08:22:40 -04:00
|
|
|
this.spies = {
|
|
|
|
history: spyOn(window.history, 'replaceState').and.callFake(function() {}),
|
|
|
|
};
|
|
|
|
});
|
2017-02-09 17:19:12 -05:00
|
|
|
|
2018-06-21 08:22:40 -04:00
|
|
|
afterEach(function() {
|
|
|
|
this.class.unbindEvents();
|
|
|
|
this.class.destroyPipelinesView();
|
|
|
|
mrPageMock.restore();
|
2018-06-30 09:17:46 -04:00
|
|
|
$('.js-merge-request-test').remove();
|
2018-06-21 08:22:40 -04:00
|
|
|
});
|
2017-02-09 17:19:12 -05:00
|
|
|
|
2018-06-21 08:22:40 -04:00
|
|
|
describe('opensInNewTab', function() {
|
|
|
|
var tabUrl;
|
|
|
|
var windowTarget = '_blank';
|
2017-02-09 17:19:12 -05:00
|
|
|
|
2018-06-21 08:22:40 -04:00
|
|
|
beforeEach(function() {
|
|
|
|
loadFixtures('merge_requests/merge_request_with_task_list.html.raw');
|
2017-02-09 17:19:12 -05:00
|
|
|
|
2018-06-21 08:22:40 -04:00
|
|
|
tabUrl = $('.commits-tab a').attr('href');
|
|
|
|
});
|
2017-02-07 11:45:27 -05:00
|
|
|
|
2018-06-21 08:22:40 -04:00
|
|
|
describe('meta click', () => {
|
|
|
|
let metakeyEvent;
|
|
|
|
beforeEach(function() {
|
|
|
|
metakeyEvent = $.Event('click', { keyCode: 91, ctrlKey: true });
|
2017-02-06 05:06:57 -05:00
|
|
|
});
|
2017-04-07 00:19:30 -04:00
|
|
|
|
2018-06-21 08:22:40 -04:00
|
|
|
it('opens page when commits link is clicked', function() {
|
|
|
|
spyOn(window, 'open').and.callFake(function(url, name) {
|
2017-02-07 11:45:27 -05:00
|
|
|
expect(url).toEqual(tabUrl);
|
2017-02-09 17:19:12 -05:00
|
|
|
expect(name).toEqual(windowTarget);
|
2017-02-07 11:45:27 -05:00
|
|
|
});
|
|
|
|
|
2018-06-21 08:22:40 -04:00
|
|
|
this.class.bindEvents();
|
|
|
|
$('.merge-request-tabs .commits-tab a').trigger(metakeyEvent);
|
2017-02-06 05:06:57 -05:00
|
|
|
});
|
2017-04-07 00:19:30 -04:00
|
|
|
|
2018-06-21 08:22:40 -04:00
|
|
|
it('opens page when commits badge is clicked', function() {
|
|
|
|
spyOn(window, 'open').and.callFake(function(url, name) {
|
2017-02-07 11:45:27 -05:00
|
|
|
expect(url).toEqual(tabUrl);
|
2017-02-09 17:19:12 -05:00
|
|
|
expect(name).toEqual(windowTarget);
|
2017-02-07 11:45:27 -05:00
|
|
|
});
|
|
|
|
|
2018-06-21 08:22:40 -04:00
|
|
|
this.class.bindEvents();
|
|
|
|
$('.merge-request-tabs .commits-tab a .badge').trigger(metakeyEvent);
|
2017-02-07 01:04:42 -05:00
|
|
|
});
|
2017-02-06 05:06:57 -05:00
|
|
|
});
|
2016-10-27 16:32:30 -04:00
|
|
|
|
2018-06-21 08:22:40 -04:00
|
|
|
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-07-24 16:45:11 -04:00
|
|
|
});
|
2017-04-07 00:19:30 -04:00
|
|
|
|
2018-06-21 08:22:40 -04:00
|
|
|
this.class.clickTab({
|
|
|
|
metaKey: false,
|
|
|
|
ctrlKey: true,
|
|
|
|
which: 1,
|
|
|
|
stopImmediatePropagation: function() {},
|
2016-07-24 16:45:11 -04:00
|
|
|
});
|
2018-06-21 08:22:40 -04:00
|
|
|
});
|
2017-04-07 00:19:30 -04:00
|
|
|
|
2018-06-21 08:22:40 -04:00
|
|
|
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-07-24 16:45:11 -04:00
|
|
|
});
|
2017-04-07 00:19:30 -04:00
|
|
|
|
2018-06-21 08:22:40 -04:00
|
|
|
this.class.clickTab({
|
|
|
|
metaKey: true,
|
|
|
|
ctrlKey: false,
|
|
|
|
which: 1,
|
|
|
|
stopImmediatePropagation: function() {},
|
2016-07-24 16:45:11 -04:00
|
|
|
});
|
2018-06-21 08:22:40 -04:00
|
|
|
});
|
2017-04-07 00:19:30 -04:00
|
|
|
|
2018-06-21 08:22:40 -04:00
|
|
|
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-07-24 16:45:11 -04:00
|
|
|
});
|
2017-04-07 00:19:30 -04:00
|
|
|
|
2018-06-21 08:22:40 -04:00
|
|
|
this.class.clickTab({
|
|
|
|
metaKey: false,
|
|
|
|
ctrlKey: false,
|
|
|
|
which: 2,
|
|
|
|
stopImmediatePropagation: function() {},
|
2016-07-24 16:45:11 -04:00
|
|
|
});
|
|
|
|
});
|
2018-06-21 08:22:40 -04:00
|
|
|
});
|
2017-03-22 22:39:09 -04:00
|
|
|
|
2018-06-21 08:22:40 -04:00
|
|
|
describe('setCurrentAction', function() {
|
|
|
|
let mock;
|
2018-01-30 12:23:27 -05:00
|
|
|
|
2018-06-21 08:22:40 -04:00
|
|
|
beforeEach(function() {
|
|
|
|
mock = new MockAdapter(axios);
|
|
|
|
mock.onAny().reply({ data: {} });
|
|
|
|
this.subject = this.class.setCurrentAction;
|
|
|
|
});
|
2018-01-30 12:23:27 -05:00
|
|
|
|
2018-06-21 08:22:40 -04:00
|
|
|
afterEach(() => {
|
|
|
|
mock.restore();
|
|
|
|
});
|
2017-03-22 22:39:09 -04:00
|
|
|
|
2018-06-21 08:22:40 -04:00
|
|
|
it('changes from commits', function() {
|
|
|
|
setLocation({
|
|
|
|
pathname: '/foo/bar/merge_requests/1/commits',
|
2018-01-30 12:23:27 -05:00
|
|
|
});
|
|
|
|
|
2018-06-21 08:22:40 -04:00
|
|
|
expect(this.subject('show')).toBe('/foo/bar/merge_requests/1');
|
|
|
|
expect(this.subject('diffs')).toBe('/foo/bar/merge_requests/1/diffs');
|
2017-03-22 22:39:09 -04:00
|
|
|
});
|
|
|
|
|
2018-06-21 08:22:40 -04:00
|
|
|
it('changes from diffs', function() {
|
|
|
|
setLocation({
|
|
|
|
pathname: '/foo/bar/merge_requests/1/diffs',
|
2017-06-21 02:36:08 -04:00
|
|
|
});
|
|
|
|
|
2018-06-21 08:22:40 -04:00
|
|
|
expect(this.subject('show')).toBe('/foo/bar/merge_requests/1');
|
|
|
|
expect(this.subject('commits')).toBe('/foo/bar/merge_requests/1/commits');
|
|
|
|
});
|
2017-10-06 16:36:15 -04:00
|
|
|
|
2018-06-21 08:22:40 -04:00
|
|
|
it('changes from diffs.html', function() {
|
|
|
|
setLocation({
|
|
|
|
pathname: '/foo/bar/merge_requests/1/diffs.html',
|
2017-06-21 02:36:08 -04:00
|
|
|
});
|
|
|
|
|
2018-06-21 08:22:40 -04:00
|
|
|
expect(this.subject('show')).toBe('/foo/bar/merge_requests/1');
|
|
|
|
expect(this.subject('commits')).toBe('/foo/bar/merge_requests/1/commits');
|
|
|
|
});
|
2017-05-24 21:41:41 -04:00
|
|
|
|
2018-06-21 08:22:40 -04:00
|
|
|
it('changes from notes', function() {
|
|
|
|
setLocation({
|
|
|
|
pathname: '/foo/bar/merge_requests/1',
|
2016-11-17 07:05:32 -05:00
|
|
|
});
|
2017-08-29 08:34:12 -04:00
|
|
|
|
2018-06-21 08:22:40 -04:00
|
|
|
expect(this.subject('diffs')).toBe('/foo/bar/merge_requests/1/diffs');
|
|
|
|
expect(this.subject('commits')).toBe('/foo/bar/merge_requests/1/commits');
|
|
|
|
});
|
2017-08-29 08:34:12 -04:00
|
|
|
|
2018-06-21 08:22:40 -04:00
|
|
|
it('includes search parameters and hash string', function() {
|
|
|
|
setLocation({
|
|
|
|
pathname: '/foo/bar/merge_requests/1/diffs',
|
|
|
|
search: '?view=parallel',
|
|
|
|
hash: '#L15-35',
|
2017-08-29 08:34:12 -04:00
|
|
|
});
|
2017-05-24 21:41:41 -04:00
|
|
|
|
2018-06-21 08:22:40 -04:00
|
|
|
expect(this.subject('show')).toBe('/foo/bar/merge_requests/1?view=parallel#L15-35');
|
|
|
|
});
|
2017-06-21 02:36:08 -04:00
|
|
|
|
2018-06-21 08:22:40 -04:00
|
|
|
it('replaces the current history state', function() {
|
|
|
|
var newState;
|
|
|
|
setLocation({
|
|
|
|
pathname: '/foo/bar/merge_requests/1',
|
2017-06-21 02:36:08 -04:00
|
|
|
});
|
2018-06-21 08:22:40 -04:00
|
|
|
newState = this.subject('commits');
|
2017-06-21 02:36:08 -04:00
|
|
|
|
2018-06-21 08:22:40 -04:00
|
|
|
expect(this.spies.history).toHaveBeenCalledWith(
|
|
|
|
{
|
|
|
|
url: newState,
|
|
|
|
},
|
|
|
|
document.title,
|
|
|
|
newState,
|
|
|
|
);
|
|
|
|
});
|
2017-06-21 02:36:08 -04:00
|
|
|
|
2018-06-21 08:22:40 -04:00
|
|
|
it('treats "show" like "notes"', function() {
|
|
|
|
setLocation({
|
|
|
|
pathname: '/foo/bar/merge_requests/1/commits',
|
2017-05-24 21:41:41 -04:00
|
|
|
});
|
2018-06-21 08:22:40 -04:00
|
|
|
|
|
|
|
expect(this.subject('show')).toBe('/foo/bar/merge_requests/1');
|
2016-11-17 07:05:32 -05:00
|
|
|
});
|
2018-06-21 08:22:40 -04:00
|
|
|
});
|
2017-09-22 12:53:34 -04:00
|
|
|
|
2018-06-21 08:22:40 -04:00
|
|
|
describe('expandViewContainer', function() {
|
|
|
|
beforeEach(() => {
|
|
|
|
$('body').append(
|
|
|
|
'<div class="content-wrapper"><div class="container-fluid container-limited"></div></div>',
|
|
|
|
);
|
|
|
|
});
|
2017-09-22 12:53:34 -04:00
|
|
|
|
2018-06-21 08:22:40 -04:00
|
|
|
afterEach(() => {
|
|
|
|
$('.content-wrapper').remove();
|
|
|
|
});
|
2017-09-22 12:53:34 -04:00
|
|
|
|
2018-06-21 08:22:40 -04:00
|
|
|
it('removes container-limited from containers', function() {
|
|
|
|
this.class.expandViewContainer();
|
2017-09-22 12:53:34 -04:00
|
|
|
|
2018-06-21 08:22:40 -04:00
|
|
|
expect($('.content-wrapper')).not.toContainElement('.container-limited');
|
|
|
|
});
|
2017-09-22 12:53:34 -04:00
|
|
|
|
2018-06-21 08:22:40 -04:00
|
|
|
it('does remove container-limited from breadcrumbs', function() {
|
|
|
|
$('.container-limited').addClass('breadcrumbs');
|
|
|
|
this.class.expandViewContainer();
|
2017-09-22 12:53:34 -04:00
|
|
|
|
2018-06-21 08:22:40 -04:00
|
|
|
expect($('.content-wrapper')).toContainElement('.container-limited');
|
2017-09-22 12:53:34 -04:00
|
|
|
});
|
2016-07-24 16:45:11 -04:00
|
|
|
});
|
2018-06-21 08:22:40 -04:00
|
|
|
});
|