2017-09-10 17:25:29 +05:30
|
|
|
import Vue from 'vue';
|
2019-10-12 21:52:04 +05:30
|
|
|
import mountComponent from 'spec/helpers/vue_mount_component_helper';
|
2017-09-10 17:25:29 +05:30
|
|
|
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-10-12 21:52:04 +05:30
|
|
|
const defaultProps = {
|
|
|
|
canDestroy: true,
|
|
|
|
formState: {
|
|
|
|
title: 'b',
|
|
|
|
description: 'a',
|
|
|
|
lockedWarningVisible: false,
|
|
|
|
},
|
|
|
|
issuableType: 'issue',
|
|
|
|
markdownPreviewPath: '/',
|
|
|
|
markdownDocsPath: '/',
|
|
|
|
projectPath: '/',
|
|
|
|
projectNamespace: '/',
|
|
|
|
};
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
vm.$destroy();
|
|
|
|
});
|
2019-07-31 22:56:46 +05:30
|
|
|
|
2019-10-12 21:52:04 +05:30
|
|
|
const createComponent = props => {
|
2017-09-10 17:25:29 +05:30
|
|
|
const Component = Vue.extend(formComponent);
|
|
|
|
|
2019-10-12 21:52:04 +05:30
|
|
|
vm = mountComponent(Component, {
|
|
|
|
...defaultProps,
|
|
|
|
...props,
|
|
|
|
});
|
|
|
|
};
|
2017-09-10 17:25:29 +05:30
|
|
|
|
|
|
|
it('does not render template selector if no templates exist', () => {
|
2019-10-12 21:52:04 +05:30
|
|
|
createComponent();
|
|
|
|
|
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
|
|
|
});
|
|
|
|
|
2019-10-12 21:52:04 +05:30
|
|
|
it('renders template selector when templates exists', () => {
|
|
|
|
createComponent({ issuableTemplates: ['test'] });
|
2017-09-10 17:25:29 +05:30
|
|
|
|
2019-10-12 21:52:04 +05:30
|
|
|
expect(vm.$el.querySelector('.js-issuable-selector-wrap')).not.toBeNull();
|
2017-09-10 17:25:29 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('hides locked warning by default', () => {
|
2019-10-12 21:52:04 +05:30
|
|
|
createComponent();
|
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
expect(vm.$el.querySelector('.alert')).toBeNull();
|
2017-09-10 17:25:29 +05:30
|
|
|
});
|
|
|
|
|
2019-10-12 21:52:04 +05:30
|
|
|
it('shows locked warning if formState is different', () => {
|
|
|
|
createComponent({ formState: { ...defaultProps.formState, lockedWarningVisible: true } });
|
2017-09-10 17:25:29 +05:30
|
|
|
|
2019-10-12 21:52:04 +05:30
|
|
|
expect(vm.$el.querySelector('.alert')).not.toBeNull();
|
|
|
|
});
|
2017-09-10 17:25:29 +05:30
|
|
|
|
2019-10-12 21:52:04 +05:30
|
|
|
it('hides locked warning when currently saving', () => {
|
|
|
|
createComponent({
|
|
|
|
formState: { ...defaultProps.formState, updateLoading: true, lockedWarningVisible: true },
|
2017-09-10 17:25:29 +05:30
|
|
|
});
|
2019-07-31 22:56:46 +05:30
|
|
|
|
2019-10-12 21:52:04 +05:30
|
|
|
expect(vm.$el.querySelector('.alert')).toBeNull();
|
2019-07-31 22:56:46 +05:30
|
|
|
});
|
|
|
|
|
2019-10-12 21:52:04 +05:30
|
|
|
describe('autosave', () => {
|
|
|
|
let autosaveObj;
|
|
|
|
let autosave;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
autosaveObj = { reset: jasmine.createSpy() };
|
|
|
|
autosave = spyOnDependency(formComponent, 'Autosave').and.returnValue(autosaveObj);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('initialized Autosave on mount', () => {
|
|
|
|
createComponent();
|
2019-07-31 22:56:46 +05:30
|
|
|
|
2019-10-12 21:52:04 +05:30
|
|
|
expect(autosave).toHaveBeenCalledTimes(2);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('calls reset on autosave when eventHub emits appropriate events', () => {
|
|
|
|
createComponent();
|
|
|
|
|
|
|
|
eventHub.$emit('close.form');
|
2019-07-31 22:56:46 +05:30
|
|
|
|
2019-10-12 21:52:04 +05:30
|
|
|
expect(autosaveObj.reset).toHaveBeenCalledTimes(2);
|
2019-07-31 22:56:46 +05:30
|
|
|
|
2019-10-12 21:52:04 +05:30
|
|
|
eventHub.$emit('delete.issuable');
|
2019-07-31 22:56:46 +05:30
|
|
|
|
2019-10-12 21:52:04 +05:30
|
|
|
expect(autosaveObj.reset).toHaveBeenCalledTimes(4);
|
2019-07-31 22:56:46 +05:30
|
|
|
|
2019-10-12 21:52:04 +05:30
|
|
|
eventHub.$emit('update.issuable');
|
|
|
|
|
|
|
|
expect(autosaveObj.reset).toHaveBeenCalledTimes(6);
|
|
|
|
});
|
2019-07-31 22:56:46 +05:30
|
|
|
});
|
2017-09-10 17:25:29 +05:30
|
|
|
});
|