debian-mirror-gitlab/spec/frontend/sidebar/sidebar_assignees_spec.js

100 lines
2.8 KiB
JavaScript
Raw Normal View History

2020-04-22 19:07:51 +05:30
import { shallowMount } from '@vue/test-utils';
import axios from 'axios';
2021-03-11 19:13:27 +05:30
import AxiosMockAdapter from 'axios-mock-adapter';
2022-04-04 11:22:00 +05:30
import { nextTick } from 'vue';
2020-04-22 19:07:51 +05:30
import Assigness from '~/sidebar/components/assignees/assignees.vue';
2020-05-24 23:13:21 +05:30
import AssigneesRealtime from '~/sidebar/components/assignees/assignees_realtime.vue';
2021-03-11 19:13:27 +05:30
import SidebarAssignees from '~/sidebar/components/assignees/sidebar_assignees.vue';
2020-04-22 19:07:51 +05:30
import SidebarService from '~/sidebar/services/sidebar_service';
2021-03-11 19:13:27 +05:30
import SidebarMediator from '~/sidebar/sidebar_mediator';
2020-04-22 19:07:51 +05:30
import SidebarStore from '~/sidebar/stores/sidebar_store';
import Mock from './mock_data';
describe('sidebar assignees', () => {
let wrapper;
let mediator;
let axiosMock;
2022-05-07 20:08:51 +05:30
const createComponent = (props) => {
2020-04-22 19:07:51 +05:30
wrapper = shallowMount(SidebarAssignees, {
propsData: {
2020-05-24 23:13:21 +05:30
issuableIid: '1',
2021-06-08 01:23:25 +05:30
issuableId: 1,
2020-04-22 19:07:51 +05:30
mediator,
field: '',
2020-05-24 23:13:21 +05:30
projectPath: 'projectPath',
2021-01-03 14:25:43 +05:30
changing: false,
2020-05-24 23:13:21 +05:30
...props,
},
2020-04-22 19:07:51 +05:30
// Attaching to document is required because this component emits something from the parent element :/
2021-03-08 18:12:59 +05:30
attachTo: document.body,
2020-04-22 19:07:51 +05:30
});
};
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-24 23:13:21 +05:30
createComponent();
2020-04-22 19:07:51 +05:30
expect(mediator.saveAssignees).not.toHaveBeenCalled();
wrapper.vm.saveAssignees();
expect(mediator.saveAssignees).toHaveBeenCalled();
});
it('calls the mediator when "assignSelf" method is called', () => {
2020-05-24 23:13:21 +05:30
createComponent();
2020-04-22 19:07:51 +05:30
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-04-04 11:22:00 +05:30
it('hides assignees until fetched', async () => {
2020-05-24 23:13:21 +05:30
createComponent();
2022-11-25 23:54:43 +05:30
expect(wrapper.findComponent(Assigness).exists()).toBe(false);
2020-04-22 19:07:51 +05:30
wrapper.vm.store.isFetching.assignees = false;
2022-04-04 11:22:00 +05:30
await nextTick();
2022-11-25 23:54:43 +05:30
expect(wrapper.findComponent(Assigness).exists()).toBe(true);
2020-04-22 19:07:51 +05:30
});
2020-05-24 23:13:21 +05:30
2022-05-07 20:08:51 +05:30
describe('when issuableType is issue', () => {
it('finds AssigneesRealtime component', () => {
createComponent();
2020-05-24 23:13:21 +05:30
2022-11-25 23:54:43 +05:30
expect(wrapper.findComponent(AssigneesRealtime).exists()).toBe(true);
2020-05-24 23:13:21 +05:30
});
});
2022-05-07 20:08:51 +05:30
describe('when issuableType is MR', () => {
it('does not find AssigneesRealtime component', () => {
createComponent({ issuableType: 'MR' });
2020-05-24 23:13:21 +05:30
2022-11-25 23:54:43 +05:30
expect(wrapper.findComponent(AssigneesRealtime).exists()).toBe(false);
2020-05-24 23:13:21 +05:30
});
});
2020-04-22 19:07:51 +05:30
});