2016-10-27 16:32:30 -04:00
|
|
|
/* eslint-disable no-var, comma-dangle, object-shorthand */
|
2016-07-24 16:45:11 -04:00
|
|
|
|
|
|
|
/*= require merge_request_tabs */
|
2016-09-16 06:21:45 -04:00
|
|
|
//= require breakpoints
|
2016-11-17 07:05:32 -05:00
|
|
|
//= require lib/utils/common_utils
|
|
|
|
//= require 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
|
|
|
};
|
|
|
|
fixture.preload('merge_request_tabs.html');
|
2016-10-27 16:32:30 -04:00
|
|
|
|
|
|
|
beforeEach(function () {
|
|
|
|
this.class = new gl.MergeRequestTabs({ stubLocation: stubLocation });
|
|
|
|
setLocation();
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
describe('#activateTab', function () {
|
|
|
|
beforeEach(function () {
|
2016-12-03 17:04:21 -05:00
|
|
|
spyOn($, 'ajax').and.callFake(function () {});
|
2016-07-24 16:45:11 -04:00
|
|
|
fixture.load('merge_request_tabs.html');
|
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
|
|
|
});
|
|
|
|
});
|
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
|
|
|
});
|
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
|
|
|
});
|
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'
|
|
|
|
});
|
|
|
|
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
|
|
|
});
|
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
|
|
|
});
|
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
|
|
|
});
|
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
|
|
|
});
|
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');
|
|
|
|
expect(this.spies.history).toHaveBeenCalledWith({
|
2016-07-24 16:45:11 -04:00
|
|
|
turbolinks: true,
|
2016-10-27 16:32:30 -04:00
|
|
|
url: newState
|
|
|
|
}, document.title, newState);
|
2016-07-24 16:45:11 -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
|
|
|
});
|
|
|
|
});
|
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
|
|
|
});
|
|
|
|
}).call(this);
|