debian-mirror-gitlab/spec/frontend/boards/components/board_new_issue_spec.js

115 lines
3.3 KiB
JavaScript
Raw Normal View History

2021-01-29 00:20:46 +05:30
import { shallowMount, createLocalVue } from '@vue/test-utils';
2021-03-11 19:13:27 +05:30
import Vuex from 'vuex';
2021-03-08 18:12:59 +05:30
import BoardNewIssue from '~/boards/components/board_new_issue.vue';
2021-10-27 15:23:28 +05:30
import BoardNewItem from '~/boards/components/board_new_item.vue';
import ProjectSelect from '~/boards/components/project_select.vue';
import eventHub from '~/boards/eventhub';
2021-01-29 00:20:46 +05:30
2021-03-08 18:12:59 +05:30
import { mockList, mockGroupProjects } from '../mock_data';
2021-01-29 00:20:46 +05:30
const localVue = createLocalVue();
localVue.use(Vuex);
2021-10-27 15:23:28 +05:30
const addListNewIssuesSpy = jest.fn().mockResolvedValue();
const mockActions = { addListNewIssue: addListNewIssuesSpy };
const createComponent = ({
state = { selectedProject: mockGroupProjects[0], fullPath: mockGroupProjects[0].fullPath },
actions = mockActions,
getters = { isGroupBoard: () => true, isProjectBoard: () => false },
} = {}) =>
shallowMount(BoardNewIssue, {
localVue,
store: new Vuex.Store({
state,
actions,
getters,
}),
propsData: {
list: mockList,
},
provide: {
groupId: 1,
weightFeatureAvailable: false,
boardWeight: null,
},
stubs: {
BoardNewItem,
},
});
2021-01-29 00:20:46 +05:30
describe('Issue boards new issue form', () => {
let wrapper;
2021-10-27 15:23:28 +05:30
const findBoardNewItem = () => wrapper.findComponent(BoardNewItem);
2021-01-29 00:20:46 +05:30
2021-10-27 15:23:28 +05:30
beforeEach(async () => {
wrapper = createComponent();
2021-01-29 00:20:46 +05:30
2021-10-27 15:23:28 +05:30
await wrapper.vm.$nextTick();
2021-01-29 00:20:46 +05:30
});
afterEach(() => {
wrapper.destroy();
});
2021-10-27 15:23:28 +05:30
it('renders board-new-item component', () => {
const boardNewItem = findBoardNewItem();
expect(boardNewItem.exists()).toBe(true);
expect(boardNewItem.props()).toEqual({
list: mockList,
formEventPrefix: 'toggle-issue-form-',
submitButtonTitle: 'Create issue',
disableSubmit: false,
});
2021-01-29 00:20:46 +05:30
});
2021-10-27 15:23:28 +05:30
it('calls addListNewIssue action when `board-new-item` emits form-submit event', async () => {
findBoardNewItem().vm.$emit('form-submit', { title: 'Foo' });
await wrapper.vm.$nextTick();
expect(addListNewIssuesSpy).toHaveBeenCalledWith(expect.any(Object), {
list: mockList,
issueInput: {
title: 'Foo',
labelIds: [],
assigneeIds: [],
milestoneId: undefined,
projectPath: mockGroupProjects[0].fullPath,
},
});
2021-01-29 00:20:46 +05:30
});
2021-10-27 15:23:28 +05:30
it('emits event `toggle-issue-form` with current list Id suffix on eventHub when `board-new-item` emits form-cancel event', async () => {
jest.spyOn(eventHub, '$emit').mockImplementation();
findBoardNewItem().vm.$emit('form-cancel');
2021-01-29 00:20:46 +05:30
2021-10-27 15:23:28 +05:30
await wrapper.vm.$nextTick();
expect(eventHub.$emit).toHaveBeenCalledWith(`toggle-issue-form-${mockList.id}`);
2021-01-29 00:20:46 +05:30
});
2021-10-27 15:23:28 +05:30
describe('when in group issue board', () => {
it('renders project-select component within board-new-item component', () => {
const projectSelect = findBoardNewItem().findComponent(ProjectSelect);
2021-01-29 00:20:46 +05:30
2021-10-27 15:23:28 +05:30
expect(projectSelect.exists()).toBe(true);
expect(projectSelect.props('list')).toEqual(mockList);
2021-01-29 00:20:46 +05:30
});
2021-10-27 15:23:28 +05:30
});
2021-01-29 00:20:46 +05:30
2021-10-27 15:23:28 +05:30
describe('when in project issue board', () => {
beforeEach(() => {
wrapper = createComponent({
getters: { isGroupBoard: () => false, isProjectBoard: () => true },
});
2021-01-29 00:20:46 +05:30
});
2021-10-27 15:23:28 +05:30
it('does not render project-select component within board-new-item component', () => {
const projectSelect = findBoardNewItem().findComponent(ProjectSelect);
2021-01-29 00:20:46 +05:30
2021-10-27 15:23:28 +05:30
expect(projectSelect.exists()).toBe(false);
2021-01-29 00:20:46 +05:30
});
});
});