2017-02-28 05:57:39 -05:00
|
|
|
/* global List */
|
2017-02-28 05:23:19 -05:00
|
|
|
|
2017-03-01 05:09:56 -05:00
|
|
|
import Vue from 'vue';
|
2017-12-15 03:31:14 -05:00
|
|
|
import MockAdapter from 'axios-mock-adapter';
|
|
|
|
import axios from '~/lib/utils/axios_utils';
|
2018-02-06 09:44:38 -05:00
|
|
|
import boardNewIssue from '~/boards/components/board_new_issue.vue';
|
2018-10-10 13:08:43 -04:00
|
|
|
import boardsStore from '~/boards/stores/boards_store';
|
2017-02-28 05:23:19 -05:00
|
|
|
|
2017-05-16 17:01:51 -04:00
|
|
|
import '~/boards/models/list';
|
2019-11-28 10:06:57 -05:00
|
|
|
import { listObj, boardsMockInterceptor } from './mock_data';
|
2017-02-28 05:23:19 -05:00
|
|
|
|
2017-02-28 05:57:39 -05:00
|
|
|
describe('Issue boards new issue form', () => {
|
2017-02-28 05:23:19 -05:00
|
|
|
let vm;
|
|
|
|
let list;
|
2017-12-15 03:31:14 -05:00
|
|
|
let mock;
|
2017-06-23 05:28:19 -04:00
|
|
|
let newIssueMock;
|
2017-02-28 05:23:19 -05:00
|
|
|
const promiseReturn = {
|
2017-12-15 03:31:14 -05:00
|
|
|
data: {
|
|
|
|
iid: 100,
|
2017-02-28 05:23:19 -05:00
|
|
|
},
|
|
|
|
};
|
2017-05-30 04:32:49 -04:00
|
|
|
|
2017-02-28 05:23:19 -05:00
|
|
|
const submitIssue = () => {
|
2017-06-23 05:28:19 -04:00
|
|
|
const dummySubmitEvent = {
|
|
|
|
preventDefault() {},
|
|
|
|
};
|
|
|
|
vm.$refs.submitButton = vm.$el.querySelector('.btn-success');
|
|
|
|
return vm.submit(dummySubmitEvent);
|
2017-02-28 05:23:19 -05:00
|
|
|
};
|
|
|
|
|
2018-10-17 03:13:26 -04:00
|
|
|
beforeEach(done => {
|
2017-08-18 00:42:28 -04:00
|
|
|
setFixtures('<div class="test-container"></div>');
|
|
|
|
|
2017-02-28 05:23:19 -05:00
|
|
|
const BoardNewIssueComp = Vue.extend(boardNewIssue);
|
|
|
|
|
2017-12-15 03:31:14 -05:00
|
|
|
mock = new MockAdapter(axios);
|
|
|
|
mock.onAny().reply(boardsMockInterceptor);
|
|
|
|
|
2018-10-10 13:08:43 -04:00
|
|
|
boardsStore.create();
|
2017-02-28 05:23:19 -05:00
|
|
|
|
2017-06-23 05:28:19 -04:00
|
|
|
list = new List(listObj);
|
|
|
|
|
|
|
|
newIssueMock = Promise.resolve(promiseReturn);
|
|
|
|
spyOn(list, 'newIssue').and.callFake(() => newIssueMock);
|
|
|
|
|
|
|
|
vm = new BoardNewIssueComp({
|
|
|
|
propsData: {
|
|
|
|
list,
|
|
|
|
},
|
2017-08-18 00:42:28 -04:00
|
|
|
}).$mount(document.querySelector('.test-container'));
|
2017-06-23 05:28:19 -04:00
|
|
|
|
|
|
|
Vue.nextTick()
|
|
|
|
.then(done)
|
|
|
|
.catch(done.fail);
|
2017-02-28 05:23:19 -05:00
|
|
|
});
|
|
|
|
|
2017-12-15 03:31:14 -05:00
|
|
|
afterEach(() => {
|
|
|
|
vm.$destroy();
|
2018-01-23 06:42:02 -05:00
|
|
|
mock.restore();
|
2017-12-15 03:31:14 -05:00
|
|
|
});
|
2017-08-18 00:42:28 -04:00
|
|
|
|
2018-10-17 03:13:26 -04:00
|
|
|
it('calls submit if submit button is clicked', done => {
|
2017-08-18 00:42:28 -04:00
|
|
|
spyOn(vm, 'submit').and.callFake(e => e.preventDefault());
|
2017-06-23 05:28:19 -04:00
|
|
|
vm.title = 'Testing Title';
|
|
|
|
|
|
|
|
Vue.nextTick()
|
|
|
|
.then(() => {
|
|
|
|
vm.$el.querySelector('.btn-success').click();
|
|
|
|
|
|
|
|
expect(vm.submit.calls.count()).toBe(1);
|
|
|
|
})
|
|
|
|
.then(done)
|
|
|
|
.catch(done.fail);
|
2017-02-28 05:23:19 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
it('disables submit button if title is empty', () => {
|
|
|
|
expect(vm.$el.querySelector('.btn-success').disabled).toBe(true);
|
|
|
|
});
|
|
|
|
|
2018-10-17 03:13:26 -04:00
|
|
|
it('enables submit button if title is not empty', done => {
|
2017-02-28 05:23:19 -05:00
|
|
|
vm.title = 'Testing Title';
|
|
|
|
|
2017-06-23 05:28:19 -04:00
|
|
|
Vue.nextTick()
|
|
|
|
.then(() => {
|
|
|
|
expect(vm.$el.querySelector('.form-control').value).toBe('Testing Title');
|
|
|
|
expect(vm.$el.querySelector('.btn-success').disabled).not.toBe(true);
|
|
|
|
})
|
|
|
|
.then(done)
|
|
|
|
.catch(done.fail);
|
2017-02-28 05:23:19 -05:00
|
|
|
});
|
|
|
|
|
2018-10-17 03:13:26 -04:00
|
|
|
it('clears title after clicking cancel', done => {
|
2017-02-28 05:23:19 -05:00
|
|
|
vm.$el.querySelector('.btn-default').click();
|
|
|
|
|
2017-06-23 05:28:19 -04:00
|
|
|
Vue.nextTick()
|
|
|
|
.then(() => {
|
|
|
|
expect(vm.title).toBe('');
|
|
|
|
})
|
|
|
|
.then(done)
|
|
|
|
.catch(done.fail);
|
2017-02-28 05:23:19 -05:00
|
|
|
});
|
|
|
|
|
2018-10-17 03:13:26 -04:00
|
|
|
it('does not create new issue if title is empty', done => {
|
2017-06-23 05:28:19 -04:00
|
|
|
submitIssue()
|
|
|
|
.then(() => {
|
|
|
|
expect(list.newIssue).not.toHaveBeenCalled();
|
|
|
|
})
|
|
|
|
.then(done)
|
|
|
|
.catch(done.fail);
|
2017-02-28 05:23:19 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('submit success', () => {
|
2018-10-17 03:13:26 -04:00
|
|
|
it('creates new issue', done => {
|
2017-02-28 05:23:19 -05:00
|
|
|
vm.title = 'submit title';
|
|
|
|
|
2017-06-23 05:28:19 -04:00
|
|
|
Vue.nextTick()
|
|
|
|
.then(submitIssue)
|
|
|
|
.then(() => {
|
|
|
|
expect(list.newIssue).toHaveBeenCalled();
|
|
|
|
})
|
|
|
|
.then(done)
|
|
|
|
.catch(done.fail);
|
2017-02-28 05:23:19 -05:00
|
|
|
});
|
|
|
|
|
2018-10-17 03:13:26 -04:00
|
|
|
it('enables button after submit', done => {
|
2017-02-28 05:57:39 -05:00
|
|
|
vm.title = 'submit issue';
|
2017-02-28 05:23:19 -05:00
|
|
|
|
2017-06-23 05:28:19 -04:00
|
|
|
Vue.nextTick()
|
|
|
|
.then(submitIssue)
|
|
|
|
.then(() => {
|
|
|
|
expect(vm.$el.querySelector('.btn-success').disabled).toBe(false);
|
|
|
|
})
|
|
|
|
.then(done)
|
|
|
|
.catch(done.fail);
|
2017-02-28 05:23:19 -05:00
|
|
|
});
|
|
|
|
|
2018-10-17 03:13:26 -04:00
|
|
|
it('clears title after submit', done => {
|
2017-02-28 05:23:19 -05:00
|
|
|
vm.title = 'submit issue';
|
|
|
|
|
2017-06-23 05:28:19 -04:00
|
|
|
Vue.nextTick()
|
|
|
|
.then(submitIssue)
|
|
|
|
.then(() => {
|
2017-05-30 04:32:49 -04:00
|
|
|
expect(vm.title).toBe('');
|
2017-06-23 05:28:19 -04:00
|
|
|
})
|
|
|
|
.then(done)
|
|
|
|
.catch(done.fail);
|
2017-02-28 05:23:19 -05:00
|
|
|
});
|
|
|
|
|
2018-10-17 03:13:26 -04:00
|
|
|
it('sets detail issue after submit', done => {
|
2018-10-10 13:08:43 -04:00
|
|
|
expect(boardsStore.detail.issue.title).toBe(undefined);
|
2017-02-28 05:23:19 -05:00
|
|
|
vm.title = 'submit issue';
|
|
|
|
|
2017-06-23 05:28:19 -04:00
|
|
|
Vue.nextTick()
|
|
|
|
.then(submitIssue)
|
|
|
|
.then(() => {
|
2018-10-10 13:08:43 -04:00
|
|
|
expect(boardsStore.detail.issue.title).toBe('submit issue');
|
2017-06-23 05:28:19 -04:00
|
|
|
})
|
|
|
|
.then(done)
|
|
|
|
.catch(done.fail);
|
2017-02-28 05:23:19 -05:00
|
|
|
});
|
|
|
|
|
2018-10-17 03:13:26 -04:00
|
|
|
it('sets detail list after submit', done => {
|
2017-02-28 05:23:19 -05:00
|
|
|
vm.title = 'submit issue';
|
|
|
|
|
2017-06-23 05:28:19 -04:00
|
|
|
Vue.nextTick()
|
|
|
|
.then(submitIssue)
|
|
|
|
.then(() => {
|
2018-10-10 13:08:43 -04:00
|
|
|
expect(boardsStore.detail.list.id).toBe(list.id);
|
2017-06-23 05:28:19 -04:00
|
|
|
})
|
|
|
|
.then(done)
|
|
|
|
.catch(done.fail);
|
2017-02-28 05:23:19 -05:00
|
|
|
});
|
2019-09-06 06:46:12 -04:00
|
|
|
|
|
|
|
it('sets detail weight after submit', done => {
|
|
|
|
boardsStore.weightFeatureAvailable = true;
|
|
|
|
vm.title = 'submit issue';
|
|
|
|
|
|
|
|
Vue.nextTick()
|
|
|
|
.then(submitIssue)
|
|
|
|
.then(() => {
|
|
|
|
expect(boardsStore.detail.list.weight).toBe(list.weight);
|
|
|
|
})
|
|
|
|
.then(done)
|
|
|
|
.catch(done.fail);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('does not set detail weight after submit', done => {
|
|
|
|
boardsStore.weightFeatureAvailable = false;
|
|
|
|
vm.title = 'submit issue';
|
|
|
|
|
|
|
|
Vue.nextTick()
|
|
|
|
.then(submitIssue)
|
|
|
|
.then(() => {
|
|
|
|
expect(boardsStore.detail.list.weight).toBe(list.weight);
|
|
|
|
})
|
|
|
|
.then(done)
|
|
|
|
.catch(done.fail);
|
|
|
|
});
|
2017-02-28 05:23:19 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('submit error', () => {
|
2017-06-23 05:28:19 -04:00
|
|
|
beforeEach(() => {
|
|
|
|
newIssueMock = Promise.reject(new Error('My hovercraft is full of eels!'));
|
2017-02-28 05:23:19 -05:00
|
|
|
vm.title = 'error';
|
2017-06-23 05:28:19 -04:00
|
|
|
});
|
2017-02-28 05:23:19 -05:00
|
|
|
|
2018-10-17 03:13:26 -04:00
|
|
|
it('removes issue', done => {
|
2017-06-23 05:28:19 -04:00
|
|
|
Vue.nextTick()
|
|
|
|
.then(submitIssue)
|
|
|
|
.then(() => {
|
2017-02-28 05:23:19 -05:00
|
|
|
expect(list.issues.length).toBe(1);
|
2017-06-23 05:28:19 -04:00
|
|
|
})
|
|
|
|
.then(done)
|
|
|
|
.catch(done.fail);
|
2017-02-28 05:23:19 -05:00
|
|
|
});
|
|
|
|
|
2018-10-17 03:13:26 -04:00
|
|
|
it('shows error', done => {
|
2017-06-23 05:28:19 -04:00
|
|
|
Vue.nextTick()
|
|
|
|
.then(submitIssue)
|
|
|
|
.then(() => {
|
2017-02-28 05:23:19 -05:00
|
|
|
expect(vm.error).toBe(true);
|
2017-06-23 05:28:19 -04:00
|
|
|
})
|
|
|
|
.then(done)
|
|
|
|
.catch(done.fail);
|
2017-02-28 05:23:19 -05:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|