2021-02-11 06:09:17 +00:00
|
|
|
import { shallowMount } from '@vue/test-utils';
|
2021-12-07 00:14:07 +00:00
|
|
|
import DescriptionField from '~/issues/show/components/fields/description.vue';
|
|
|
|
import eventHub from '~/issues/show/event_hub';
|
2021-02-14 18:09:20 +00:00
|
|
|
import MarkdownField from '~/vue_shared/components/markdown/field.vue';
|
2017-05-15 12:51:25 +00:00
|
|
|
|
|
|
|
describe('Description field component', () => {
|
2021-02-11 06:09:17 +00:00
|
|
|
let wrapper;
|
2017-05-17 13:35:02 +00:00
|
|
|
|
2021-02-11 06:09:17 +00:00
|
|
|
const findTextarea = () => wrapper.find({ ref: 'textarea' });
|
2017-06-23 11:29:49 +00:00
|
|
|
|
2021-02-11 06:09:17 +00:00
|
|
|
const mountComponent = (description = 'test') =>
|
|
|
|
shallowMount(DescriptionField, {
|
|
|
|
attachTo: document.body,
|
2017-05-15 12:51:25 +00:00
|
|
|
propsData: {
|
2017-08-17 17:25:56 +00:00
|
|
|
markdownPreviewPath: '/',
|
|
|
|
markdownDocsPath: '/',
|
2022-04-05 12:10:23 +00:00
|
|
|
quickActionsDocsPath: '/',
|
2022-04-07 12:10:21 +00:00
|
|
|
value: description,
|
2021-02-11 06:09:17 +00:00
|
|
|
},
|
|
|
|
stubs: {
|
|
|
|
MarkdownField,
|
2017-05-15 12:51:25 +00:00
|
|
|
},
|
2021-02-11 06:09:17 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
jest.spyOn(eventHub, '$emit');
|
|
|
|
});
|
2017-05-15 12:51:25 +00:00
|
|
|
|
2021-02-11 06:09:17 +00:00
|
|
|
afterEach(() => {
|
|
|
|
wrapper.destroy();
|
|
|
|
wrapper = null;
|
2017-05-15 12:51:25 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it('renders markdown field with description', () => {
|
2021-02-11 06:09:17 +00:00
|
|
|
wrapper = mountComponent();
|
|
|
|
|
|
|
|
expect(findTextarea().element.value).toBe('test');
|
2017-05-15 12:51:25 +00:00
|
|
|
});
|
2017-05-17 14:24:39 +00:00
|
|
|
|
2021-02-11 06:09:17 +00:00
|
|
|
it('renders markdown field with a markdown description', () => {
|
|
|
|
const markdown = '**test**';
|
2017-05-17 14:24:39 +00:00
|
|
|
|
2021-02-11 06:09:17 +00:00
|
|
|
wrapper = mountComponent(markdown);
|
2017-05-17 14:24:39 +00:00
|
|
|
|
2021-02-11 06:09:17 +00:00
|
|
|
expect(findTextarea().element.value).toBe(markdown);
|
2017-05-17 14:24:39 +00:00
|
|
|
});
|
2017-05-18 11:05:51 +00:00
|
|
|
|
2017-05-17 13:35:02 +00:00
|
|
|
it('focuses field when mounted', () => {
|
2021-02-11 06:09:17 +00:00
|
|
|
wrapper = mountComponent();
|
|
|
|
|
|
|
|
expect(document.activeElement).toBe(findTextarea().element);
|
2017-05-17 13:35:02 +00:00
|
|
|
});
|
2017-06-23 11:29:49 +00:00
|
|
|
|
|
|
|
it('triggers update with meta+enter', () => {
|
2021-02-11 06:09:17 +00:00
|
|
|
wrapper = mountComponent();
|
2017-06-23 11:29:49 +00:00
|
|
|
|
2021-02-11 06:09:17 +00:00
|
|
|
findTextarea().trigger('keydown.enter', { metaKey: true });
|
|
|
|
|
|
|
|
expect(eventHub.$emit).toHaveBeenCalledWith('update.issuable');
|
2017-06-23 11:29:49 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it('triggers update with ctrl+enter', () => {
|
2021-02-11 06:09:17 +00:00
|
|
|
wrapper = mountComponent();
|
2017-06-23 11:29:49 +00:00
|
|
|
|
2021-02-11 06:09:17 +00:00
|
|
|
findTextarea().trigger('keydown.enter', { ctrlKey: true });
|
2019-04-16 08:20:37 +00:00
|
|
|
|
2021-02-11 06:09:17 +00:00
|
|
|
expect(eventHub.$emit).toHaveBeenCalledWith('update.issuable');
|
2019-04-16 08:20:37 +00:00
|
|
|
});
|
2017-05-15 12:51:25 +00:00
|
|
|
});
|