Commit 017385bd authored by Denys Mishunov's avatar Denys Mishunov

Converting mixin to a component

As siggested by maintainer, converted mixin into a component to avoid
technical debt
parent be4e286b
<script> <script>
import MarkdownFieldMixin from '~/vue_shared/mixins/markdown_field_mixin'; import MarkdownFieldView from '~/vue_shared/components/markdown/field_view.vue';
export default { export default {
mixins: [MarkdownFieldMixin], components: {
MarkdownFieldView,
},
props: { props: {
description: { description: {
type: String, type: String,
...@@ -13,7 +15,7 @@ export default { ...@@ -13,7 +15,7 @@ export default {
}; };
</script> </script>
<template> <template>
<div class="snippet-description" data-qa-selector="snippet_description_field"> <markdown-field-view class="snippet-description" data-qa-selector="snippet_description_field">
<div class="md js-snippet-description" v-html="description"></div> <div class="md js-snippet-description" v-html="description"></div>
</div> </markdown-field-view>
</template> </template>
<script> <script>
import MarkdownFieldMixin from '~/vue_shared/mixins/markdown_field_mixin'; import MarkdownFieldView from '~/vue_shared/components/markdown/field_view.vue';
import ViewerMixin from './mixins'; import ViewerMixin from './mixins';
import { handleBlobRichViewer } from '~/blob/viewer'; import { handleBlobRichViewer } from '~/blob/viewer';
export default { export default {
mixins: [ViewerMixin, MarkdownFieldMixin], components: {
MarkdownFieldView,
},
mixins: [ViewerMixin],
mounted() { mounted() {
handleBlobRichViewer(this.$refs.content, this.type); handleBlobRichViewer(this.$refs.content, this.type);
}, },
}; };
</script> </script>
<template> <template>
<div ref="content" v-html="content"></div> <markdown-field-view ref="content" v-html="content" />
</template> </template>
<script>
import $ from 'jquery'; import $ from 'jquery';
import '~/behaviors/markdown/render_gfm'; import '~/behaviors/markdown/render_gfm';
...@@ -11,3 +12,8 @@ export default { ...@@ -11,3 +12,8 @@ export default {
}, },
}, },
}; };
</script>
<template>
<div><slot></slot></div>
</template>
// Jest Snapshot v1, https://goo.gl/fbAQLP // Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`Snippet Description component matches the snapshot 1`] = ` exports[`Snippet Description component matches the snapshot 1`] = `
<div <markdown-field-view-stub
class="snippet-description" class="snippet-description"
data-qa-selector="snippet_description_field" data-qa-selector="snippet_description_field"
> >
...@@ -12,5 +12,5 @@ exports[`Snippet Description component matches the snapshot 1`] = ` ...@@ -12,5 +12,5 @@ exports[`Snippet Description component matches the snapshot 1`] = `
The property of Thor The property of Thor
</h2> </h2>
</div> </div>
</div> </markdown-field-view-stub>
`; `;
import SnippetDescription from '~/snippets/components/snippet_description_view.vue'; import SnippetDescription from '~/snippets/components/snippet_description_view.vue';
import { shallowMount } from '@vue/test-utils'; import { shallowMount } from '@vue/test-utils';
import $ from 'jquery';
describe('Snippet Description component', () => { describe('Snippet Description component', () => {
let wrapper; let wrapper;
const description = '<h2>The property of Thor</h2>'; const description = '<h2>The property of Thor</h2>';
let renderGFMSpy;
function createComponent() { function createComponent() {
wrapper = shallowMount(SnippetDescription, { wrapper = shallowMount(SnippetDescription, {
...@@ -16,7 +14,6 @@ describe('Snippet Description component', () => { ...@@ -16,7 +14,6 @@ describe('Snippet Description component', () => {
} }
beforeEach(() => { beforeEach(() => {
renderGFMSpy = jest.spyOn($.fn, 'renderGFM');
createComponent(); createComponent();
}); });
...@@ -27,8 +24,4 @@ describe('Snippet Description component', () => { ...@@ -27,8 +24,4 @@ describe('Snippet Description component', () => {
it('matches the snapshot', () => { it('matches the snapshot', () => {
expect(wrapper.element).toMatchSnapshot(); expect(wrapper.element).toMatchSnapshot();
}); });
it('processes rendering with GFM', () => {
expect(renderGFMSpy).toHaveBeenCalled();
});
}); });
import { shallowMount } from '@vue/test-utils'; import { shallowMount } from '@vue/test-utils';
import RichViewer from '~/vue_shared/components/blob_viewers/rich_viewer.vue'; import RichViewer from '~/vue_shared/components/blob_viewers/rich_viewer.vue';
import MarkdownFieldView from '~/vue_shared/components/markdown/field_view.vue';
import { handleBlobRichViewer } from '~/blob/viewer'; import { handleBlobRichViewer } from '~/blob/viewer';
import $ from 'jquery';
jest.mock('~/blob/viewer'); jest.mock('~/blob/viewer');
...@@ -10,8 +10,6 @@ describe('Blob Rich Viewer component', () => { ...@@ -10,8 +10,6 @@ describe('Blob Rich Viewer component', () => {
const content = '<h1 id="markdown">Foo Bar</h1>'; const content = '<h1 id="markdown">Foo Bar</h1>';
const defaultType = 'markdown'; const defaultType = 'markdown';
let renderGFMSpy;
function createComponent(type = defaultType) { function createComponent(type = defaultType) {
wrapper = shallowMount(RichViewer, { wrapper = shallowMount(RichViewer, {
propsData: { propsData: {
...@@ -22,7 +20,6 @@ describe('Blob Rich Viewer component', () => { ...@@ -22,7 +20,6 @@ describe('Blob Rich Viewer component', () => {
} }
beforeEach(() => { beforeEach(() => {
renderGFMSpy = jest.spyOn($.fn, 'renderGFM');
createComponent(); createComponent();
}); });
...@@ -38,7 +35,7 @@ describe('Blob Rich Viewer component', () => { ...@@ -38,7 +35,7 @@ describe('Blob Rich Viewer component', () => {
expect(handleBlobRichViewer).toHaveBeenCalledWith(expect.anything(), defaultType); expect(handleBlobRichViewer).toHaveBeenCalledWith(expect.anything(), defaultType);
}); });
it('processes rendering with GFM', () => { it('is using Markdown View Field', () => {
expect(renderGFMSpy).toHaveBeenCalled(); expect(wrapper.contains(MarkdownFieldView)).toBe(true);
}); });
}); });
import $ from 'jquery';
import { shallowMount } from '@vue/test-utils';
import MarkdownFieldView from '~/vue_shared/components/markdown/field_view.vue';
describe('Markdown Field View component', () => {
let renderGFMSpy;
let wrapper;
function createComponent() {
wrapper = shallowMount(MarkdownFieldView);
}
beforeEach(() => {
renderGFMSpy = jest.spyOn($.fn, 'renderGFM');
createComponent();
});
afterEach(() => {
wrapper.destroy();
});
it('processes rendering with GFM', () => {
expect(renderGFMSpy).toHaveBeenCalledTimes(1);
});
});
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment