2016-10-27 16:32:30 -04:00
|
|
|
/* eslint-disable no-var, comma-dangle, 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-07 07:30:53 -05:00
|
|
|
import * as urlUtils from '~/lib/utils/url_utility';
|
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';
|
2017-10-19 05:46:43 -04:00
|
|
|
import Diff from '~/diff';
|
2017-12-15 05:21:49 -05:00
|
|
|
import Notes from '~/notes';
|
2017-05-16 17:01:51 -04:00
|
|
|
import 'vendor/jquery.scrollTo';
|
2016-07-24 16:45:11 -04:00
|
|
|
|
2016-10-27 16:32:30 -04:00
|
|
|
(function () {
|
|
|
|
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-06-21 02:36:08 -04:00
|
|
|
|
2017-06-13 18:12:31 -04:00
|
|
|
const inlineChangesTabJsonFixture = 'merge_request_diffs/inline_changes_tab_with_comments.json';
|
|
|
|
const parallelChangesTabJsonFixture = 'merge_request_diffs/parallel_changes_tab_with_comments.json';
|
2017-06-21 02:36:08 -04:00
|
|
|
preloadFixtures(
|
|
|
|
'merge_requests/merge_request_with_task_list.html.raw',
|
|
|
|
'merge_requests/diff_comment.html.raw',
|
|
|
|
inlineChangesTabJsonFixture,
|
|
|
|
parallelChangesTabJsonFixture
|
|
|
|
);
|
2016-10-27 16:32:30 -04:00
|
|
|
|
|
|
|
beforeEach(function () {
|
2017-12-15 04:31:58 -05:00
|
|
|
this.class = new MergeRequestTabs({ stubLocation: stubLocation });
|
2016-10-27 16:32:30 -04:00
|
|
|
setLocation();
|
|
|
|
|
2017-06-13 01:03:36 -04:00
|
|
|
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
|
|
|
});
|
|
|
|
|
2017-05-05 18:17:08 -04:00
|
|
|
describe('activateTab', function () {
|
2016-10-27 16:32:30 -04:00
|
|
|
beforeEach(function () {
|
2018-01-30 12:23:27 -05:00
|
|
|
spyOn(axios, 'get').and.returnValue(Promise.resolve({ data: {} }));
|
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
|
|
|
});
|
2017-06-13 18:12:31 -04:00
|
|
|
it('shows the notes 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 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-05-05 18:17:08 -04: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', () => {
|
2017-09-06 12:14:34 -04:00
|
|
|
let metakeyEvent;
|
2017-02-09 17:19:12 -05:00
|
|
|
beforeEach(function () {
|
2017-09-06 12:14:34 -04:00
|
|
|
metakeyEvent = $.Event('click', { keyCode: 91, ctrlKey: true });
|
2017-02-09 17:19:12 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
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();
|
2017-09-06 12:14:34 -04:00
|
|
|
$('.merge-request-tabs .commits-tab a').trigger(metakeyEvent);
|
2017-02-09 17:19:12 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
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();
|
2017-09-06 12:14:34 -04:00
|
|
|
$('.merge-request-tabs .commits-tab a .badge').trigger(metakeyEvent);
|
2017-02-09 17:19:12 -05:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
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
|
|
|
|
2017-05-05 18:17:08 -04:00
|
|
|
describe('setCurrentAction', function () {
|
2016-10-27 16:32:30 -04:00
|
|
|
beforeEach(function () {
|
2018-01-30 12:23:27 -05:00
|
|
|
spyOn(axios, 'get').and.returnValue(Promise.resolve({ data: {} }));
|
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'
|
|
|
|
});
|
2017-06-13 18:12:31 -04:00
|
|
|
expect(this.subject('show')).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
|
|
|
|
2017-06-13 18:12:31 -04:00
|
|
|
expect(this.subject('show')).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'
|
|
|
|
});
|
2017-06-13 18:12:31 -04:00
|
|
|
expect(this.subject('show')).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-06-13 01:03:36 -04:00
|
|
|
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
|
|
|
|
2017-05-05 18:17:08 -04:00
|
|
|
describe('tabShown', () => {
|
2018-01-30 12:23:27 -05:00
|
|
|
let mock;
|
|
|
|
|
2017-03-22 22:39:09 -04:00
|
|
|
beforeEach(function () {
|
2018-01-31 04:27:30 -05:00
|
|
|
mock = new MockAdapter(axios);
|
2018-01-30 12:23:27 -05:00
|
|
|
mock.onGet(/(.*)\/diffs\.json/).reply(200, {
|
|
|
|
data: { html: '' },
|
2017-04-07 08:11:42 -04:00
|
|
|
});
|
2018-01-30 12:23:27 -05:00
|
|
|
|
2017-03-22 22:39:09 -04:00
|
|
|
loadFixtures('merge_requests/merge_request_with_task_list.html.raw');
|
|
|
|
});
|
|
|
|
|
2018-01-30 12:23:27 -05:00
|
|
|
afterEach(() => {
|
|
|
|
mock.restore();
|
|
|
|
});
|
|
|
|
|
2017-03-22 22:39:09 -04:00
|
|
|
describe('with "Side-by-side"/parallel diff view', () => {
|
|
|
|
beforeEach(function () {
|
|
|
|
this.class.diffViewType = () => 'parallel';
|
2017-10-19 05:46:43 -04:00
|
|
|
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
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-05-05 18:17:08 -04:00
|
|
|
describe('loadDiff', function () {
|
2017-06-21 02:36:08 -04:00
|
|
|
beforeEach(() => {
|
|
|
|
loadFixtures('merge_requests/diff_comment.html.raw');
|
2017-10-06 16:36:15 -04:00
|
|
|
$('body').attr('data-page', 'projects:merge_requests:show');
|
2017-06-21 02:36:08 -04:00
|
|
|
window.gl.ImageFile = () => {};
|
2017-12-15 05:21:49 -05:00
|
|
|
Notes.initialize('', []);
|
|
|
|
spyOn(Notes.instance, 'toggleDiffNote').and.callThrough();
|
2017-06-21 02:36:08 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
delete window.gl.ImageFile;
|
|
|
|
delete window.notes;
|
2017-10-06 16:36:15 -04:00
|
|
|
|
|
|
|
// Undo what we did to the shared <body>
|
|
|
|
$('body').removeAttr('data-page');
|
2017-06-21 02:36:08 -04:00
|
|
|
});
|
|
|
|
|
2017-12-19 07:20:06 -05:00
|
|
|
it('triggers Ajax request to JSON endpoint', function (done) {
|
|
|
|
const url = '/foo/bar/merge_requests/1/diffs';
|
2018-01-30 12:23:27 -05:00
|
|
|
|
|
|
|
spyOn(axios, 'get').and.callFake((reqUrl) => {
|
|
|
|
expect(reqUrl).toBe(`${url}.json`);
|
|
|
|
|
2017-12-19 07:20:06 -05:00
|
|
|
done();
|
2018-01-30 12:23:27 -05:00
|
|
|
|
|
|
|
return Promise.resolve({ data: {} });
|
2016-11-17 07:05:32 -05:00
|
|
|
});
|
2017-05-24 21:41:41 -04:00
|
|
|
|
2017-12-19 07:20:06 -05:00
|
|
|
this.class.loadDiff(url);
|
2016-11-17 07:05:32 -05:00
|
|
|
});
|
2017-08-29 08:34:12 -04:00
|
|
|
|
2017-12-19 07:20:06 -05:00
|
|
|
it('triggers scroll event when diff already loaded', function (done) {
|
2018-01-30 12:23:27 -05:00
|
|
|
spyOn(axios, 'get').and.callFake(done.fail);
|
2017-08-29 08:34:12 -04:00
|
|
|
spyOn(document, 'dispatchEvent');
|
|
|
|
|
|
|
|
this.class.diffsLoaded = true;
|
|
|
|
this.class.loadDiff('/foo/bar/merge_requests/1/diffs');
|
|
|
|
|
|
|
|
expect(
|
|
|
|
document.dispatchEvent,
|
|
|
|
).toHaveBeenCalledWith(new CustomEvent('scroll'));
|
2017-12-19 07:20:06 -05:00
|
|
|
done();
|
2017-08-29 08:34:12 -04:00
|
|
|
});
|
2017-05-24 21:41:41 -04:00
|
|
|
|
2017-06-21 02:36:08 -04:00
|
|
|
describe('with inline diff', () => {
|
|
|
|
let noteId;
|
|
|
|
let noteLineNumId;
|
2018-01-30 12:23:27 -05:00
|
|
|
let mock;
|
2017-06-21 02:36:08 -04:00
|
|
|
|
2017-05-24 21:41:41 -04:00
|
|
|
beforeEach(() => {
|
2017-06-21 02:36:08 -04:00
|
|
|
const diffsResponse = getJSONFixture(inlineChangesTabJsonFixture);
|
|
|
|
|
|
|
|
const $html = $(diffsResponse.html);
|
|
|
|
noteId = $html.find('.note').attr('id');
|
|
|
|
noteLineNumId = $html
|
|
|
|
.find('.note')
|
|
|
|
.closest('.notes_holder')
|
|
|
|
.prev('.line_holder')
|
|
|
|
.find('a[data-linenumber]')
|
|
|
|
.attr('href')
|
|
|
|
.replace('#', '');
|
2017-05-24 21:41:41 -04:00
|
|
|
|
2018-01-31 04:27:30 -05:00
|
|
|
mock = new MockAdapter(axios);
|
2018-01-30 12:23:27 -05:00
|
|
|
mock.onGet(/(.*)\/diffs\.json/).reply(200, diffsResponse);
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
mock.restore();
|
2017-05-24 21:41:41 -04:00
|
|
|
});
|
|
|
|
|
2017-06-21 02:36:08 -04:00
|
|
|
describe('with note fragment hash', () => {
|
2018-01-30 12:23:27 -05:00
|
|
|
it('should expand and scroll to linked fragment hash #note_xxx', function (done) {
|
2017-12-07 07:30:53 -05:00
|
|
|
spyOn(urlUtils, 'getLocationHash').and.returnValue(noteId);
|
2017-06-21 02:36:08 -04:00
|
|
|
this.class.loadDiff('/foo/bar/merge_requests/1/diffs');
|
|
|
|
|
2018-01-30 12:23:27 -05:00
|
|
|
setTimeout(() => {
|
|
|
|
expect(noteId.length).toBeGreaterThan(0);
|
|
|
|
expect(Notes.instance.toggleDiffNote).toHaveBeenCalledWith({
|
|
|
|
target: jasmine.any(Object),
|
|
|
|
lineType: 'old',
|
|
|
|
forceShow: true,
|
|
|
|
});
|
|
|
|
|
|
|
|
done();
|
2017-06-21 02:36:08 -04:00
|
|
|
});
|
2017-05-24 21:41:41 -04:00
|
|
|
});
|
|
|
|
|
2018-01-30 12:23:27 -05:00
|
|
|
it('should gracefully ignore non-existant fragment hash', function (done) {
|
2017-12-07 07:30:53 -05:00
|
|
|
spyOn(urlUtils, 'getLocationHash').and.returnValue('note_something-that-does-not-exist');
|
2017-06-21 02:36:08 -04:00
|
|
|
this.class.loadDiff('/foo/bar/merge_requests/1/diffs');
|
2017-05-24 21:41:41 -04:00
|
|
|
|
2018-01-30 12:23:27 -05:00
|
|
|
setTimeout(() => {
|
|
|
|
expect(Notes.instance.toggleDiffNote).not.toHaveBeenCalled();
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
2017-05-24 21:41:41 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-06-21 02:36:08 -04:00
|
|
|
describe('with line number fragment hash', () => {
|
|
|
|
it('should gracefully ignore line number fragment hash', function () {
|
2017-12-07 07:30:53 -05:00
|
|
|
spyOn(urlUtils, 'getLocationHash').and.returnValue(noteLineNumId);
|
2017-06-21 02:36:08 -04:00
|
|
|
this.class.loadDiff('/foo/bar/merge_requests/1/diffs');
|
|
|
|
|
|
|
|
expect(noteLineNumId.length).toBeGreaterThan(0);
|
2017-12-15 05:21:49 -05:00
|
|
|
expect(Notes.instance.toggleDiffNote).not.toHaveBeenCalled();
|
2017-06-21 02:36:08 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('with parallel diff', () => {
|
|
|
|
let noteId;
|
|
|
|
let noteLineNumId;
|
2018-01-30 12:23:27 -05:00
|
|
|
let mock;
|
2017-06-21 02:36:08 -04:00
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
const diffsResponse = getJSONFixture(parallelChangesTabJsonFixture);
|
|
|
|
|
|
|
|
const $html = $(diffsResponse.html);
|
|
|
|
noteId = $html.find('.note').attr('id');
|
|
|
|
noteLineNumId = $html
|
|
|
|
.find('.note')
|
|
|
|
.closest('.notes_holder')
|
|
|
|
.prev('.line_holder')
|
|
|
|
.find('a[data-linenumber]')
|
|
|
|
.attr('href')
|
|
|
|
.replace('#', '');
|
|
|
|
|
2018-01-31 04:27:30 -05:00
|
|
|
mock = new MockAdapter(axios);
|
2018-01-30 12:23:27 -05:00
|
|
|
mock.onGet(/(.*)\/diffs\.json/).reply(200, diffsResponse);
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
mock.restore();
|
2017-06-21 02:36:08 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('with note fragment hash', () => {
|
2018-01-30 12:23:27 -05:00
|
|
|
it('should expand and scroll to linked fragment hash #note_xxx', function (done) {
|
2017-12-07 07:30:53 -05:00
|
|
|
spyOn(urlUtils, 'getLocationHash').and.returnValue(noteId);
|
2017-05-24 21:41:41 -04:00
|
|
|
|
2017-06-21 02:36:08 -04:00
|
|
|
this.class.loadDiff('/foo/bar/merge_requests/1/diffs');
|
2017-05-24 21:41:41 -04:00
|
|
|
|
2018-01-30 12:23:27 -05:00
|
|
|
setTimeout(() => {
|
|
|
|
expect(noteId.length).toBeGreaterThan(0);
|
|
|
|
expect(Notes.instance.toggleDiffNote).toHaveBeenCalledWith({
|
|
|
|
target: jasmine.any(Object),
|
|
|
|
lineType: 'new',
|
|
|
|
forceShow: true,
|
|
|
|
});
|
|
|
|
|
|
|
|
done();
|
2017-06-21 02:36:08 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-01-30 12:23:27 -05:00
|
|
|
it('should gracefully ignore non-existant fragment hash', function (done) {
|
2017-12-07 07:30:53 -05:00
|
|
|
spyOn(urlUtils, 'getLocationHash').and.returnValue('note_something-that-does-not-exist');
|
2017-06-21 02:36:08 -04:00
|
|
|
this.class.loadDiff('/foo/bar/merge_requests/1/diffs');
|
|
|
|
|
2018-01-30 12:23:27 -05:00
|
|
|
setTimeout(() => {
|
|
|
|
expect(Notes.instance.toggleDiffNote).not.toHaveBeenCalled();
|
|
|
|
done();
|
|
|
|
});
|
2017-06-21 02:36:08 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('with line number fragment hash', () => {
|
|
|
|
it('should gracefully ignore line number fragment hash', function () {
|
2017-12-07 07:30:53 -05:00
|
|
|
spyOn(urlUtils, 'getLocationHash').and.returnValue(noteLineNumId);
|
2017-06-21 02:36:08 -04:00
|
|
|
this.class.loadDiff('/foo/bar/merge_requests/1/diffs');
|
|
|
|
|
|
|
|
expect(noteLineNumId.length).toBeGreaterThan(0);
|
2017-12-15 05:21:49 -05:00
|
|
|
expect(Notes.instance.toggleDiffNote).not.toHaveBeenCalled();
|
2017-06-21 02:36:08 -04:00
|
|
|
});
|
2017-05-24 21:41:41 -04:00
|
|
|
});
|
|
|
|
});
|
2016-11-17 07:05:32 -05:00
|
|
|
});
|
2017-09-22 12:53:34 -04:00
|
|
|
|
|
|
|
describe('expandViewContainer', function () {
|
|
|
|
beforeEach(() => {
|
|
|
|
$('body').append('<div class="content-wrapper"><div class="container-fluid container-limited"></div></div>');
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
$('.content-wrapper').remove();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('removes container-limited from containers', function () {
|
|
|
|
this.class.expandViewContainer();
|
|
|
|
|
|
|
|
expect($('.content-wrapper')).not.toContainElement('.container-limited');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('does remove container-limited from breadcrumbs', function () {
|
|
|
|
$('.container-limited').addClass('breadcrumbs');
|
|
|
|
this.class.expandViewContainer();
|
|
|
|
|
|
|
|
expect($('.content-wrapper')).toContainElement('.container-limited');
|
|
|
|
});
|
|
|
|
});
|
2016-07-24 16:45:11 -04:00
|
|
|
});
|
2017-02-10 02:29:41 -05:00
|
|
|
}).call(window);
|