2016-10-27 16:32:30 -04:00
|
|
|
/* eslint-disable no-var, comma-dangle, object-shorthand */
|
2016-07-24 16:45:11 -04:00
|
|
|
|
2017-01-09 18:23:54 -05:00
|
|
|
require('~/merge_request_tabs');
|
2017-04-07 15:36:09 -04:00
|
|
|
require('~/commit/pipelines/pipelines_bundle.js');
|
2017-01-09 18:23:54 -05:00
|
|
|
require('~/breakpoints');
|
|
|
|
require('~/lib/utils/common_utils');
|
2017-03-23 02:05:55 -04:00
|
|
|
require('~/diff');
|
|
|
|
require('~/single_file_diff');
|
|
|
|
require('~/files_comment_button');
|
2016-12-29 16:42:48 -05:00
|
|
|
require('vendor/jquery.scrollTo');
|
2016-07-24 16:45:11 -04:00
|
|
|
|
2016-10-27 16:32:30 -04:00
|
|
|
(function () {
|
2017-01-13 11:04:41 -05:00
|
|
|
// TODO: remove this hack!
|
|
|
|
// PhantomJS causes spyOn to panic because replaceState isn't "writable"
|
2017-01-27 20:33:58 -05:00
|
|
|
var phantomjs;
|
|
|
|
try {
|
|
|
|
phantomjs = !Object.getOwnPropertyDescriptor(window.history, 'replaceState').writable;
|
|
|
|
} catch (err) {
|
|
|
|
phantomjs = false;
|
|
|
|
}
|
2017-01-13 11:04:41 -05:00
|
|
|
|
2016-10-27 16:32:30 -04:00
|
|
|
describe('MergeRequestTabs', function () {
|
|
|
|
var stubLocation = {};
|
|
|
|
var setLocation = function (stubs) {
|
|
|
|
var defaults = {
|
2016-07-24 16:45:11 -04:00
|
|
|
pathname: '',
|
|
|
|
search: '',
|
|
|
|
hash: ''
|
|
|
|
};
|
2016-10-27 16:32:30 -04:00
|
|
|
$.extend(stubLocation, defaults, stubs || {});
|
2016-07-24 16:45:11 -04:00
|
|
|
};
|
2017-02-12 17:49:29 -05:00
|
|
|
preloadFixtures('merge_requests/merge_request_with_task_list.html.raw');
|
2016-10-27 16:32:30 -04:00
|
|
|
|
|
|
|
beforeEach(function () {
|
|
|
|
this.class = new gl.MergeRequestTabs({ stubLocation: stubLocation });
|
|
|
|
setLocation();
|
|
|
|
|
2017-01-13 11:04:41 -05:00
|
|
|
if (!phantomjs) {
|
|
|
|
this.spies = {
|
|
|
|
history: spyOn(window.history, 'replaceState').and.callFake(function () {})
|
|
|
|
};
|
|
|
|
}
|
2016-07-24 16:45:11 -04:00
|
|
|
});
|
2016-10-27 16:32:30 -04:00
|
|
|
|
2017-03-22 22:39:09 -04:00
|
|
|
afterEach(function () {
|
2017-04-07 00:19:30 -04:00
|
|
|
this.class.unbindEvents();
|
|
|
|
this.class.destroyPipelinesView();
|
2017-03-22 22:39:09 -04:00
|
|
|
});
|
|
|
|
|
2016-10-27 16:32:30 -04:00
|
|
|
describe('#activateTab', function () {
|
|
|
|
beforeEach(function () {
|
2016-12-03 17:04:21 -05:00
|
|
|
spyOn($, 'ajax').and.callFake(function () {});
|
2017-02-12 17:49:29 -05:00
|
|
|
loadFixtures('merge_requests/merge_request_with_task_list.html.raw');
|
2016-10-27 16:32:30 -04:00
|
|
|
this.subject = this.class.activateTab;
|
2016-07-24 16:45:11 -04:00
|
|
|
});
|
2016-10-27 16:32:30 -04:00
|
|
|
it('shows the first tab when action is show', function () {
|
2016-07-24 16:45:11 -04:00
|
|
|
this.subject('show');
|
2016-10-27 16:32:30 -04:00
|
|
|
expect($('#notes')).toHaveClass('active');
|
2016-07-24 16:45:11 -04:00
|
|
|
});
|
2016-10-27 16:32:30 -04:00
|
|
|
it('shows the notes tab when action is notes', function () {
|
2016-07-24 16:45:11 -04:00
|
|
|
this.subject('notes');
|
2016-10-27 16:32:30 -04:00
|
|
|
expect($('#notes')).toHaveClass('active');
|
2016-07-24 16:45:11 -04:00
|
|
|
});
|
2016-10-27 16:32:30 -04:00
|
|
|
it('shows the commits tab when action is commits', function () {
|
2016-07-24 16:45:11 -04:00
|
|
|
this.subject('commits');
|
2016-10-27 16:32:30 -04:00
|
|
|
expect($('#commits')).toHaveClass('active');
|
2016-07-24 16:45:11 -04:00
|
|
|
});
|
2016-10-27 16:32:30 -04:00
|
|
|
it('shows the diffs tab when action is diffs', function () {
|
2016-07-24 16:45:11 -04:00
|
|
|
this.subject('diffs');
|
2016-10-27 16:32:30 -04:00
|
|
|
expect($('#diffs')).toHaveClass('active');
|
2016-07-24 16:45:11 -04:00
|
|
|
});
|
|
|
|
});
|
2017-04-07 00:19:30 -04:00
|
|
|
|
2017-02-06 05:06:57 -05:00
|
|
|
describe('#opensInNewTab', function () {
|
2017-02-07 11:45:27 -05:00
|
|
|
var tabUrl;
|
2017-02-09 17:19:12 -05:00
|
|
|
var windowTarget = '_blank';
|
2017-02-07 11:45:27 -05:00
|
|
|
|
2017-02-07 11:10:31 -05:00
|
|
|
beforeEach(function () {
|
2017-02-09 17:19:12 -05:00
|
|
|
loadFixtures('merge_requests/merge_request_with_task_list.html.raw');
|
|
|
|
|
|
|
|
tabUrl = $('.commits-tab a').attr('href');
|
2017-02-06 05:06:57 -05:00
|
|
|
|
|
|
|
spyOn($.fn, 'attr').and.returnValue(tabUrl);
|
2017-02-07 11:45:27 -05:00
|
|
|
});
|
2017-02-09 17:19:12 -05:00
|
|
|
|
|
|
|
describe('meta click', () => {
|
|
|
|
beforeEach(function () {
|
|
|
|
spyOn(gl.utils, 'isMetaClick').and.returnValue(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('opens page when commits link is clicked', function () {
|
|
|
|
spyOn(window, 'open').and.callFake(function (url, name) {
|
|
|
|
expect(url).toEqual(tabUrl);
|
|
|
|
expect(name).toEqual(windowTarget);
|
|
|
|
});
|
|
|
|
|
|
|
|
this.class.bindEvents();
|
|
|
|
document.querySelector('.merge-request-tabs .commits-tab a').click();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('opens page when commits badge is clicked', function () {
|
|
|
|
spyOn(window, 'open').and.callFake(function (url, name) {
|
|
|
|
expect(url).toEqual(tabUrl);
|
|
|
|
expect(name).toEqual(windowTarget);
|
|
|
|
});
|
|
|
|
|
|
|
|
this.class.bindEvents();
|
|
|
|
document.querySelector('.merge-request-tabs .commits-tab a .badge').click();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-02-07 11:45:27 -05:00
|
|
|
it('opens page tab in a new browser tab with Ctrl+Click - Windows/Linux', function () {
|
2017-02-06 05:06:57 -05:00
|
|
|
spyOn(window, 'open').and.callFake(function (url, name) {
|
|
|
|
expect(url).toEqual(tabUrl);
|
2017-02-09 17:19:12 -05:00
|
|
|
expect(name).toEqual(windowTarget);
|
2017-02-06 05:06:57 -05:00
|
|
|
});
|
2017-02-07 11:45:27 -05:00
|
|
|
|
2017-02-06 05:06:57 -05:00
|
|
|
this.class.clickTab({
|
|
|
|
metaKey: false,
|
|
|
|
ctrlKey: true,
|
|
|
|
which: 1,
|
|
|
|
stopImmediatePropagation: function () {}
|
|
|
|
});
|
|
|
|
});
|
2017-04-07 00:19:30 -04:00
|
|
|
|
2017-02-06 05:06:57 -05:00
|
|
|
it('opens page tab in a new browser tab with Cmd+Click - Mac', function () {
|
2017-02-07 11:45:27 -05:00
|
|
|
spyOn(window, 'open').and.callFake(function (url, name) {
|
|
|
|
expect(url).toEqual(tabUrl);
|
2017-02-09 17:19:12 -05:00
|
|
|
expect(name).toEqual(windowTarget);
|
2017-02-07 11:45:27 -05:00
|
|
|
});
|
|
|
|
|
2017-02-06 05:06:57 -05:00
|
|
|
this.class.clickTab({
|
|
|
|
metaKey: true,
|
|
|
|
ctrlKey: false,
|
|
|
|
which: 1,
|
|
|
|
stopImmediatePropagation: function () {}
|
|
|
|
});
|
|
|
|
});
|
2017-04-07 00:19:30 -04:00
|
|
|
|
2017-02-07 01:04:42 -05:00
|
|
|
it('opens page tab in a new browser tab with Middle-click - Mac/PC', function () {
|
2017-02-07 11:45:27 -05:00
|
|
|
spyOn(window, 'open').and.callFake(function (url, name) {
|
|
|
|
expect(url).toEqual(tabUrl);
|
2017-02-09 17:19:12 -05:00
|
|
|
expect(name).toEqual(windowTarget);
|
2017-02-07 11:45:27 -05:00
|
|
|
});
|
|
|
|
|
2017-02-07 01:04:42 -05:00
|
|
|
this.class.clickTab({
|
|
|
|
metaKey: false,
|
|
|
|
ctrlKey: false,
|
|
|
|
which: 2,
|
|
|
|
stopImmediatePropagation: function () {}
|
|
|
|
});
|
|
|
|
});
|
2017-02-06 05:06:57 -05:00
|
|
|
});
|
2016-10-27 16:32:30 -04:00
|
|
|
|
|
|
|
describe('#setCurrentAction', function () {
|
|
|
|
beforeEach(function () {
|
2016-12-03 17:04:21 -05:00
|
|
|
spyOn($, 'ajax').and.callFake(function () {});
|
2016-10-27 16:32:30 -04:00
|
|
|
this.subject = this.class.setCurrentAction;
|
2016-07-24 16:45:11 -04:00
|
|
|
});
|
2017-04-07 00:19:30 -04:00
|
|
|
|
2016-10-27 16:32:30 -04:00
|
|
|
it('changes from commits', function () {
|
|
|
|
setLocation({
|
2016-07-24 16:45:11 -04:00
|
|
|
pathname: '/foo/bar/merge_requests/1/commits'
|
|
|
|
});
|
|
|
|
expect(this.subject('notes')).toBe('/foo/bar/merge_requests/1');
|
2016-10-27 16:32:30 -04:00
|
|
|
expect(this.subject('diffs')).toBe('/foo/bar/merge_requests/1/diffs');
|
2016-07-24 16:45:11 -04:00
|
|
|
});
|
2017-04-07 00:19:30 -04:00
|
|
|
|
2016-10-27 16:32:30 -04:00
|
|
|
it('changes from diffs', function () {
|
|
|
|
setLocation({
|
2016-07-24 16:45:11 -04:00
|
|
|
pathname: '/foo/bar/merge_requests/1/diffs'
|
|
|
|
});
|
2017-04-07 00:19:30 -04:00
|
|
|
|
2016-07-24 16:45:11 -04:00
|
|
|
expect(this.subject('notes')).toBe('/foo/bar/merge_requests/1');
|
2016-10-27 16:32:30 -04:00
|
|
|
expect(this.subject('commits')).toBe('/foo/bar/merge_requests/1/commits');
|
2016-07-24 16:45:11 -04:00
|
|
|
});
|
2017-04-07 00:19:30 -04:00
|
|
|
|
2016-10-27 16:32:30 -04:00
|
|
|
it('changes from diffs.html', function () {
|
|
|
|
setLocation({
|
2016-07-24 16:45:11 -04:00
|
|
|
pathname: '/foo/bar/merge_requests/1/diffs.html'
|
|
|
|
});
|
|
|
|
expect(this.subject('notes')).toBe('/foo/bar/merge_requests/1');
|
2016-10-27 16:32:30 -04:00
|
|
|
expect(this.subject('commits')).toBe('/foo/bar/merge_requests/1/commits');
|
2016-07-24 16:45:11 -04:00
|
|
|
});
|
2017-04-07 00:19:30 -04:00
|
|
|
|
2016-10-27 16:32:30 -04:00
|
|
|
it('changes from notes', function () {
|
|
|
|
setLocation({
|
2016-07-24 16:45:11 -04:00
|
|
|
pathname: '/foo/bar/merge_requests/1'
|
|
|
|
});
|
|
|
|
expect(this.subject('diffs')).toBe('/foo/bar/merge_requests/1/diffs');
|
2016-10-27 16:32:30 -04:00
|
|
|
expect(this.subject('commits')).toBe('/foo/bar/merge_requests/1/commits');
|
2016-07-24 16:45:11 -04:00
|
|
|
});
|
2017-04-07 00:19:30 -04:00
|
|
|
|
2016-10-27 16:32:30 -04:00
|
|
|
it('includes search parameters and hash string', function () {
|
|
|
|
setLocation({
|
2016-07-24 16:45:11 -04:00
|
|
|
pathname: '/foo/bar/merge_requests/1/diffs',
|
|
|
|
search: '?view=parallel',
|
|
|
|
hash: '#L15-35'
|
|
|
|
});
|
2016-10-27 16:32:30 -04:00
|
|
|
expect(this.subject('show')).toBe('/foo/bar/merge_requests/1?view=parallel#L15-35');
|
2016-07-24 16:45:11 -04:00
|
|
|
});
|
2017-04-07 00:19:30 -04:00
|
|
|
|
2016-10-27 16:32:30 -04:00
|
|
|
it('replaces the current history state', function () {
|
|
|
|
var newState;
|
|
|
|
setLocation({
|
2016-07-24 16:45:11 -04:00
|
|
|
pathname: '/foo/bar/merge_requests/1'
|
|
|
|
});
|
2016-10-27 16:32:30 -04:00
|
|
|
newState = this.subject('commits');
|
2017-01-13 11:04:41 -05:00
|
|
|
if (!phantomjs) {
|
|
|
|
expect(this.spies.history).toHaveBeenCalledWith({
|
|
|
|
url: newState
|
|
|
|
}, document.title, newState);
|
|
|
|
}
|
2016-07-24 16:45:11 -04:00
|
|
|
});
|
2017-04-07 00:19:30 -04:00
|
|
|
|
2016-10-27 16:32:30 -04:00
|
|
|
it('treats "show" like "notes"', function () {
|
|
|
|
setLocation({
|
2016-07-24 16:45:11 -04:00
|
|
|
pathname: '/foo/bar/merge_requests/1/commits'
|
|
|
|
});
|
2016-10-27 16:32:30 -04:00
|
|
|
expect(this.subject('show')).toBe('/foo/bar/merge_requests/1');
|
2016-07-24 16:45:11 -04:00
|
|
|
});
|
|
|
|
});
|
2017-03-22 22:39:09 -04:00
|
|
|
|
|
|
|
describe('#tabShown', () => {
|
|
|
|
beforeEach(function () {
|
2017-04-07 08:11:42 -04:00
|
|
|
spyOn($, 'ajax').and.callFake(function (options) {
|
|
|
|
options.success({ html: '' });
|
|
|
|
});
|
2017-03-22 22:39:09 -04:00
|
|
|
loadFixtures('merge_requests/merge_request_with_task_list.html.raw');
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('with "Side-by-side"/parallel diff view', () => {
|
|
|
|
beforeEach(function () {
|
|
|
|
this.class.diffViewType = () => 'parallel';
|
2017-03-23 02:05:55 -04:00
|
|
|
gl.Diff.prototype.diffViewType = () => 'parallel';
|
2017-03-22 22:39:09 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('maintains `container-limited` for pipelines tab', function (done) {
|
|
|
|
const asyncClick = function (selector) {
|
|
|
|
return new Promise((resolve) => {
|
|
|
|
setTimeout(() => {
|
|
|
|
document.querySelector(selector).click();
|
|
|
|
resolve();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
asyncClick('.merge-request-tabs .pipelines-tab a')
|
|
|
|
.then(() => asyncClick('.merge-request-tabs .diffs-tab a'))
|
|
|
|
.then(() => asyncClick('.merge-request-tabs .pipelines-tab a'))
|
|
|
|
.then(() => {
|
|
|
|
const hasContainerLimitedClass = document.querySelector('.content-wrapper .container-fluid').classList.contains('container-limited');
|
|
|
|
expect(hasContainerLimitedClass).toBe(true);
|
|
|
|
})
|
|
|
|
.then(done)
|
|
|
|
.catch((err) => {
|
|
|
|
done.fail(`Something went wrong clicking MR tabs: ${err.message}\n${err.stack}`);
|
|
|
|
});
|
|
|
|
});
|
2017-03-23 02:05:55 -04:00
|
|
|
|
|
|
|
it('maintains `container-limited` when switching from "Changes" tab before it loads', function (done) {
|
|
|
|
const asyncClick = function (selector) {
|
|
|
|
return new Promise((resolve) => {
|
|
|
|
setTimeout(() => {
|
|
|
|
document.querySelector(selector).click();
|
|
|
|
resolve();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
asyncClick('.merge-request-tabs .diffs-tab a')
|
|
|
|
.then(() => asyncClick('.merge-request-tabs .notes-tab a'))
|
|
|
|
.then(() => {
|
|
|
|
const hasContainerLimitedClass = document.querySelector('.content-wrapper .container-fluid').classList.contains('container-limited');
|
|
|
|
expect(hasContainerLimitedClass).toBe(true);
|
|
|
|
})
|
|
|
|
.then(done)
|
|
|
|
.catch((err) => {
|
|
|
|
done.fail(`Something went wrong clicking MR tabs: ${err.message}\n${err.stack}`);
|
|
|
|
});
|
|
|
|
});
|
2017-03-22 22:39:09 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2016-12-03 17:04:21 -05:00
|
|
|
describe('#loadDiff', function () {
|
|
|
|
it('requires an absolute pathname', function () {
|
|
|
|
spyOn($, 'ajax').and.callFake(function (options) {
|
2016-11-17 07:05:32 -05:00
|
|
|
expect(options.url).toEqual('/foo/bar/merge_requests/1/diffs.json');
|
|
|
|
});
|
|
|
|
this.class.loadDiff('/foo/bar/merge_requests/1/diffs');
|
|
|
|
});
|
|
|
|
});
|
2016-07-24 16:45:11 -04:00
|
|
|
});
|
2017-02-10 02:29:41 -05:00
|
|
|
}).call(window);
|