2018-05-09 12:01:36 +05:30
|
|
|
import $ from 'jquery';
|
2018-03-17 18:26:18 +05:30
|
|
|
import _ from 'underscore';
|
|
|
|
import Vue from 'vue';
|
|
|
|
import SidebarMediator from '~/sidebar/sidebar_mediator';
|
|
|
|
import SidebarStore from '~/sidebar/stores/sidebar_store';
|
|
|
|
import SidebarService from '~/sidebar/services/sidebar_service';
|
|
|
|
import SidebarMoveIssue from '~/sidebar/lib/sidebar_move_issue';
|
|
|
|
import Mock from './mock_data';
|
|
|
|
|
2018-10-15 14:42:47 +05:30
|
|
|
describe('SidebarMoveIssue', function () {
|
2018-03-17 18:26:18 +05:30
|
|
|
beforeEach(() => {
|
|
|
|
Vue.http.interceptors.push(Mock.sidebarMockInterceptor);
|
|
|
|
this.mediator = new SidebarMediator(Mock.mediator);
|
|
|
|
this.$content = $(`
|
|
|
|
<div class="dropdown">
|
|
|
|
<div class="js-toggle"></div>
|
|
|
|
<div class="dropdown-content"></div>
|
|
|
|
<div class="js-confirm-button"></div>
|
|
|
|
</div>
|
|
|
|
`);
|
|
|
|
this.$toggleButton = this.$content.find('.js-toggle');
|
|
|
|
this.$confirmButton = this.$content.find('.js-confirm-button');
|
|
|
|
|
|
|
|
this.sidebarMoveIssue = new SidebarMoveIssue(
|
|
|
|
this.mediator,
|
|
|
|
this.$toggleButton,
|
|
|
|
this.$confirmButton,
|
|
|
|
);
|
|
|
|
this.sidebarMoveIssue.init();
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
SidebarService.singleton = null;
|
|
|
|
SidebarStore.singleton = null;
|
|
|
|
SidebarMediator.singleton = null;
|
|
|
|
|
|
|
|
this.sidebarMoveIssue.destroy();
|
|
|
|
|
|
|
|
Vue.http.interceptors = _.without(Vue.http.interceptors, Mock.sidebarMockInterceptor);
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('init', () => {
|
|
|
|
it('should initialize the dropdown and listeners', () => {
|
|
|
|
spyOn(this.sidebarMoveIssue, 'initDropdown');
|
|
|
|
spyOn(this.sidebarMoveIssue, 'addEventListeners');
|
|
|
|
|
|
|
|
this.sidebarMoveIssue.init();
|
|
|
|
|
|
|
|
expect(this.sidebarMoveIssue.initDropdown).toHaveBeenCalled();
|
|
|
|
expect(this.sidebarMoveIssue.addEventListeners).toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('destroy', () => {
|
|
|
|
it('should remove the listeners', () => {
|
|
|
|
spyOn(this.sidebarMoveIssue, 'removeEventListeners');
|
|
|
|
|
|
|
|
this.sidebarMoveIssue.destroy();
|
|
|
|
|
|
|
|
expect(this.sidebarMoveIssue.removeEventListeners).toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('initDropdown', () => {
|
|
|
|
it('should initialize the gl_dropdown', () => {
|
|
|
|
spyOn($.fn, 'glDropdown');
|
|
|
|
|
|
|
|
this.sidebarMoveIssue.initDropdown();
|
|
|
|
|
|
|
|
expect($.fn.glDropdown).toHaveBeenCalled();
|
|
|
|
});
|
2018-05-01 15:08:00 +05:30
|
|
|
|
|
|
|
it('escapes html from project name', (done) => {
|
|
|
|
this.$toggleButton.dropdown('toggle');
|
|
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
expect(this.$content.find('.js-move-issue-dropdown-item')[1].innerHTML.trim()).toEqual('<img src=x onerror=alert(document.domain)> foo / bar');
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
describe('onConfirmClicked', () => {
|
|
|
|
it('should move the issue with valid project ID', () => {
|
|
|
|
spyOn(this.mediator, 'moveIssue').and.returnValue(Promise.resolve());
|
|
|
|
this.mediator.setMoveToProjectId(7);
|
|
|
|
|
|
|
|
this.sidebarMoveIssue.onConfirmClicked();
|
|
|
|
|
|
|
|
expect(this.mediator.moveIssue).toHaveBeenCalled();
|
2018-03-27 19:54:05 +05:30
|
|
|
expect(this.$confirmButton.prop('disabled')).toBeTruthy();
|
2018-03-17 18:26:18 +05:30
|
|
|
expect(this.$confirmButton.hasClass('is-loading')).toBe(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should remove loading state from confirm button on failure', (done) => {
|
|
|
|
spyOn(window, 'Flash');
|
|
|
|
spyOn(this.mediator, 'moveIssue').and.returnValue(Promise.reject());
|
|
|
|
this.mediator.setMoveToProjectId(7);
|
|
|
|
|
|
|
|
this.sidebarMoveIssue.onConfirmClicked();
|
|
|
|
|
|
|
|
expect(this.mediator.moveIssue).toHaveBeenCalled();
|
|
|
|
// Wait for the move issue request to fail
|
|
|
|
setTimeout(() => {
|
|
|
|
expect(window.Flash).toHaveBeenCalled();
|
2018-03-27 19:54:05 +05:30
|
|
|
expect(this.$confirmButton.prop('disabled')).toBeFalsy();
|
2018-03-17 18:26:18 +05:30
|
|
|
expect(this.$confirmButton.hasClass('is-loading')).toBe(false);
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should not move the issue with id=0', () => {
|
|
|
|
spyOn(this.mediator, 'moveIssue');
|
|
|
|
this.mediator.setMoveToProjectId(0);
|
|
|
|
|
|
|
|
this.sidebarMoveIssue.onConfirmClicked();
|
|
|
|
|
|
|
|
expect(this.mediator.moveIssue).not.toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should set moveToProjectId on dropdown item "No project" click', (done) => {
|
|
|
|
spyOn(this.mediator, 'setMoveToProjectId');
|
|
|
|
|
|
|
|
// Open the dropdown
|
|
|
|
this.$toggleButton.dropdown('toggle');
|
|
|
|
|
|
|
|
// Wait for the autocomplete request to finish
|
|
|
|
setTimeout(() => {
|
|
|
|
this.$content.find('.js-move-issue-dropdown-item').eq(0).trigger('click');
|
|
|
|
|
|
|
|
expect(this.mediator.setMoveToProjectId).toHaveBeenCalledWith(0);
|
2018-03-27 19:54:05 +05:30
|
|
|
expect(this.$confirmButton.prop('disabled')).toBeTruthy();
|
2018-03-17 18:26:18 +05:30
|
|
|
done();
|
|
|
|
}, 0);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should set moveToProjectId on dropdown item click', (done) => {
|
|
|
|
spyOn(this.mediator, 'setMoveToProjectId');
|
|
|
|
|
|
|
|
// Open the dropdown
|
|
|
|
this.$toggleButton.dropdown('toggle');
|
|
|
|
|
|
|
|
// Wait for the autocomplete request to finish
|
|
|
|
setTimeout(() => {
|
|
|
|
this.$content.find('.js-move-issue-dropdown-item').eq(1).trigger('click');
|
|
|
|
|
|
|
|
expect(this.mediator.setMoveToProjectId).toHaveBeenCalledWith(20);
|
|
|
|
expect(this.$confirmButton.attr('disabled')).toBe(undefined);
|
|
|
|
done();
|
|
|
|
}, 0);
|
|
|
|
});
|
|
|
|
});
|