2021-06-08 01:23:25 +05:30
|
|
|
import { GlAlert } from '@gitlab/ui';
|
|
|
|
import { shallowMount } from '@vue/test-utils';
|
2020-05-24 23:13:21 +05:30
|
|
|
import Autosave from '~/autosave';
|
2022-01-26 12:08:38 +05:30
|
|
|
import DescriptionTemplate from '~/issues/show/components/fields/description_template.vue';
|
|
|
|
import IssueTypeField from '~/issues/show/components/fields/type.vue';
|
|
|
|
import formComponent from '~/issues/show/components/form.vue';
|
|
|
|
import LockedWarning from '~/issues/show/components/locked_warning.vue';
|
|
|
|
import eventHub from '~/issues/show/event_hub';
|
2017-09-10 17:25:29 +05:30
|
|
|
|
2020-05-24 23:13:21 +05:30
|
|
|
jest.mock('~/autosave');
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
describe('Inline edit form component', () => {
|
2021-06-08 01:23:25 +05:30
|
|
|
let wrapper;
|
2019-10-12 21:52:04 +05:30
|
|
|
const defaultProps = {
|
|
|
|
canDestroy: true,
|
2022-01-26 12:08:38 +05:30
|
|
|
endpoint: 'gitlab-org/gitlab-test/-/issues/1',
|
2019-10-12 21:52:04 +05:30
|
|
|
formState: {
|
|
|
|
title: 'b',
|
|
|
|
description: 'a',
|
|
|
|
lockedWarningVisible: false,
|
|
|
|
},
|
|
|
|
issuableType: 'issue',
|
|
|
|
markdownPreviewPath: '/',
|
|
|
|
markdownDocsPath: '/',
|
|
|
|
projectPath: '/',
|
2021-03-11 19:13:27 +05:30
|
|
|
projectId: 1,
|
2019-10-12 21:52:04 +05:30
|
|
|
projectNamespace: '/',
|
|
|
|
};
|
|
|
|
|
|
|
|
afterEach(() => {
|
2021-06-08 01:23:25 +05:30
|
|
|
wrapper.destroy();
|
2019-10-12 21:52:04 +05:30
|
|
|
});
|
2019-07-31 22:56:46 +05:30
|
|
|
|
2021-03-08 18:12:59 +05:30
|
|
|
const createComponent = (props) => {
|
2021-06-08 01:23:25 +05:30
|
|
|
wrapper = shallowMount(formComponent, {
|
|
|
|
propsData: {
|
|
|
|
...defaultProps,
|
|
|
|
...props,
|
|
|
|
},
|
2019-10-12 21:52:04 +05:30
|
|
|
});
|
|
|
|
};
|
2017-09-10 17:25:29 +05:30
|
|
|
|
2021-06-08 01:23:25 +05:30
|
|
|
const findDescriptionTemplate = () => wrapper.findComponent(DescriptionTemplate);
|
2021-09-04 01:27:46 +05:30
|
|
|
const findIssuableTypeField = () => wrapper.findComponent(IssueTypeField);
|
2021-06-08 01:23:25 +05:30
|
|
|
const findLockedWarning = () => wrapper.findComponent(LockedWarning);
|
|
|
|
const findAlert = () => wrapper.findComponent(GlAlert);
|
|
|
|
|
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();
|
|
|
|
|
2021-06-08 01:23:25 +05:30
|
|
|
expect(findDescriptionTemplate().exists()).toBe(false);
|
2017-09-10 17:25:29 +05:30
|
|
|
});
|
|
|
|
|
2021-04-17 20:07:23 +05:30
|
|
|
it('renders template selector when templates as array exists', () => {
|
2021-03-11 19:13:27 +05:30
|
|
|
createComponent({
|
|
|
|
issuableTemplates: [
|
|
|
|
{ name: 'test', id: 'test', project_path: 'test', namespace_path: 'test' },
|
|
|
|
],
|
|
|
|
});
|
2017-09-10 17:25:29 +05:30
|
|
|
|
2021-06-08 01:23:25 +05:30
|
|
|
expect(findDescriptionTemplate().exists()).toBe(true);
|
2017-09-10 17:25:29 +05:30
|
|
|
});
|
|
|
|
|
2021-04-17 20:07:23 +05:30
|
|
|
it('renders template selector when templates as hash exists', () => {
|
|
|
|
createComponent({
|
|
|
|
issuableTemplates: {
|
|
|
|
test: [{ name: 'test', id: 'test', project_path: 'test', namespace_path: 'test' }],
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2021-06-08 01:23:25 +05:30
|
|
|
expect(findDescriptionTemplate().exists()).toBe(true);
|
2021-04-17 20:07:23 +05:30
|
|
|
});
|
|
|
|
|
2021-09-04 01:27:46 +05:30
|
|
|
it.each`
|
|
|
|
issuableType | value
|
|
|
|
${'issue'} | ${true}
|
|
|
|
${'epic'} | ${false}
|
|
|
|
`(
|
|
|
|
'when `issue_type` is set to "$issuableType" rendering the type select will be "$value"',
|
|
|
|
({ issuableType, value }) => {
|
|
|
|
createComponent({
|
|
|
|
issuableType,
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(findIssuableTypeField().exists()).toBe(value);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
it('hides locked warning by default', () => {
|
2019-10-12 21:52:04 +05:30
|
|
|
createComponent();
|
|
|
|
|
2021-06-08 01:23:25 +05:30
|
|
|
expect(findLockedWarning().exists()).toBe(false);
|
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
|
|
|
|
2021-06-08 01:23:25 +05:30
|
|
|
expect(findLockedWarning().exists()).toBe(true);
|
2019-10-12 21:52:04 +05:30
|
|
|
});
|
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
|
|
|
|
2021-06-08 01:23:25 +05:30
|
|
|
expect(findLockedWarning().exists()).toBe(false);
|
2019-07-31 22:56:46 +05:30
|
|
|
});
|
|
|
|
|
2019-10-12 21:52:04 +05:30
|
|
|
describe('autosave', () => {
|
2020-05-24 23:13:21 +05:30
|
|
|
let spy;
|
2019-10-12 21:52:04 +05:30
|
|
|
|
|
|
|
beforeEach(() => {
|
2020-05-24 23:13:21 +05:30
|
|
|
spy = jest.spyOn(Autosave.prototype, 'reset');
|
2019-10-12 21:52:04 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('initialized Autosave on mount', () => {
|
|
|
|
createComponent();
|
2019-07-31 22:56:46 +05:30
|
|
|
|
2020-05-24 23:13:21 +05:30
|
|
|
expect(Autosave).toHaveBeenCalledTimes(2);
|
2019-10-12 21:52:04 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('calls reset on autosave when eventHub emits appropriate events', () => {
|
|
|
|
createComponent();
|
|
|
|
|
|
|
|
eventHub.$emit('close.form');
|
2019-07-31 22:56:46 +05:30
|
|
|
|
2020-05-24 23:13:21 +05:30
|
|
|
expect(spy).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
|
|
|
|
2020-05-24 23:13:21 +05:30
|
|
|
expect(spy).toHaveBeenCalledTimes(4);
|
2019-07-31 22:56:46 +05:30
|
|
|
|
2019-10-12 21:52:04 +05:30
|
|
|
eventHub.$emit('update.issuable');
|
|
|
|
|
2020-05-24 23:13:21 +05:30
|
|
|
expect(spy).toHaveBeenCalledTimes(6);
|
2019-10-12 21:52:04 +05:30
|
|
|
});
|
2021-06-08 01:23:25 +05:30
|
|
|
|
|
|
|
describe('outdated description', () => {
|
|
|
|
it('does not show warning if lock version from server is the same as the local lock version', () => {
|
|
|
|
createComponent();
|
|
|
|
expect(findAlert().exists()).toBe(false);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('shows warning if lock version from server differs than the local lock version', async () => {
|
|
|
|
Autosave.prototype.getSavedLockVersion.mockResolvedValue('lock version from local storage');
|
|
|
|
|
|
|
|
createComponent({
|
|
|
|
formState: { ...defaultProps.formState, lock_version: 'lock version from server' },
|
|
|
|
});
|
|
|
|
|
|
|
|
await wrapper.vm.$nextTick();
|
|
|
|
expect(findAlert().exists()).toBe(true);
|
|
|
|
});
|
|
|
|
});
|
2019-07-31 22:56:46 +05:30
|
|
|
});
|
2017-09-10 17:25:29 +05:30
|
|
|
});
|