debian-mirror-gitlab/spec/frontend/issue_show/components/fields/description_spec.js

71 lines
1.7 KiB
JavaScript
Raw Normal View History

2021-03-11 19:13:27 +05:30
import { shallowMount } from '@vue/test-utils';
import DescriptionField from '~/issue_show/components/fields/description.vue';
2017-09-10 17:25:29 +05:30
import eventHub from '~/issue_show/event_hub';
2021-03-11 19:13:27 +05:30
import MarkdownField from '~/vue_shared/components/markdown/field.vue';
2017-09-10 17:25:29 +05:30
describe('Description field component', () => {
2021-03-11 19:13:27 +05:30
let wrapper;
2017-09-10 17:25:29 +05:30
2021-03-11 19:13:27 +05:30
const findTextarea = () => wrapper.find({ ref: 'textarea' });
2017-09-10 17:25:29 +05:30
2021-03-11 19:13:27 +05:30
const mountComponent = (description = 'test') =>
shallowMount(DescriptionField, {
attachTo: document.body,
2017-09-10 17:25:29 +05:30
propsData: {
2018-03-17 18:26:18 +05:30
markdownPreviewPath: '/',
markdownDocsPath: '/',
2021-03-11 19:13:27 +05:30
formState: {
description,
},
},
stubs: {
MarkdownField,
2017-09-10 17:25:29 +05:30
},
2021-03-11 19:13:27 +05:30
});
beforeEach(() => {
jest.spyOn(eventHub, '$emit');
});
2017-09-10 17:25:29 +05:30
2021-03-11 19:13:27 +05:30
afterEach(() => {
wrapper.destroy();
wrapper = null;
2017-09-10 17:25:29 +05:30
});
it('renders markdown field with description', () => {
2021-03-11 19:13:27 +05:30
wrapper = mountComponent();
expect(findTextarea().element.value).toBe('test');
2017-09-10 17:25:29 +05:30
});
2021-03-11 19:13:27 +05:30
it('renders markdown field with a markdown description', () => {
const markdown = '**test**';
2017-09-10 17:25:29 +05:30
2021-03-11 19:13:27 +05:30
wrapper = mountComponent(markdown);
2017-09-10 17:25:29 +05:30
2021-03-11 19:13:27 +05:30
expect(findTextarea().element.value).toBe(markdown);
2017-09-10 17:25:29 +05:30
});
it('focuses field when mounted', () => {
2021-03-11 19:13:27 +05:30
wrapper = mountComponent();
expect(document.activeElement).toBe(findTextarea().element);
2017-09-10 17:25:29 +05:30
});
it('triggers update with meta+enter', () => {
2021-03-11 19:13:27 +05:30
wrapper = mountComponent();
2017-09-10 17:25:29 +05:30
2021-03-11 19:13:27 +05:30
findTextarea().trigger('keydown.enter', { metaKey: true });
expect(eventHub.$emit).toHaveBeenCalledWith('update.issuable');
2017-09-10 17:25:29 +05:30
});
it('triggers update with ctrl+enter', () => {
2021-03-11 19:13:27 +05:30
wrapper = mountComponent();
2017-09-10 17:25:29 +05:30
2021-03-11 19:13:27 +05:30
findTextarea().trigger('keydown.enter', { ctrlKey: true });
2019-07-31 22:56:46 +05:30
2021-03-11 19:13:27 +05:30
expect(eventHub.$emit).toHaveBeenCalledWith('update.issuable');
2019-07-31 22:56:46 +05:30
});
2017-09-10 17:25:29 +05:30
});