2017-05-12 06:23:30 -04:00
|
|
|
import Vue from 'vue';
|
|
|
|
import editActions from '~/issue_show/components/edit_actions.vue';
|
|
|
|
import eventHub from '~/issue_show/event_hub';
|
2017-05-16 08:07:38 -04:00
|
|
|
import Store from '~/issue_show/stores';
|
2017-05-12 06:23:30 -04:00
|
|
|
|
|
|
|
describe('Edit Actions components', () => {
|
|
|
|
let vm;
|
|
|
|
|
2018-10-17 03:13:26 -04:00
|
|
|
beforeEach(done => {
|
2017-05-12 06:23:30 -04:00
|
|
|
const Component = Vue.extend(editActions);
|
2017-05-16 08:07:38 -04:00
|
|
|
const store = new Store({
|
|
|
|
titleHtml: '',
|
|
|
|
descriptionHtml: '',
|
|
|
|
issuableRef: '',
|
|
|
|
});
|
|
|
|
store.formState.title = 'test';
|
2017-05-12 06:23:30 -04:00
|
|
|
|
2019-12-20 10:07:34 -05:00
|
|
|
jest.spyOn(eventHub, '$emit').mockImplementation(() => {});
|
2017-05-12 06:23:30 -04:00
|
|
|
|
2017-05-12 06:58:48 -04:00
|
|
|
vm = new Component({
|
|
|
|
propsData: {
|
|
|
|
canDestroy: true,
|
2017-05-16 08:07:38 -04:00
|
|
|
formState: store.formState,
|
2018-09-24 16:52:06 -04:00
|
|
|
issuableType: 'issue',
|
2017-05-12 06:58:48 -04:00
|
|
|
},
|
|
|
|
}).$mount();
|
2017-05-12 06:23:30 -04:00
|
|
|
|
|
|
|
Vue.nextTick(done);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders all buttons as enabled', () => {
|
2018-10-17 03:13:26 -04:00
|
|
|
expect(vm.$el.querySelectorAll('.disabled').length).toBe(0);
|
2017-05-12 06:23:30 -04:00
|
|
|
|
2018-10-17 03:13:26 -04:00
|
|
|
expect(vm.$el.querySelectorAll('[disabled]').length).toBe(0);
|
2017-05-12 06:23:30 -04:00
|
|
|
});
|
|
|
|
|
2018-10-17 03:13:26 -04:00
|
|
|
it('does not render delete button if canUpdate is false', done => {
|
2017-05-12 06:58:48 -04:00
|
|
|
vm.canDestroy = false;
|
|
|
|
|
|
|
|
Vue.nextTick(() => {
|
2018-10-17 03:13:26 -04:00
|
|
|
expect(vm.$el.querySelector('.btn-danger')).toBeNull();
|
2017-05-12 06:58:48 -04:00
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-10-17 03:13:26 -04:00
|
|
|
it('disables submit button when title is blank', done => {
|
2017-05-16 08:07:38 -04:00
|
|
|
vm.formState.title = '';
|
|
|
|
|
|
|
|
Vue.nextTick(() => {
|
2018-10-17 03:13:26 -04:00
|
|
|
expect(vm.$el.querySelector('.btn-success').getAttribute('disabled')).toBe('disabled');
|
2017-05-16 08:07:38 -04:00
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-10-17 03:13:26 -04:00
|
|
|
it('should not show delete button if showDeleteButton is false', done => {
|
2017-11-15 18:13:20 -05:00
|
|
|
vm.showDeleteButton = false;
|
|
|
|
|
|
|
|
Vue.nextTick(() => {
|
|
|
|
expect(vm.$el.querySelector('.btn-danger')).toBeNull();
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-05-12 06:23:30 -04:00
|
|
|
describe('updateIssuable', () => {
|
|
|
|
it('sends update.issauble event when clicking save button', () => {
|
2018-09-18 05:58:22 -04:00
|
|
|
vm.$el.querySelector('.btn-success').click();
|
2017-05-12 06:23:30 -04:00
|
|
|
|
2018-10-17 03:13:26 -04:00
|
|
|
expect(eventHub.$emit).toHaveBeenCalledWith('update.issuable');
|
2017-05-12 06:23:30 -04:00
|
|
|
});
|
|
|
|
|
2018-10-17 03:13:26 -04:00
|
|
|
it('shows loading icon after clicking save button', done => {
|
2018-09-18 05:58:22 -04:00
|
|
|
vm.$el.querySelector('.btn-success').click();
|
2017-05-12 06:23:30 -04:00
|
|
|
|
|
|
|
Vue.nextTick(() => {
|
2018-10-17 03:13:26 -04:00
|
|
|
expect(vm.$el.querySelector('.btn-success .fa')).not.toBeNull();
|
2017-05-12 06:23:30 -04:00
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-10-17 03:13:26 -04:00
|
|
|
it('disabled button after clicking save button', done => {
|
2018-09-18 05:58:22 -04:00
|
|
|
vm.$el.querySelector('.btn-success').click();
|
2017-05-12 06:23:30 -04:00
|
|
|
|
|
|
|
Vue.nextTick(() => {
|
2018-10-17 03:13:26 -04:00
|
|
|
expect(vm.$el.querySelector('.btn-success').getAttribute('disabled')).toBe('disabled');
|
2017-05-12 06:23:30 -04:00
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('closeForm', () => {
|
|
|
|
it('emits close.form when clicking cancel', () => {
|
|
|
|
vm.$el.querySelector('.btn-default').click();
|
|
|
|
|
2018-10-17 03:13:26 -04:00
|
|
|
expect(eventHub.$emit).toHaveBeenCalledWith('close.form');
|
2017-05-12 06:23:30 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('deleteIssuable', () => {
|
|
|
|
it('sends delete.issuable event when clicking save button', () => {
|
2019-12-20 10:07:34 -05:00
|
|
|
jest.spyOn(window, 'confirm').mockReturnValue(true);
|
2017-05-12 06:23:30 -04:00
|
|
|
vm.$el.querySelector('.btn-danger').click();
|
|
|
|
|
2019-08-29 00:57:54 -04:00
|
|
|
expect(eventHub.$emit).toHaveBeenCalledWith('delete.issuable', { destroy_confirm: true });
|
2017-05-12 06:23:30 -04:00
|
|
|
});
|
|
|
|
|
2018-10-17 03:13:26 -04:00
|
|
|
it('shows loading icon after clicking delete button', done => {
|
2019-12-20 10:07:34 -05:00
|
|
|
jest.spyOn(window, 'confirm').mockReturnValue(true);
|
2017-05-12 06:23:30 -04:00
|
|
|
vm.$el.querySelector('.btn-danger').click();
|
|
|
|
|
|
|
|
Vue.nextTick(() => {
|
2018-10-17 03:13:26 -04:00
|
|
|
expect(vm.$el.querySelector('.btn-danger .fa')).not.toBeNull();
|
2017-05-12 06:23:30 -04:00
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-10-17 03:13:26 -04:00
|
|
|
it('does no actions when confirm is false', done => {
|
2019-12-20 10:07:34 -05:00
|
|
|
jest.spyOn(window, 'confirm').mockReturnValue(false);
|
2017-05-12 06:23:30 -04:00
|
|
|
vm.$el.querySelector('.btn-danger').click();
|
|
|
|
|
|
|
|
Vue.nextTick(() => {
|
2018-10-17 03:13:26 -04:00
|
|
|
expect(eventHub.$emit).not.toHaveBeenCalledWith('delete.issuable');
|
2018-10-09 14:03:09 -04:00
|
|
|
|
2018-10-17 03:13:26 -04:00
|
|
|
expect(vm.$el.querySelector('.btn-danger .fa')).toBeNull();
|
2017-05-12 06:23:30 -04:00
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|