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.

118 lines
3.3 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';
2022-11-25 23:54:43 +05:30
import MarkdownEditor from '~/vue_shared/components/markdown/markdown_editor.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
2022-10-11 01:57:18 +05:30
const findTextarea = () => wrapper.findComponent({ ref: 'textarea' });
2022-11-25 23:54:43 +05:30
const findMarkdownEditor = () => wrapper.findComponent(MarkdownEditor);
2017-09-10 17:25:29 +05:30
2022-11-25 23:54:43 +05:30
const mountComponent = ({ description = 'test', contentEditorOnIssues = false } = {}) =>
2021-03-11 19:13:27 +05:30
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
},
2022-11-25 23:54:43 +05:30
provide: {
glFeatures: {
contentEditorOnIssues,
},
},
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
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
2022-11-25 23:54:43 +05:30
wrapper = mountComponent({ description: 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
});
2022-11-25 23:54:43 +05:30
describe('when contentEditorOnIssues feature flag is on', () => {
beforeEach(() => {
wrapper = mountComponent({ contentEditorOnIssues: true });
});
it('uses the MarkdownEditor component to edit markdown', () => {
2023-05-27 22:25:52 +05:30
expect(findMarkdownEditor().props()).toMatchObject({
value: 'test',
renderMarkdownPath: '/',
autofocus: true,
supportsQuickActions: true,
quickActionsDocsPath: expect.any(String),
2023-06-20 00:43:36 +05:30
markdownDocsPath: '/',
enableAutocomplete: true,
2023-05-27 22:25:52 +05:30
});
2022-11-25 23:54:43 +05:30
});
it('triggers update with meta+enter', () => {
findMarkdownEditor().vm.$emit('keydown', {
type: 'keydown',
keyCode: 13,
metaKey: true,
});
expect(eventHub.$emit).toHaveBeenCalledWith('update.issuable');
});
it('triggers update with ctrl+enter', () => {
findMarkdownEditor().vm.$emit('keydown', {
type: 'keydown',
keyCode: 13,
ctrlKey: true,
});
expect(eventHub.$emit).toHaveBeenCalledWith('update.issuable');
});
it('emits input event when MarkdownEditor emits input event', () => {
const markdown = 'markdown';
findMarkdownEditor().vm.$emit('input', markdown);
expect(wrapper.emitted('input')).toEqual([[markdown]]);
});
});
2017-09-10 17:25:29 +05:30
});