2020-04-16 02:09:39 -04:00
|
|
|
import { shallowMount } from '@vue/test-utils';
|
|
|
|
import axios from 'axios';
|
2021-02-14 13:09:20 -05:00
|
|
|
import AxiosMockAdapter from 'axios-mock-adapter';
|
2022-01-25 07:14:14 -05:00
|
|
|
import { nextTick } from 'vue';
|
2020-04-16 02:09:39 -04:00
|
|
|
import Assigness from '~/sidebar/components/assignees/assignees.vue';
|
2020-05-04 08:09:46 -04:00
|
|
|
import AssigneesRealtime from '~/sidebar/components/assignees/assignees_realtime.vue';
|
2021-02-14 13:09:20 -05:00
|
|
|
import SidebarAssignees from '~/sidebar/components/assignees/sidebar_assignees.vue';
|
2020-04-16 02:09:39 -04:00
|
|
|
import SidebarService from '~/sidebar/services/sidebar_service';
|
2021-02-14 13:09:20 -05:00
|
|
|
import SidebarMediator from '~/sidebar/sidebar_mediator';
|
2020-04-16 02:09:39 -04:00
|
|
|
import SidebarStore from '~/sidebar/stores/sidebar_store';
|
|
|
|
import Mock from './mock_data';
|
|
|
|
|
|
|
|
describe('sidebar assignees', () => {
|
|
|
|
let wrapper;
|
|
|
|
let mediator;
|
|
|
|
let axiosMock;
|
2020-05-04 08:09:46 -04:00
|
|
|
const createComponent = (realTimeIssueSidebar = false, props) => {
|
2020-04-16 02:09:39 -04:00
|
|
|
wrapper = shallowMount(SidebarAssignees, {
|
|
|
|
propsData: {
|
2020-05-04 08:09:46 -04:00
|
|
|
issuableIid: '1',
|
2021-04-26 05:09:53 -04:00
|
|
|
issuableId: 1,
|
2020-04-16 02:09:39 -04:00
|
|
|
mediator,
|
|
|
|
field: '',
|
2020-05-04 08:09:46 -04:00
|
|
|
projectPath: 'projectPath',
|
2020-10-14 08:08:58 -04:00
|
|
|
changing: false,
|
2020-05-04 08:09:46 -04:00
|
|
|
...props,
|
|
|
|
},
|
|
|
|
provide: {
|
|
|
|
glFeatures: {
|
|
|
|
realTimeIssueSidebar,
|
|
|
|
},
|
2020-04-16 02:09:39 -04:00
|
|
|
},
|
|
|
|
// Attaching to document is required because this component emits something from the parent element :/
|
2020-12-25 13:10:00 -05:00
|
|
|
attachTo: document.body,
|
2020-04-16 02:09:39 -04:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
axiosMock = new AxiosMockAdapter(axios);
|
|
|
|
mediator = new SidebarMediator(Mock.mediator);
|
|
|
|
|
|
|
|
jest.spyOn(mediator, 'saveAssignees');
|
|
|
|
jest.spyOn(mediator, 'assignYourself');
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
wrapper.destroy();
|
|
|
|
wrapper = null;
|
|
|
|
|
|
|
|
SidebarService.singleton = null;
|
|
|
|
SidebarStore.singleton = null;
|
|
|
|
SidebarMediator.singleton = null;
|
|
|
|
axiosMock.restore();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('calls the mediator when saves the assignees', () => {
|
2020-05-04 08:09:46 -04:00
|
|
|
createComponent();
|
|
|
|
|
2020-04-16 02:09:39 -04:00
|
|
|
expect(mediator.saveAssignees).not.toHaveBeenCalled();
|
|
|
|
|
|
|
|
wrapper.vm.saveAssignees();
|
|
|
|
|
|
|
|
expect(mediator.saveAssignees).toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('calls the mediator when "assignSelf" method is called', () => {
|
2020-05-04 08:09:46 -04:00
|
|
|
createComponent();
|
|
|
|
|
2020-04-16 02:09:39 -04:00
|
|
|
expect(mediator.assignYourself).not.toHaveBeenCalled();
|
|
|
|
expect(mediator.store.assignees.length).toBe(0);
|
|
|
|
|
|
|
|
wrapper.vm.assignSelf();
|
|
|
|
|
|
|
|
expect(mediator.assignYourself).toHaveBeenCalled();
|
|
|
|
expect(mediator.store.assignees.length).toBe(1);
|
|
|
|
});
|
|
|
|
|
2022-01-25 07:14:14 -05:00
|
|
|
it('hides assignees until fetched', async () => {
|
2020-05-04 08:09:46 -04:00
|
|
|
createComponent();
|
|
|
|
|
2020-04-16 02:09:39 -04:00
|
|
|
expect(wrapper.find(Assigness).exists()).toBe(false);
|
|
|
|
|
|
|
|
wrapper.vm.store.isFetching.assignees = false;
|
|
|
|
|
2022-01-25 07:14:14 -05:00
|
|
|
await nextTick();
|
|
|
|
expect(wrapper.find(Assigness).exists()).toBe(true);
|
2020-04-16 02:09:39 -04:00
|
|
|
});
|
2020-05-04 08:09:46 -04:00
|
|
|
|
|
|
|
describe('when realTimeIssueSidebar is turned on', () => {
|
|
|
|
describe('when issuableType is issue', () => {
|
|
|
|
it('finds AssigneesRealtime componeont', () => {
|
|
|
|
createComponent(true);
|
|
|
|
|
|
|
|
expect(wrapper.find(AssigneesRealtime).exists()).toBe(true);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('when issuableType is MR', () => {
|
|
|
|
it('does not find AssigneesRealtime componeont', () => {
|
|
|
|
createComponent(true, { issuableType: 'MR' });
|
|
|
|
|
|
|
|
expect(wrapper.find(AssigneesRealtime).exists()).toBe(false);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('when realTimeIssueSidebar is turned off', () => {
|
|
|
|
it('does not find AssigneesRealtime', () => {
|
|
|
|
createComponent(false, { issuableType: 'issue' });
|
|
|
|
|
|
|
|
expect(wrapper.find(AssigneesRealtime).exists()).toBe(false);
|
|
|
|
});
|
|
|
|
});
|
2020-04-16 02:09:39 -04:00
|
|
|
});
|