diff --git a/app/assets/javascripts/vue_shared/components/markdown/field.vue b/app/assets/javascripts/vue_shared/components/markdown/field.vue index b520d302407..a32ed529342 100644 --- a/app/assets/javascripts/vue_shared/components/markdown/field.vue +++ b/app/assets/javascripts/vue_shared/components/markdown/field.vue @@ -9,6 +9,7 @@ import markdownHeader from './header.vue'; import markdownToolbar from './toolbar.vue'; import icon from '../icon.vue'; import Suggestions from '~/vue_shared/components/markdown/suggestions.vue'; +import axios from '~/lib/utils/axios_utils'; export default { components: { @@ -167,10 +168,9 @@ export default { if (text) { this.markdownPreviewLoading = true; this.markdownPreview = __('Loading…'); - this.$http + axios .post(this.markdownPreviewPath, { text }) - .then(resp => resp.json()) - .then(data => this.renderMarkdown(data)) + .then(response => this.renderMarkdown(response.data)) .catch(() => new Flash(__('Error loading markdown preview'))); } else { this.renderMarkdown(); diff --git a/changelogs/unreleased/61385-replace-vue-resource.yml b/changelogs/unreleased/61385-replace-vue-resource.yml new file mode 100644 index 00000000000..787581b3f81 --- /dev/null +++ b/changelogs/unreleased/61385-replace-vue-resource.yml @@ -0,0 +1,5 @@ +--- +title: Replaced vue resource to axios in the Markdown field preview component +merge_request: 32742 +author: Prakash Chokalingam @prakash_Chokalingam +type: fixed diff --git a/spec/javascripts/vue_shared/components/markdown/field_spec.js b/spec/javascripts/vue_shared/components/markdown/field_spec.js index 02d73e1849a..da984175f9f 100644 --- a/spec/javascripts/vue_shared/components/markdown/field_spec.js +++ b/spec/javascripts/vue_shared/components/markdown/field_spec.js @@ -1,6 +1,10 @@ import $ from 'jquery'; +import '~/behaviors/markdown/render_gfm'; import Vue from 'vue'; +import AxiosMockAdapter from 'axios-mock-adapter'; +import axios from '~/lib/utils/axios_utils'; import fieldComponent from '~/vue_shared/components/markdown/field.vue'; +import { TEST_HOST } from 'spec/test_constants'; function assertMarkdownTabs(isWrite, writeLink, previewLink, vm) { expect(writeLink.parentNode.classList.contains('active')).toEqual(isWrite); @@ -9,9 +13,13 @@ function assertMarkdownTabs(isWrite, writeLink, previewLink, vm) { } describe('Markdown field component', () => { + const markdownPreviewPath = `${TEST_HOST}/preview`; + const markdownDocsPath = `${TEST_HOST}/docs`; + let axiosMock; let vm; beforeEach(done => { + axiosMock = new AxiosMockAdapter(axios); vm = new Vue({ components: { fieldComponent, @@ -23,8 +31,8 @@ describe('Markdown field component', () => { }, template: `