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

69 lines
2 KiB
JavaScript
Raw Normal View History

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