debian-mirror-gitlab/spec/frontend/issue_show/components/edit_actions_spec.js

135 lines
3.5 KiB
JavaScript
Raw Normal View History

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