Commit 7336fe61 authored by Dheeraj Joshi's avatar Dheeraj Joshi Committed by Ezekiel Kigbo

Swaps out v-html with GlSprintf in MR widget

parent c6904269
<script> <script>
import { GlModal, GlButton } from '@gitlab/ui'; import { GlModal, GlButton, GlSprintf, GlLink } from '@gitlab/ui';
import { escape } from 'lodash'; import { __ } from '~/locale';
import { __, sprintf } from '~/locale';
export default { export default {
name: 'MergeImmediatelyConfirmationDialog', name: 'MergeImmediatelyConfirmationDialog',
components: { components: {
GlModal, GlModal,
GlButton, GlButton,
GlSprintf,
GlLink,
}, },
props: { props: {
docsUrl: { docsUrl: {
...@@ -17,17 +18,8 @@ export default { ...@@ -17,17 +18,8 @@ export default {
}, },
computed: { computed: {
bodyText() { bodyText() {
return sprintf( return __(
__( "Merging immediately isn't recommended as it may negatively impact the existing merge train. Read the %{docsLinkStart}documentation%{docsLinkEnd} for more information.",
"Merging immediately isn't recommended as it may negatively impact the existing merge train. Read the %{docsLinkStart}documentation%{docsLinkEnd} for more information.",
),
{
docsLinkStart: `<a href="${escape(
this.docsUrl,
)}" target="_blank" rel="noopener noreferrer">`,
docsLinkEnd: '</a>',
},
false,
); );
}, },
}, },
...@@ -58,7 +50,13 @@ export default { ...@@ -58,7 +50,13 @@ export default {
:title="__('Merge immediately')" :title="__('Merge immediately')"
@shown="focusCancelButton" @shown="focusCancelButton"
> >
<p v-html="bodyText /* eslint-disable-line vue/no-v-html */"></p> <p>
<gl-sprintf :message="bodyText">
<template #docsLink="{ content }">
<gl-link :href="docsUrl" target="_blank">{{ content }}</gl-link>
</template>
</gl-sprintf>
</p>
<p>{{ __('Are you sure you want to merge immediately?') }}</p> <p>{{ __('Are you sure you want to merge immediately?') }}</p>
<template #modal-footer> <template #modal-footer>
<gl-button ref="cancelButton" @click="cancel">{{ __('Cancel') }}</gl-button> <gl-button ref="cancelButton" @click="cancel">{{ __('Cancel') }}</gl-button>
......
import { GlSprintf, GlLink } from '@gitlab/ui';
import { shallowMount } from '@vue/test-utils'; import { shallowMount } from '@vue/test-utils';
import MergeImmediatelyConfirmationDialog from 'ee/vue_merge_request_widget/components/merge_immediately_confirmation_dialog.vue'; import MergeImmediatelyConfirmationDialog from 'ee/vue_merge_request_widget/components/merge_immediately_confirmation_dialog.vue';
import { trimText } from 'helpers/text_helper'; import { trimText } from 'helpers/text_helper';
...@@ -9,6 +10,9 @@ describe('MergeImmediatelyConfirmationDialog', () => { ...@@ -9,6 +10,9 @@ describe('MergeImmediatelyConfirmationDialog', () => {
beforeEach(() => { beforeEach(() => {
wrapper = shallowMount(MergeImmediatelyConfirmationDialog, { wrapper = shallowMount(MergeImmediatelyConfirmationDialog, {
propsData: { docsUrl }, propsData: { docsUrl },
stubs: {
GlSprintf,
},
}); });
return wrapper.vm.$nextTick(); return wrapper.vm.$nextTick();
...@@ -21,10 +25,10 @@ describe('MergeImmediatelyConfirmationDialog', () => { ...@@ -21,10 +25,10 @@ describe('MergeImmediatelyConfirmationDialog', () => {
}); });
it('should render a link to the documentation', () => { it('should render a link to the documentation', () => {
const docsLink = wrapper.find(`a[href="${docsUrl}"]`); const docsLink = wrapper.findComponent(GlLink);
expect(docsLink.exists()).toBe(true); expect(docsLink.exists()).toBe(true);
expect(docsLink.attributes().rel).toBe('noopener noreferrer'); expect(docsLink.attributes('href')).toBe(docsUrl);
expect(trimText(docsLink.text())).toBe('documentation'); expect(trimText(docsLink.text())).toBe('documentation');
}); });
......
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