Commit 8701d44c authored by sstern's avatar sstern

Mv sidebar_assignees to jest

parent 383c0d19
import Vue from 'vue'; import { shallowMount } from '@vue/test-utils';
import mountComponent from 'spec/helpers/vue_mount_component_helper'; import AxiosMockAdapter from 'axios-mock-adapter';
import axios from 'axios';
import SidebarAssignees from '~/sidebar/components/assignees/sidebar_assignees.vue'; import SidebarAssignees from '~/sidebar/components/assignees/sidebar_assignees.vue';
import Assigness from '~/sidebar/components/assignees/assignees.vue';
import SidebarMediator from '~/sidebar/sidebar_mediator'; import SidebarMediator from '~/sidebar/sidebar_mediator';
import SidebarService from '~/sidebar/services/sidebar_service'; import SidebarService from '~/sidebar/services/sidebar_service';
import SidebarStore from '~/sidebar/stores/sidebar_store'; import SidebarStore from '~/sidebar/stores/sidebar_store';
import Mock from './mock_data'; import Mock from './mock_data';
describe('sidebar assignees', () => { describe('sidebar assignees', () => {
let vm; let wrapper;
let mediator; let mediator;
let sidebarAssigneesEl; let axiosMock;
preloadFixtures('issues/open-issue.html');
beforeEach(() => { const createComponent = () => {
loadFixtures('issues/open-issue.html'); wrapper = shallowMount(SidebarAssignees, {
propsData: {
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');
vm = mountComponent(
SidebarAssigneeComponent,
{
mediator, mediator,
field: sidebarAssigneesEl.dataset.field, field: '',
}, },
sidebarAssigneesEl, // Attaching to document is required because this component emits something from the parent element :/
); attachToDocument: true,
});
};
beforeEach(() => {
axiosMock = new AxiosMockAdapter(axios);
mediator = new SidebarMediator(Mock.mediator);
jest.spyOn(mediator, 'saveAssignees');
jest.spyOn(mediator, 'assignYourself');
createComponent();
}); });
afterEach(() => { afterEach(() => {
wrapper.destroy();
wrapper = null;
SidebarService.singleton = null; SidebarService.singleton = null;
SidebarStore.singleton = null; SidebarStore.singleton = null;
SidebarMediator.singleton = null; SidebarMediator.singleton = null;
axiosMock.restore();
}); });
it('calls the mediator when saves the assignees', () => { it('calls the mediator when saves the assignees', () => {
vm.saveAssignees(); expect(mediator.saveAssignees).not.toHaveBeenCalled();
wrapper.vm.saveAssignees();
expect(mediator.saveAssignees).toHaveBeenCalled(); expect(mediator.saveAssignees).toHaveBeenCalled();
}); });
it('calls the mediator when "assignSelf" method is called', () => { it('calls the mediator when "assignSelf" method is called', () => {
vm.assignSelf(); expect(mediator.assignYourself).not.toHaveBeenCalled();
expect(mediator.store.assignees.length).toBe(0);
wrapper.vm.assignSelf();
expect(mediator.assignYourself).toHaveBeenCalled(); expect(mediator.assignYourself).toHaveBeenCalled();
expect(mediator.store.assignees.length).toEqual(1); expect(mediator.store.assignees.length).toBe(1);
}); });
it('hides assignees until fetched', done => { it('hides assignees until fetched', () => {
const currentAssignee = sidebarAssigneesEl.querySelector('.value'); expect(wrapper.find(Assigness).exists()).toBe(false);
expect(currentAssignee).toBe(null); wrapper.vm.store.isFetching.assignees = false;
vm.store.isFetching.assignees = false; return wrapper.vm.$nextTick(() => {
Vue.nextTick(() => { expect(wrapper.find(Assigness).exists()).toBe(true);
expect(vm.$el.querySelector('.value')).toBeVisible();
done();
}); });
}); });
}); });
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