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

115 lines
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-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);
describe('Issue boards new issue form', () => {
let wrapper;
let vm;
const addListNewIssuesSpy = jest.fn();
const findSubmitButton = () => wrapper.find({ ref: 'submitButton' });
const findCancelButton = () => wrapper.find({ ref: 'cancelButton' });
const findSubmitForm = () => wrapper.find({ ref: 'submitForm' });
const submitIssue = () => {
const dummySubmitEvent = {
preventDefault() {},
};
return findSubmitForm().trigger('submit', dummySubmitEvent);
};
beforeEach(() => {
const store = new Vuex.Store({
2021-03-08 18:12:59 +05:30
state: { selectedProject: mockGroupProjects[0] },
2021-01-29 00:20:46 +05:30
actions: { addListNewIssue: addListNewIssuesSpy },
2021-04-17 20:07:23 +05:30
getters: { isGroupBoard: () => false, isProjectBoard: () => true },
2021-01-29 00:20:46 +05:30
});
wrapper = shallowMount(BoardNewIssue, {
propsData: {
disabled: false,
2021-02-22 17:27:13 +05:30
list: mockList,
2021-01-29 00:20:46 +05:30
},
store,
localVue,
provide: {
groupId: null,
weightFeatureAvailable: false,
boardWeight: null,
},
});
vm = wrapper.vm;
return vm.$nextTick();
});
afterEach(() => {
wrapper.destroy();
});
it('calls submit if submit button is clicked', async () => {
jest.spyOn(wrapper.vm, 'submit').mockImplementation();
wrapper.setData({ title: 'Testing Title' });
await vm.$nextTick();
await submitIssue();
expect(wrapper.vm.submit).toHaveBeenCalled();
});
it('disables submit button if title is empty', () => {
expect(findSubmitButton().props().disabled).toBe(true);
});
it('enables submit button if title is not empty', async () => {
wrapper.setData({ title: 'Testing Title' });
await vm.$nextTick();
expect(wrapper.find({ ref: 'input' }).element.value).toBe('Testing Title');
expect(findSubmitButton().props().disabled).toBe(false);
});
it('clears title after clicking cancel', async () => {
findCancelButton().trigger('click');
await vm.$nextTick();
expect(vm.title).toBe('');
});
describe('submit success', () => {
it('creates new issue', async () => {
2021-04-29 21:17:54 +05:30
wrapper.setData({ title: 'create issue' });
2021-01-29 00:20:46 +05:30
await vm.$nextTick();
await submitIssue();
expect(addListNewIssuesSpy).toHaveBeenCalled();
});
it('enables button after submit', async () => {
jest.spyOn(wrapper.vm, 'submit').mockImplementation();
2021-04-29 21:17:54 +05:30
wrapper.setData({ title: 'create issue' });
2021-01-29 00:20:46 +05:30
await vm.$nextTick();
await submitIssue();
expect(findSubmitButton().props().disabled).toBe(false);
});
it('clears title after submit', async () => {
2021-04-29 21:17:54 +05:30
wrapper.setData({ title: 'create issue' });
2021-01-29 00:20:46 +05:30
await vm.$nextTick();
await submitIssue();
await vm.$nextTick();
expect(vm.title).toBe('');
});
});
});