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

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

141 lines
4 KiB
JavaScript
Raw Normal View History

2022-04-04 11:22:00 +05:30
import { shallowMount } from '@vue/test-utils';
import Vue, { nextTick } from 'vue';
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
2022-04-04 11:22:00 +05:30
import { mockList, mockGroupProjects, mockIssue, mockIssue2 } from '../mock_data';
2021-01-29 00:20:46 +05:30
2022-04-04 11:22:00 +05:30
Vue.use(Vuex);
2021-01-29 00:20:46 +05:30
2021-10-27 15:23:28 +05:30
const addListNewIssuesSpy = jest.fn().mockResolvedValue();
const mockActions = { addListNewIssue: addListNewIssuesSpy };
const createComponent = ({
2023-03-17 16:20:25 +05:30
state = { selectedProject: mockGroupProjects[0] },
2021-10-27 15:23:28 +05:30
actions = mockActions,
2023-03-17 16:20:25 +05:30
getters = { getBoardItemsByList: () => () => [] },
isGroupBoard = true,
2021-10-27 15:23:28 +05:30
} = {}) =>
shallowMount(BoardNewIssue, {
store: new Vuex.Store({
state,
actions,
getters,
}),
propsData: {
list: mockList,
},
provide: {
groupId: 1,
2023-03-17 16:20:25 +05:30
fullPath: mockGroupProjects[0].fullPath,
2021-10-27 15:23:28 +05:30
weightFeatureAvailable: false,
boardWeight: null,
2023-03-17 16:20:25 +05:30
isGroupBoard,
2021-10-27 15:23:28 +05:30
},
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
2022-04-04 11:22:00 +05:30
await nextTick();
2021-01-29 00:20:46 +05:30
});
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' });
2022-04-04 11:22:00 +05:30
await nextTick();
2021-10-27 15:23:28 +05:30
expect(addListNewIssuesSpy).toHaveBeenCalledWith(expect.any(Object), {
list: mockList,
issueInput: {
title: 'Foo',
labelIds: [],
assigneeIds: [],
milestoneId: undefined,
projectPath: mockGroupProjects[0].fullPath,
2022-04-04 11:22:00 +05:30
moveAfterId: undefined,
2021-10-27 15:23:28 +05:30
},
});
2021-01-29 00:20:46 +05:30
});
2022-04-04 11:22:00 +05:30
describe('when list has an existing issues', () => {
beforeEach(() => {
wrapper = createComponent({
getters: {
getBoardItemsByList: () => () => [mockIssue, mockIssue2],
},
2023-03-17 16:20:25 +05:30
isGroupBoard: true,
2022-04-04 11:22:00 +05:30
});
});
2022-10-11 01:57:18 +05:30
it('uses the first issue ID as moveAfterId', async () => {
2022-04-04 11:22:00 +05:30
findBoardNewItem().vm.$emit('form-submit', { title: 'Foo' });
await nextTick();
expect(addListNewIssuesSpy).toHaveBeenCalledWith(expect.any(Object), {
list: mockList,
issueInput: {
title: 'Foo',
labelIds: [],
assigneeIds: [],
milestoneId: undefined,
projectPath: mockGroupProjects[0].fullPath,
moveAfterId: mockIssue.id,
},
});
});
});
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
2022-04-04 11:22:00 +05:30
await nextTick();
2021-10-27 15:23:28 +05:30
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({
2023-03-17 16:20:25 +05:30
isGroupBoard: false,
2021-10-27 15:23:28 +05:30
});
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
});
});
});