summaryrefslogtreecommitdiff
path: root/spec/frontend/vue_shared/components/markdown/field_spec.js
diff options
context:
space:
mode:
Diffstat (limited to 'spec/frontend/vue_shared/components/markdown/field_spec.js')
-rw-r--r--spec/frontend/vue_shared/components/markdown/field_spec.js43
1 files changed, 37 insertions, 6 deletions
diff --git a/spec/frontend/vue_shared/components/markdown/field_spec.js b/spec/frontend/vue_shared/components/markdown/field_spec.js
index 3b8e78bbadd..68ce07f86b9 100644
--- a/spec/frontend/vue_shared/components/markdown/field_spec.js
+++ b/spec/frontend/vue_shared/components/markdown/field_spec.js
@@ -1,11 +1,13 @@
+import $ from 'jquery';
import { nextTick } from 'vue';
import AxiosMockAdapter from 'axios-mock-adapter';
import { TEST_HOST, FIXTURES_PATH } from 'spec/test_constants';
import axios from '~/lib/utils/axios_utils';
+import { HTTP_STATUS_OK } from '~/lib/utils/http_status';
import MarkdownField from '~/vue_shared/components/markdown/field.vue';
import MarkdownFieldHeader from '~/vue_shared/components/markdown/header.vue';
import MarkdownToolbar from '~/vue_shared/components/markdown/toolbar.vue';
-import { mountExtended } from 'helpers/vue_test_utils_helper';
+import { mountExtended, shallowMountExtended } from 'helpers/vue_test_utils_helper';
import { renderGFM } from '~/behaviors/markdown/render_gfm';
jest.mock('~/behaviors/markdown/render_gfm');
@@ -74,6 +76,22 @@ describe('Markdown field component', () => {
);
}
+ function createWrapper({ autocompleteDataSources = {} } = {}) {
+ subject = shallowMountExtended(MarkdownField, {
+ propsData: {
+ markdownDocsPath,
+ markdownPreviewPath,
+ isSubmitting: false,
+ textareaValue,
+ lines: [],
+ enablePreview: true,
+ restrictedToolBarItems,
+ showContentEditorSwitcher: false,
+ autocompleteDataSources,
+ },
+ });
+ }
+
const getPreviewLink = () => subject.findByTestId('preview-tab');
const getWriteLink = () => subject.findByTestId('write-tab');
const getMarkdownButton = () => subject.find('.js-md');
@@ -84,6 +102,7 @@ describe('Markdown field component', () => {
const findDropzone = () => subject.find('.div-dropzone');
const findMarkdownHeader = () => subject.findComponent(MarkdownFieldHeader);
const findMarkdownToolbar = () => subject.findComponent(MarkdownToolbar);
+ const findGlForm = () => $(subject.vm.$refs['gl-form']).data('glForm');
describe('mounted', () => {
const previewHTML = `
@@ -100,6 +119,18 @@ describe('Markdown field component', () => {
findDropzone().element.addEventListener('click', dropzoneSpy);
});
+ describe('GlForm', () => {
+ beforeEach(() => {
+ createWrapper({ autocompleteDataSources: { commands: '/foobar/-/autocomplete_sources' } });
+ });
+
+ it('initializes GlForm with autocomplete data sources', () => {
+ expect(findGlForm().autoComplete.dataSources).toMatchObject({
+ commands: '/foobar/-/autocomplete_sources',
+ });
+ });
+ });
+
it('renders textarea inside backdrop', () => {
expect(subject.find('.zen-backdrop textarea').element).not.toBeNull();
});
@@ -107,7 +138,7 @@ describe('Markdown field component', () => {
it('renders referenced commands on markdown preview', async () => {
axiosMock
.onPost(markdownPreviewPath)
- .reply(200, { references: { users: [], commands: 'test command' } });
+ .reply(HTTP_STATUS_OK, { references: { users: [], commands: 'test command' } });
previewLink = getPreviewLink();
previewLink.vm.$emit('click', { target: {} });
@@ -121,7 +152,7 @@ describe('Markdown field component', () => {
describe('markdown preview', () => {
beforeEach(() => {
- axiosMock.onPost(markdownPreviewPath).reply(200, { body: previewHTML });
+ axiosMock.onPost(markdownPreviewPath).reply(HTTP_STATUS_OK, { body: previewHTML });
});
it('sets preview link as active', async () => {
@@ -267,7 +298,7 @@ describe('Markdown field component', () => {
const users = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11].map((i) => `user_${i}`);
it('shows warning on mention of all users', async () => {
- axiosMock.onPost(markdownPreviewPath).reply(200, { references: { users } });
+ axiosMock.onPost(markdownPreviewPath).reply(HTTP_STATUS_OK, { references: { users } });
subject.setProps({ textareaValue: 'hello @all' });
@@ -279,7 +310,7 @@ describe('Markdown field component', () => {
});
it('removes warning when all mention is removed', async () => {
- axiosMock.onPost(markdownPreviewPath).reply(200, { references: { users } });
+ axiosMock.onPost(markdownPreviewPath).reply(HTTP_STATUS_OK, { references: { users } });
subject.setProps({ textareaValue: 'hello @all' });
@@ -298,7 +329,7 @@ describe('Markdown field component', () => {
});
it('removes warning when all mention is removed while endpoint is loading', async () => {
- axiosMock.onPost(markdownPreviewPath).reply(200, { references: { users } });
+ axiosMock.onPost(markdownPreviewPath).reply(HTTP_STATUS_OK, { references: { users } });
jest.spyOn(axios, 'post');
subject.setProps({ textareaValue: 'hello @all' });