2018-03-17 18:26:18 +05:30
|
|
|
import _ from 'underscore';
|
2017-08-17 22:00:37 +05:30
|
|
|
import Vue from 'vue';
|
2018-03-27 19:54:05 +05:30
|
|
|
import SidebarAssignees from '~/sidebar/components/assignees/sidebar_assignees.vue';
|
2017-08-17 22:00:37 +05:30
|
|
|
import SidebarMediator from '~/sidebar/sidebar_mediator';
|
|
|
|
import SidebarService from '~/sidebar/services/sidebar_service';
|
|
|
|
import SidebarStore from '~/sidebar/stores/sidebar_store';
|
2018-03-27 19:54:05 +05:30
|
|
|
import mountComponent from 'spec/helpers/vue_mount_component_helper';
|
2017-08-17 22:00:37 +05:30
|
|
|
import Mock from './mock_data';
|
|
|
|
|
|
|
|
describe('sidebar assignees', () => {
|
2018-03-17 18:26:18 +05:30
|
|
|
let vm;
|
|
|
|
let mediator;
|
|
|
|
let sidebarAssigneesEl;
|
2019-05-18 00:54:41 +05:30
|
|
|
preloadFixtures('issues/open-issue.html');
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
Vue.http.interceptors.push(Mock.sidebarMockInterceptor);
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2019-05-18 00:54:41 +05:30
|
|
|
loadFixtures('issues/open-issue.html');
|
2018-03-17 18:26:18 +05:30
|
|
|
|
|
|
|
mediator = new SidebarMediator(Mock.mediator);
|
|
|
|
spyOn(mediator, 'saveAssignees').and.callThrough();
|
|
|
|
spyOn(mediator, 'assignYourself').and.callThrough();
|
|
|
|
|
|
|
|
const SidebarAssigneeComponent = Vue.extend(SidebarAssignees);
|
|
|
|
sidebarAssigneesEl = document.querySelector('#js-vue-sidebar-assignees');
|
2018-12-13 13:39:08 +05:30
|
|
|
vm = mountComponent(
|
|
|
|
SidebarAssigneeComponent,
|
|
|
|
{
|
|
|
|
mediator,
|
|
|
|
field: sidebarAssigneesEl.dataset.field,
|
|
|
|
},
|
|
|
|
sidebarAssigneesEl,
|
|
|
|
);
|
2017-08-17 22:00:37 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
SidebarService.singleton = null;
|
|
|
|
SidebarStore.singleton = null;
|
|
|
|
SidebarMediator.singleton = null;
|
2017-09-10 17:25:29 +05:30
|
|
|
Vue.http.interceptors = _.without(Vue.http.interceptors, Mock.sidebarMockInterceptor);
|
2017-08-17 22:00:37 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('calls the mediator when saves the assignees', () => {
|
2018-03-17 18:26:18 +05:30
|
|
|
vm.saveAssignees();
|
2018-12-13 13:39:08 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
expect(mediator.saveAssignees).toHaveBeenCalled();
|
2017-08-17 22:00:37 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('calls the mediator when "assignSelf" method is called', () => {
|
2018-03-17 18:26:18 +05:30
|
|
|
vm.assignSelf();
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
expect(mediator.assignYourself).toHaveBeenCalled();
|
|
|
|
expect(mediator.store.assignees.length).toEqual(1);
|
2017-08-17 22:00:37 +05:30
|
|
|
});
|
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
it('hides assignees until fetched', done => {
|
2018-03-17 18:26:18 +05:30
|
|
|
const currentAssignee = sidebarAssigneesEl.querySelector('.value');
|
2018-12-13 13:39:08 +05:30
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
expect(currentAssignee).toBe(null);
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
vm.store.isFetching.assignees = false;
|
2017-08-17 22:00:37 +05:30
|
|
|
Vue.nextTick(() => {
|
2018-03-17 18:26:18 +05:30
|
|
|
expect(vm.$el.querySelector('.value')).toBeVisible();
|
2017-08-17 22:00:37 +05:30
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|