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

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

70 lines
1.8 KiB
JavaScript
Raw Normal View History

2021-03-11 19:13:27 +05:30
import { shallowMount } from '@vue/test-utils';
2022-01-26 12:08:38 +05:30
import DescriptionField from '~/issues/show/components/fields/description.vue';
import eventHub from '~/issues/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: '/',
2022-06-21 17:19:12 +05:30
quickActionsDocsPath: '/',
value: description,
2021-03-11 19:13:27 +05:30
},
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
});