Commit ae62fc05 authored by Alfredo Sumaran's avatar Alfredo Sumaran

Fixes failing spec

parent 0dd3ce62
...@@ -90,6 +90,7 @@ import './flash'; ...@@ -90,6 +90,7 @@ import './flash';
.on('click', this.clickTab); .on('click', this.clickTab);
} }
// Used in tests
unbindEvents() { unbindEvents() {
$(document) $(document)
.off('shown.bs.tab', '.merge-request-tabs a[data-toggle="tab"]', this.tabShown) .off('shown.bs.tab', '.merge-request-tabs a[data-toggle="tab"]', this.tabShown)
...@@ -103,6 +104,7 @@ import './flash'; ...@@ -103,6 +104,7 @@ import './flash';
if (this.commitPipelinesTable) { if (this.commitPipelinesTable) {
document.querySelector('#commit-pipeline-table-view') document.querySelector('#commit-pipeline-table-view')
.removeChild(this.commitPipelinesTable.$el); .removeChild(this.commitPipelinesTable.$el);
this.commitPipelinesTable.$destroy(); this.commitPipelinesTable.$destroy();
} }
} }
......
...@@ -39,7 +39,8 @@ require('vendor/jquery.scrollTo'); ...@@ -39,7 +39,8 @@ require('vendor/jquery.scrollTo');
}); });
afterEach(function () { afterEach(function () {
this.class.destroy(); this.class.unbindEvents();
this.class.destroyPipelinesView();
}); });
describe('#activateTab', function () { describe('#activateTab', function () {
...@@ -65,6 +66,7 @@ require('vendor/jquery.scrollTo'); ...@@ -65,6 +66,7 @@ require('vendor/jquery.scrollTo');
expect($('#diffs')).toHaveClass('active'); expect($('#diffs')).toHaveClass('active');
}); });
}); });
describe('#opensInNewTab', function () { describe('#opensInNewTab', function () {
var tabUrl; var tabUrl;
var windowTarget = '_blank'; var windowTarget = '_blank';
...@@ -116,6 +118,7 @@ require('vendor/jquery.scrollTo'); ...@@ -116,6 +118,7 @@ require('vendor/jquery.scrollTo');
stopImmediatePropagation: function () {} stopImmediatePropagation: function () {}
}); });
}); });
it('opens page tab in a new browser tab with Cmd+Click - Mac', function () { it('opens page tab in a new browser tab with Cmd+Click - Mac', function () {
spyOn(window, 'open').and.callFake(function (url, name) { spyOn(window, 'open').and.callFake(function (url, name) {
expect(url).toEqual(tabUrl); expect(url).toEqual(tabUrl);
...@@ -129,6 +132,7 @@ require('vendor/jquery.scrollTo'); ...@@ -129,6 +132,7 @@ require('vendor/jquery.scrollTo');
stopImmediatePropagation: function () {} stopImmediatePropagation: function () {}
}); });
}); });
it('opens page tab in a new browser tab with Middle-click - Mac/PC', function () { it('opens page tab in a new browser tab with Middle-click - Mac/PC', function () {
spyOn(window, 'open').and.callFake(function (url, name) { spyOn(window, 'open').and.callFake(function (url, name) {
expect(url).toEqual(tabUrl); expect(url).toEqual(tabUrl);
...@@ -149,6 +153,7 @@ require('vendor/jquery.scrollTo'); ...@@ -149,6 +153,7 @@ require('vendor/jquery.scrollTo');
spyOn($, 'ajax').and.callFake(function () {}); spyOn($, 'ajax').and.callFake(function () {});
this.subject = this.class.setCurrentAction; this.subject = this.class.setCurrentAction;
}); });
it('changes from commits', function () { it('changes from commits', function () {
setLocation({ setLocation({
pathname: '/foo/bar/merge_requests/1/commits' pathname: '/foo/bar/merge_requests/1/commits'
...@@ -156,13 +161,16 @@ require('vendor/jquery.scrollTo'); ...@@ -156,13 +161,16 @@ require('vendor/jquery.scrollTo');
expect(this.subject('notes')).toBe('/foo/bar/merge_requests/1'); expect(this.subject('notes')).toBe('/foo/bar/merge_requests/1');
expect(this.subject('diffs')).toBe('/foo/bar/merge_requests/1/diffs'); expect(this.subject('diffs')).toBe('/foo/bar/merge_requests/1/diffs');
}); });
it('changes from diffs', function () { it('changes from diffs', function () {
setLocation({ setLocation({
pathname: '/foo/bar/merge_requests/1/diffs' pathname: '/foo/bar/merge_requests/1/diffs'
}); });
expect(this.subject('notes')).toBe('/foo/bar/merge_requests/1'); expect(this.subject('notes')).toBe('/foo/bar/merge_requests/1');
expect(this.subject('commits')).toBe('/foo/bar/merge_requests/1/commits'); expect(this.subject('commits')).toBe('/foo/bar/merge_requests/1/commits');
}); });
it('changes from diffs.html', function () { it('changes from diffs.html', function () {
setLocation({ setLocation({
pathname: '/foo/bar/merge_requests/1/diffs.html' pathname: '/foo/bar/merge_requests/1/diffs.html'
...@@ -170,6 +178,7 @@ require('vendor/jquery.scrollTo'); ...@@ -170,6 +178,7 @@ require('vendor/jquery.scrollTo');
expect(this.subject('notes')).toBe('/foo/bar/merge_requests/1'); expect(this.subject('notes')).toBe('/foo/bar/merge_requests/1');
expect(this.subject('commits')).toBe('/foo/bar/merge_requests/1/commits'); expect(this.subject('commits')).toBe('/foo/bar/merge_requests/1/commits');
}); });
it('changes from notes', function () { it('changes from notes', function () {
setLocation({ setLocation({
pathname: '/foo/bar/merge_requests/1' pathname: '/foo/bar/merge_requests/1'
...@@ -177,6 +186,7 @@ require('vendor/jquery.scrollTo'); ...@@ -177,6 +186,7 @@ require('vendor/jquery.scrollTo');
expect(this.subject('diffs')).toBe('/foo/bar/merge_requests/1/diffs'); expect(this.subject('diffs')).toBe('/foo/bar/merge_requests/1/diffs');
expect(this.subject('commits')).toBe('/foo/bar/merge_requests/1/commits'); expect(this.subject('commits')).toBe('/foo/bar/merge_requests/1/commits');
}); });
it('includes search parameters and hash string', function () { it('includes search parameters and hash string', function () {
setLocation({ setLocation({
pathname: '/foo/bar/merge_requests/1/diffs', pathname: '/foo/bar/merge_requests/1/diffs',
...@@ -185,6 +195,7 @@ require('vendor/jquery.scrollTo'); ...@@ -185,6 +195,7 @@ require('vendor/jquery.scrollTo');
}); });
expect(this.subject('show')).toBe('/foo/bar/merge_requests/1?view=parallel#L15-35'); expect(this.subject('show')).toBe('/foo/bar/merge_requests/1?view=parallel#L15-35');
}); });
it('replaces the current history state', function () { it('replaces the current history state', function () {
var newState; var newState;
setLocation({ setLocation({
...@@ -197,6 +208,7 @@ require('vendor/jquery.scrollTo'); ...@@ -197,6 +208,7 @@ require('vendor/jquery.scrollTo');
}, document.title, newState); }, document.title, newState);
} }
}); });
it('treats "show" like "notes"', function () { it('treats "show" like "notes"', function () {
setLocation({ setLocation({
pathname: '/foo/bar/merge_requests/1/commits' pathname: '/foo/bar/merge_requests/1/commits'
...@@ -207,6 +219,7 @@ require('vendor/jquery.scrollTo'); ...@@ -207,6 +219,7 @@ require('vendor/jquery.scrollTo');
describe('#tabShown', () => { describe('#tabShown', () => {
beforeEach(function () { beforeEach(function () {
spyOn($, 'ajax').and.callFake(function () {});
loadFixtures('merge_requests/merge_request_with_task_list.html.raw'); loadFixtures('merge_requests/merge_request_with_task_list.html.raw');
}); });
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment