2022-01-21 10:13:54 -05:00
|
|
|
import { shallowMount } from '@vue/test-utils';
|
2022-01-25 10:12:32 -05:00
|
|
|
import Vue, { nextTick } from 'vue';
|
2021-02-14 13:09:20 -05:00
|
|
|
import Vuex from 'vuex';
|
2021-01-18 04:11:05 -05:00
|
|
|
import BoardNewIssue from '~/boards/components/board_new_issue.vue';
|
2021-07-20 20:09:07 -04:00
|
|
|
import BoardNewItem from '~/boards/components/board_new_item.vue';
|
|
|
|
import ProjectSelect from '~/boards/components/project_select.vue';
|
|
|
|
import eventHub from '~/boards/eventhub';
|
2020-11-12 04:08:57 -05:00
|
|
|
|
2022-02-16 07:13:53 -05:00
|
|
|
import { mockList, mockGroupProjects, mockIssue, mockIssue2 } from '../mock_data';
|
2020-11-12 04:08:57 -05:00
|
|
|
|
2022-01-21 10:13:54 -05:00
|
|
|
Vue.use(Vuex);
|
2020-11-12 04:08:57 -05:00
|
|
|
|
2021-07-20 20:09:07 -04:00
|
|
|
const addListNewIssuesSpy = jest.fn().mockResolvedValue();
|
|
|
|
const mockActions = { addListNewIssue: addListNewIssuesSpy };
|
|
|
|
|
|
|
|
const createComponent = ({
|
|
|
|
state = { selectedProject: mockGroupProjects[0], fullPath: mockGroupProjects[0].fullPath },
|
|
|
|
actions = mockActions,
|
2022-02-16 07:13:53 -05:00
|
|
|
getters = { isGroupBoard: () => true, getBoardItemsByList: () => () => [] },
|
2021-07-20 20:09:07 -04:00
|
|
|
} = {}) =>
|
|
|
|
shallowMount(BoardNewIssue, {
|
|
|
|
store: new Vuex.Store({
|
|
|
|
state,
|
|
|
|
actions,
|
|
|
|
getters,
|
|
|
|
}),
|
|
|
|
propsData: {
|
|
|
|
list: mockList,
|
|
|
|
},
|
|
|
|
provide: {
|
|
|
|
groupId: 1,
|
|
|
|
weightFeatureAvailable: false,
|
|
|
|
boardWeight: null,
|
|
|
|
},
|
|
|
|
stubs: {
|
|
|
|
BoardNewItem,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2020-11-12 04:08:57 -05:00
|
|
|
describe('Issue boards new issue form', () => {
|
|
|
|
let wrapper;
|
|
|
|
|
2021-07-20 20:09:07 -04:00
|
|
|
const findBoardNewItem = () => wrapper.findComponent(BoardNewItem);
|
2020-11-12 04:08:57 -05:00
|
|
|
|
2021-07-20 20:09:07 -04:00
|
|
|
beforeEach(async () => {
|
|
|
|
wrapper = createComponent();
|
2020-11-12 04:08:57 -05:00
|
|
|
|
2022-01-25 10:12:32 -05:00
|
|
|
await nextTick();
|
2020-11-12 04:08:57 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
wrapper.destroy();
|
|
|
|
});
|
|
|
|
|
2021-07-20 20:09:07 -04:00
|
|
|
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,
|
|
|
|
});
|
2020-11-12 04:08:57 -05:00
|
|
|
});
|
|
|
|
|
2021-07-20 20:09:07 -04:00
|
|
|
it('calls addListNewIssue action when `board-new-item` emits form-submit event', async () => {
|
|
|
|
findBoardNewItem().vm.$emit('form-submit', { title: 'Foo' });
|
|
|
|
|
2022-01-25 10:12:32 -05:00
|
|
|
await nextTick();
|
2021-07-20 20:09:07 -04:00
|
|
|
expect(addListNewIssuesSpy).toHaveBeenCalledWith(expect.any(Object), {
|
|
|
|
list: mockList,
|
|
|
|
issueInput: {
|
|
|
|
title: 'Foo',
|
|
|
|
labelIds: [],
|
|
|
|
assigneeIds: [],
|
|
|
|
milestoneId: undefined,
|
|
|
|
projectPath: mockGroupProjects[0].fullPath,
|
2022-02-16 07:13:53 -05:00
|
|
|
moveAfterId: undefined,
|
2021-07-20 20:09:07 -04:00
|
|
|
},
|
|
|
|
});
|
2020-11-12 04:08:57 -05:00
|
|
|
});
|
|
|
|
|
2022-02-16 07:13:53 -05:00
|
|
|
describe('when list has an existing issues', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
wrapper = createComponent({
|
|
|
|
getters: {
|
|
|
|
isGroupBoard: () => true,
|
|
|
|
getBoardItemsByList: () => () => [mockIssue, mockIssue2],
|
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2022-09-16 14:10:35 -04:00
|
|
|
it('uses the first issue ID as moveAfterId', async () => {
|
2022-02-16 07:13:53 -05:00
|
|
|
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-07-20 20:09:07 -04:00
|
|
|
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');
|
2020-11-12 04:08:57 -05:00
|
|
|
|
2022-01-25 10:12:32 -05:00
|
|
|
await nextTick();
|
2021-07-20 20:09:07 -04:00
|
|
|
expect(eventHub.$emit).toHaveBeenCalledWith(`toggle-issue-form-${mockList.id}`);
|
2020-11-12 04:08:57 -05:00
|
|
|
});
|
|
|
|
|
2021-07-20 20:09:07 -04:00
|
|
|
describe('when in group issue board', () => {
|
|
|
|
it('renders project-select component within board-new-item component', () => {
|
|
|
|
const projectSelect = findBoardNewItem().findComponent(ProjectSelect);
|
2020-11-12 04:08:57 -05:00
|
|
|
|
2021-07-20 20:09:07 -04:00
|
|
|
expect(projectSelect.exists()).toBe(true);
|
|
|
|
expect(projectSelect.props('list')).toEqual(mockList);
|
2020-11-12 04:08:57 -05:00
|
|
|
});
|
2021-07-20 20:09:07 -04:00
|
|
|
});
|
2020-11-12 04:08:57 -05:00
|
|
|
|
2021-07-20 20:09:07 -04:00
|
|
|
describe('when in project issue board', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
wrapper = createComponent({
|
2022-02-16 07:13:53 -05:00
|
|
|
getters: { isGroupBoard: () => false },
|
2021-07-20 20:09:07 -04:00
|
|
|
});
|
2020-11-12 04:08:57 -05:00
|
|
|
});
|
|
|
|
|
2021-07-20 20:09:07 -04:00
|
|
|
it('does not render project-select component within board-new-item component', () => {
|
|
|
|
const projectSelect = findBoardNewItem().findComponent(ProjectSelect);
|
2020-11-12 04:08:57 -05:00
|
|
|
|
2021-07-20 20:09:07 -04:00
|
|
|
expect(projectSelect.exists()).toBe(false);
|
2020-11-12 04:08:57 -05:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|