gitlab-org--gitlab-foss/spec/javascripts/sidebar/sidebar_assignees_spec.js

69 lines
2.0 KiB
JavaScript
Raw Normal View History

2017-12-19 10:12:32 +00:00
import _ from 'underscore';
2017-05-05 18:23:31 +00:00
import Vue from 'vue';
2018-02-27 18:06:55 +00:00
import SidebarAssignees from '~/sidebar/components/assignees/sidebar_assignees.vue';
2017-05-05 18:23:31 +00:00
import SidebarMediator from '~/sidebar/sidebar_mediator';
import SidebarService from '~/sidebar/services/sidebar_service';
import SidebarStore from '~/sidebar/stores/sidebar_store';
import mountComponent from 'spec/helpers/vue_mount_component_helper';
2017-05-05 18:23:31 +00:00
import Mock from './mock_data';
describe('sidebar assignees', () => {
2017-12-07 17:37:33 +00:00
let vm;
let mediator;
let sidebarAssigneesEl;
preloadFixtures('issues/open-issue.html');
2017-05-05 18:23:31 +00:00
beforeEach(() => {
Vue.http.interceptors.push(Mock.sidebarMockInterceptor);
2017-12-07 17:37:33 +00:00
loadFixtures('issues/open-issue.html');
2017-12-07 17:37:33 +00:00
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-10-17 07:13:26 +00:00
vm = mountComponent(
SidebarAssigneeComponent,
{
mediator,
field: sidebarAssigneesEl.dataset.field,
},
sidebarAssigneesEl,
);
2017-05-05 18:23:31 +00:00
});
afterEach(() => {
SidebarService.singleton = null;
SidebarStore.singleton = null;
SidebarMediator.singleton = null;
Vue.http.interceptors = _.without(Vue.http.interceptors, Mock.sidebarMockInterceptor);
2017-05-05 18:23:31 +00:00
});
it('calls the mediator when saves the assignees', () => {
2017-12-07 17:37:33 +00:00
vm.saveAssignees();
2018-10-09 18:03:09 +00:00
2017-12-07 17:37:33 +00:00
expect(mediator.saveAssignees).toHaveBeenCalled();
2017-05-05 18:23:31 +00:00
});
it('calls the mediator when "assignSelf" method is called', () => {
2017-12-07 17:37:33 +00:00
vm.assignSelf();
2017-05-05 18:23:31 +00:00
2017-12-07 17:37:33 +00:00
expect(mediator.assignYourself).toHaveBeenCalled();
expect(mediator.store.assignees.length).toEqual(1);
2017-05-05 18:23:31 +00:00
});
2018-10-17 07:13:26 +00:00
it('hides assignees until fetched', done => {
2017-12-07 17:37:33 +00:00
const currentAssignee = sidebarAssigneesEl.querySelector('.value');
2018-10-09 18:03:09 +00:00
expect(currentAssignee).toBe(null);
2017-12-07 17:37:33 +00:00
vm.store.isFetching.assignees = false;
Vue.nextTick(() => {
2017-12-07 17:37:33 +00:00
expect(vm.$el.querySelector('.value')).toBeVisible();
done();
});
});
2017-05-05 18:23:31 +00:00
});