debian-mirror-gitlab/spec/javascripts/issue_show/components/form_spec.js

82 lines
2 KiB
JavaScript
Raw Normal View History

2017-09-10 17:25:29 +05:30
import Vue from 'vue';
import formComponent from '~/issue_show/components/form.vue';
2019-07-31 22:56:46 +05:30
import eventHub from '~/issue_show/event_hub';
2017-09-10 17:25:29 +05:30
describe('Inline edit form component', () => {
let vm;
2019-07-31 22:56:46 +05:30
let autosave;
let autosaveObj;
2017-09-10 17:25:29 +05:30
2018-12-13 13:39:08 +05:30
beforeEach(done => {
2019-07-31 22:56:46 +05:30
autosaveObj = { reset: jasmine.createSpy() };
autosave = spyOnDependency(formComponent, 'Autosave').and.returnValue(autosaveObj);
2017-09-10 17:25:29 +05:30
const Component = Vue.extend(formComponent);
vm = new Component({
propsData: {
canDestroy: true,
formState: {
title: 'b',
description: 'a',
lockedWarningVisible: false,
},
2018-12-05 23:21:45 +05:30
issuableType: 'issue',
2018-03-17 18:26:18 +05:30
markdownPreviewPath: '/',
markdownDocsPath: '/',
2017-09-10 17:25:29 +05:30
projectPath: '/',
projectNamespace: '/',
},
}).$mount();
Vue.nextTick(done);
});
it('does not render template selector if no templates exist', () => {
2018-12-13 13:39:08 +05:30
expect(vm.$el.querySelector('.js-issuable-selector-wrap')).toBeNull();
2017-09-10 17:25:29 +05:30
});
2018-12-13 13:39:08 +05:30
it('renders template selector when templates exists', done => {
2017-09-10 17:25:29 +05:30
vm.issuableTemplates = ['test'];
Vue.nextTick(() => {
2018-12-13 13:39:08 +05:30
expect(vm.$el.querySelector('.js-issuable-selector-wrap')).not.toBeNull();
2017-09-10 17:25:29 +05:30
done();
});
});
it('hides locked warning by default', () => {
2018-12-13 13:39:08 +05:30
expect(vm.$el.querySelector('.alert')).toBeNull();
2017-09-10 17:25:29 +05:30
});
2018-12-13 13:39:08 +05:30
it('shows locked warning if formState is different', done => {
2017-09-10 17:25:29 +05:30
vm.formState.lockedWarningVisible = true;
Vue.nextTick(() => {
2018-12-13 13:39:08 +05:30
expect(vm.$el.querySelector('.alert')).not.toBeNull();
2017-09-10 17:25:29 +05:30
done();
});
});
2019-07-31 22:56:46 +05:30
it('initialized Autosave on mount', () => {
expect(autosave).toHaveBeenCalledTimes(2);
});
it('calls reset on autosave when eventHub emits appropriate events', () => {
eventHub.$emit('close.form');
expect(autosaveObj.reset).toHaveBeenCalledTimes(2);
eventHub.$emit('delete.issuable');
expect(autosaveObj.reset).toHaveBeenCalledTimes(4);
eventHub.$emit('update.issuable');
expect(autosaveObj.reset).toHaveBeenCalledTimes(6);
});
2017-09-10 17:25:29 +05:30
});