debian-mirror-gitlab/spec/frontend/boards/board_new_issue_deprecated_spec.js

212 lines
5.3 KiB
JavaScript
Raw Normal View History

2017-08-17 22:00:37 +05:30
/* global List */
2020-11-24 15:15:51 +05:30
import { mount } from '@vue/test-utils';
2018-03-17 18:26:18 +05:30
import MockAdapter from 'axios-mock-adapter';
2021-03-11 19:13:27 +05:30
import Vue from 'vue';
2021-04-17 20:07:23 +05:30
import Vuex from 'vuex';
2021-03-08 18:12:59 +05:30
import boardNewIssue from '~/boards/components/board_new_issue_deprecated.vue';
2018-12-13 13:39:08 +05:30
import boardsStore from '~/boards/stores/boards_store';
2021-03-11 19:13:27 +05:30
import axios from '~/lib/utils/axios_utils';
2017-08-17 22:00:37 +05:30
2017-09-10 17:25:29 +05:30
import '~/boards/models/list';
2020-01-01 13:55:28 +05:30
import { listObj, boardsMockInterceptor } from './mock_data';
2017-08-17 22:00:37 +05:30
2021-04-17 20:07:23 +05:30
Vue.use(Vuex);
2017-08-17 22:00:37 +05:30
describe('Issue boards new issue form', () => {
2020-11-24 15:15:51 +05:30
let wrapper;
2017-08-17 22:00:37 +05:30
let vm;
let list;
2018-03-17 18:26:18 +05:30
let mock;
2017-09-10 17:25:29 +05:30
let newIssueMock;
2017-08-17 22:00:37 +05:30
const promiseReturn = {
2018-03-17 18:26:18 +05:30
data: {
iid: 100,
2017-08-17 22:00:37 +05:30
},
};
2017-09-10 17:25:29 +05:30
2017-08-17 22:00:37 +05:30
const submitIssue = () => {
2017-09-10 17:25:29 +05:30
const dummySubmitEvent = {
preventDefault() {},
};
2020-11-24 15:15:51 +05:30
wrapper.vm.$refs.submitButton = wrapper.find({ ref: 'submitButton' });
return wrapper.vm.submit(dummySubmitEvent);
2017-08-17 22:00:37 +05:30
};
2020-04-22 19:07:51 +05:30
beforeEach(() => {
2017-08-17 22:00:37 +05:30
const BoardNewIssueComp = Vue.extend(boardNewIssue);
2018-03-17 18:26:18 +05:30
mock = new MockAdapter(axios);
mock.onAny().reply(boardsMockInterceptor);
2018-12-13 13:39:08 +05:30
boardsStore.create();
2017-08-17 22:00:37 +05:30
2017-09-10 17:25:29 +05:30
list = new List(listObj);
newIssueMock = Promise.resolve(promiseReturn);
2020-04-22 19:07:51 +05:30
jest.spyOn(list, 'newIssue').mockImplementation(() => newIssueMock);
2017-09-10 17:25:29 +05:30
2021-04-17 20:07:23 +05:30
const store = new Vuex.Store({
getters: { isGroupBoard: () => false },
});
2020-11-24 15:15:51 +05:30
wrapper = mount(BoardNewIssueComp, {
2017-09-10 17:25:29 +05:30
propsData: {
2020-11-24 15:15:51 +05:30
disabled: false,
2017-09-10 17:25:29 +05:30
list,
},
2021-04-17 20:07:23 +05:30
store,
2020-11-24 15:15:51 +05:30
provide: {
groupId: null,
},
});
vm = wrapper.vm;
2017-09-10 17:25:29 +05:30
2020-04-22 19:07:51 +05:30
return Vue.nextTick();
2017-08-17 22:00:37 +05:30
});
2018-03-17 18:26:18 +05:30
afterEach(() => {
2020-11-24 15:15:51 +05:30
wrapper.destroy();
2018-03-17 18:26:18 +05:30
mock.restore();
});
2020-04-22 19:07:51 +05:30
it('calls submit if submit button is clicked', () => {
2020-11-24 15:15:51 +05:30
jest.spyOn(wrapper.vm, 'submit').mockImplementation();
2017-09-10 17:25:29 +05:30
vm.title = 'Testing Title';
2020-11-24 15:15:51 +05:30
return Vue.nextTick()
.then(submitIssue)
.then(() => {
expect(wrapper.vm.submit).toHaveBeenCalled();
});
2017-08-17 22:00:37 +05:30
});
it('disables submit button if title is empty', () => {
2020-11-24 15:15:51 +05:30
expect(wrapper.find({ ref: 'submitButton' }).props().disabled).toBe(true);
2017-08-17 22:00:37 +05:30
});
2020-04-22 19:07:51 +05:30
it('enables submit button if title is not empty', () => {
2020-11-24 15:15:51 +05:30
wrapper.setData({ title: 'Testing Title' });
2017-08-17 22:00:37 +05:30
2020-04-22 19:07:51 +05:30
return Vue.nextTick().then(() => {
2020-11-24 15:15:51 +05:30
expect(wrapper.find({ ref: 'input' }).element.value).toBe('Testing Title');
expect(wrapper.find({ ref: 'submitButton' }).props().disabled).toBe(false);
2020-04-22 19:07:51 +05:30
});
2017-08-17 22:00:37 +05:30
});
2020-04-22 19:07:51 +05:30
it('clears title after clicking cancel', () => {
2020-11-24 15:15:51 +05:30
wrapper.find({ ref: 'cancelButton' }).trigger('click');
2017-08-17 22:00:37 +05:30
2020-04-22 19:07:51 +05:30
return Vue.nextTick().then(() => {
expect(vm.title).toBe('');
});
2017-08-17 22:00:37 +05:30
});
2020-04-22 19:07:51 +05:30
it('does not create new issue if title is empty', () => {
return submitIssue().then(() => {
expect(list.newIssue).not.toHaveBeenCalled();
});
2017-08-17 22:00:37 +05:30
});
describe('submit success', () => {
2020-04-22 19:07:51 +05:30
it('creates new issue', () => {
2020-11-24 15:15:51 +05:30
wrapper.setData({ title: 'submit issue' });
2017-08-17 22:00:37 +05:30
2020-04-22 19:07:51 +05:30
return Vue.nextTick()
2017-09-10 17:25:29 +05:30
.then(submitIssue)
.then(() => {
expect(list.newIssue).toHaveBeenCalled();
2020-04-22 19:07:51 +05:30
});
2017-08-17 22:00:37 +05:30
});
2020-04-22 19:07:51 +05:30
it('enables button after submit', () => {
2020-11-24 15:15:51 +05:30
jest.spyOn(wrapper.vm, 'submit').mockImplementation();
wrapper.setData({ title: 'submit issue' });
2017-08-17 22:00:37 +05:30
2020-04-22 19:07:51 +05:30
return Vue.nextTick()
2017-09-10 17:25:29 +05:30
.then(submitIssue)
.then(() => {
2020-11-24 15:15:51 +05:30
expect(wrapper.vm.$refs.submitButton.props().disabled).toBe(false);
2020-04-22 19:07:51 +05:30
});
2017-08-17 22:00:37 +05:30
});
2020-04-22 19:07:51 +05:30
it('clears title after submit', () => {
2020-11-24 15:15:51 +05:30
wrapper.setData({ title: 'submit issue' });
2017-08-17 22:00:37 +05:30
2020-04-22 19:07:51 +05:30
return Vue.nextTick()
2017-09-10 17:25:29 +05:30
.then(submitIssue)
.then(() => {
expect(vm.title).toBe('');
2020-04-22 19:07:51 +05:30
});
2017-08-17 22:00:37 +05:30
});
2020-04-22 19:07:51 +05:30
it('sets detail issue after submit', () => {
2018-12-13 13:39:08 +05:30
expect(boardsStore.detail.issue.title).toBe(undefined);
2020-11-24 15:15:51 +05:30
wrapper.setData({ title: 'submit issue' });
2017-08-17 22:00:37 +05:30
2020-04-22 19:07:51 +05:30
return Vue.nextTick()
2017-09-10 17:25:29 +05:30
.then(submitIssue)
.then(() => {
2018-12-13 13:39:08 +05:30
expect(boardsStore.detail.issue.title).toBe('submit issue');
2020-04-22 19:07:51 +05:30
});
2017-08-17 22:00:37 +05:30
});
2020-04-22 19:07:51 +05:30
it('sets detail list after submit', () => {
2020-11-24 15:15:51 +05:30
wrapper.setData({ title: 'submit issue' });
2017-08-17 22:00:37 +05:30
2020-04-22 19:07:51 +05:30
return Vue.nextTick()
2017-09-10 17:25:29 +05:30
.then(submitIssue)
.then(() => {
2018-12-13 13:39:08 +05:30
expect(boardsStore.detail.list.id).toBe(list.id);
2020-04-22 19:07:51 +05:30
});
2017-08-17 22:00:37 +05:30
});
2019-12-04 20:38:33 +05:30
2020-04-22 19:07:51 +05:30
it('sets detail weight after submit', () => {
2019-12-04 20:38:33 +05:30
boardsStore.weightFeatureAvailable = true;
2020-11-24 15:15:51 +05:30
wrapper.setData({ title: 'submit issue' });
2019-12-04 20:38:33 +05:30
2020-04-22 19:07:51 +05:30
return Vue.nextTick()
2019-12-04 20:38:33 +05:30
.then(submitIssue)
.then(() => {
expect(boardsStore.detail.list.weight).toBe(list.weight);
2020-04-22 19:07:51 +05:30
});
2019-12-04 20:38:33 +05:30
});
2020-04-22 19:07:51 +05:30
it('does not set detail weight after submit', () => {
2019-12-04 20:38:33 +05:30
boardsStore.weightFeatureAvailable = false;
2020-11-24 15:15:51 +05:30
wrapper.setData({ title: 'submit issue' });
2019-12-04 20:38:33 +05:30
2020-04-22 19:07:51 +05:30
return Vue.nextTick()
2019-12-04 20:38:33 +05:30
.then(submitIssue)
.then(() => {
expect(boardsStore.detail.list.weight).toBe(list.weight);
2020-04-22 19:07:51 +05:30
});
2019-12-04 20:38:33 +05:30
});
2017-08-17 22:00:37 +05:30
});
describe('submit error', () => {
2017-09-10 17:25:29 +05:30
beforeEach(() => {
newIssueMock = Promise.reject(new Error('My hovercraft is full of eels!'));
2017-08-17 22:00:37 +05:30
vm.title = 'error';
2017-09-10 17:25:29 +05:30
});
2017-08-17 22:00:37 +05:30
2020-04-22 19:07:51 +05:30
it('removes issue', () => {
const lengthBefore = list.issues.length;
return Vue.nextTick()
2017-09-10 17:25:29 +05:30
.then(submitIssue)
.then(() => {
2020-04-22 19:07:51 +05:30
expect(list.issues.length).toBe(lengthBefore);
});
2017-08-17 22:00:37 +05:30
});
2020-04-22 19:07:51 +05:30
it('shows error', () => {
return Vue.nextTick()
2017-09-10 17:25:29 +05:30
.then(submitIssue)
.then(() => {
2017-08-17 22:00:37 +05:30
expect(vm.error).toBe(true);
2020-04-22 19:07:51 +05:30
});
2017-08-17 22:00:37 +05:30
});
});
});