Commit e9c3df74 authored by Dheeraj Joshi's avatar Dheeraj Joshi Committed by Kushal Pandya

Remove v-html from delete cluster modal

parent 93fb6734
<script> <script>
import { GlModal, GlButton, GlFormInput } from '@gitlab/ui'; import { GlModal, GlButton, GlFormInput, GlSprintf } from '@gitlab/ui';
import { escape } from 'lodash';
import csrf from '~/lib/utils/csrf'; import csrf from '~/lib/utils/csrf';
import { s__, sprintf } from '~/locale'; import { s__ } from '~/locale';
import SplitButton from '~/vue_shared/components/split_button.vue'; import SplitButton from '~/vue_shared/components/split_button.vue';
const splitButtonActionItems = [ const splitButtonActionItems = [
...@@ -29,6 +28,7 @@ export default { ...@@ -29,6 +28,7 @@ export default {
GlModal, GlModal,
GlButton, GlButton,
GlFormInput, GlFormInput,
GlSprintf,
}, },
props: { props: {
clusterPath: { clusterPath: {
...@@ -67,17 +67,11 @@ export default { ...@@ -67,17 +67,11 @@ export default {
: s__('ClusterIntegration|You are about to remove your cluster integration.'); : s__('ClusterIntegration|You are about to remove your cluster integration.');
}, },
confirmationTextLabel() { confirmationTextLabel() {
return sprintf( return this.confirmCleanup
this.confirmCleanup ? s__(
? s__( 'ClusterIntegration|To remove your integration and resources, type %{clusterName} to confirm:',
'ClusterIntegration|To remove your integration and resources, type %{clusterName} to confirm:', )
) : s__('ClusterIntegration|To remove your integration, type %{clusterName} to confirm:');
: s__('ClusterIntegration|To remove your integration, type %{clusterName} to confirm:'),
{
clusterName: `<code>${escape(this.clusterName)}</code>`,
},
false,
);
}, },
canSubmit() { canSubmit() {
return this.enteredClusterName === this.clusterName; return this.enteredClusterName === this.clusterName;
...@@ -140,7 +134,13 @@ export default { ...@@ -140,7 +134,13 @@ export default {
<!-- eslint-enable @gitlab/vue-require-i18n-strings --> <!-- eslint-enable @gitlab/vue-require-i18n-strings -->
</ul> </ul>
</div> </div>
<strong v-html="confirmationTextLabel /* eslint-disable-line vue/no-v-html */"></strong> <strong>
<gl-sprintf :message="confirmationTextLabel">
<template #clusterName>
<code>{{ clusterName }}</code>
</template>
</gl-sprintf>
</strong>
<form ref="form" :action="clusterPath" method="post" class="gl-mb-5"> <form ref="form" :action="clusterPath" method="post" class="gl-mb-5">
<input ref="method" type="hidden" name="_method" value="delete" /> <input ref="method" type="hidden" name="_method" value="delete" />
<input :value="csrfToken" type="hidden" name="authenticity_token" /> <input :value="csrfToken" type="hidden" name="authenticity_token" />
......
import { GlModal } from '@gitlab/ui'; import { GlModal, GlSprintf } from '@gitlab/ui';
import { mount } from '@vue/test-utils'; import { mount } from '@vue/test-utils';
import { stubComponent } from 'helpers/stub_component';
import RemoveClusterConfirmation from '~/clusters/components/remove_cluster_confirmation.vue'; import RemoveClusterConfirmation from '~/clusters/components/remove_cluster_confirmation.vue';
import SplitButton from '~/vue_shared/components/split_button.vue'; import SplitButton from '~/vue_shared/components/split_button.vue';
describe('Remove cluster confirmation modal', () => { describe('Remove cluster confirmation modal', () => {
let wrapper; let wrapper;
const createComponent = (props = {}) => { const createComponent = ({ props = {}, stubs = {} } = {}) => {
wrapper = mount(RemoveClusterConfirmation, { wrapper = mount(RemoveClusterConfirmation, {
propsData: { propsData: {
clusterPath: 'clusterPath', clusterPath: 'clusterPath',
clusterName: 'clusterName', clusterName: 'clusterName',
...props, ...props,
}, },
stubs,
}); });
}; };
...@@ -27,35 +29,44 @@ describe('Remove cluster confirmation modal', () => { ...@@ -27,35 +29,44 @@ describe('Remove cluster confirmation modal', () => {
}); });
describe('split button dropdown', () => { describe('split button dropdown', () => {
const findModal = () => wrapper.find(GlModal).vm; const findModal = () => wrapper.findComponent(GlModal);
const findSplitButton = () => wrapper.find(SplitButton); const findSplitButton = () => wrapper.findComponent(SplitButton);
beforeEach(() => { beforeEach(() => {
createComponent({ clusterName: 'my-test-cluster' }); createComponent({
jest.spyOn(findModal(), 'show').mockReturnValue(); props: { clusterName: 'my-test-cluster' },
stubs: { GlSprintf, GlModal: stubComponent(GlModal) },
});
jest.spyOn(findModal().vm, 'show').mockReturnValue();
}); });
it('opens modal with "cleanup" option', () => { it('opens modal with "cleanup" option', async () => {
findSplitButton().vm.$emit('remove-cluster-and-cleanup'); findSplitButton().vm.$emit('remove-cluster-and-cleanup');
return wrapper.vm.$nextTick().then(() => { await wrapper.vm.$nextTick();
expect(findModal().show).toHaveBeenCalled();
expect(wrapper.vm.confirmCleanup).toEqual(true); expect(findModal().vm.show).toHaveBeenCalled();
}); expect(wrapper.vm.confirmCleanup).toEqual(true);
expect(findModal().html()).toContain(
'<strong>To remove your integration and resources, type <code>my-test-cluster</code> to confirm:</strong>',
);
}); });
it('opens modal without "cleanup" option', () => { it('opens modal without "cleanup" option', async () => {
findSplitButton().vm.$emit('remove-cluster'); findSplitButton().vm.$emit('remove-cluster');
return wrapper.vm.$nextTick().then(() => { await wrapper.vm.$nextTick();
expect(findModal().show).toHaveBeenCalled();
expect(wrapper.vm.confirmCleanup).toEqual(false); expect(findModal().vm.show).toHaveBeenCalled();
}); expect(wrapper.vm.confirmCleanup).toEqual(false);
expect(findModal().html()).toContain(
'<strong>To remove your integration, type <code>my-test-cluster</code> to confirm:</strong>',
);
}); });
describe('with cluster management project', () => { describe('with cluster management project', () => {
beforeEach(() => { beforeEach(() => {
createComponent({ hasManagementProject: true }); createComponent({ props: { hasManagementProject: true } });
}); });
it('renders regular button instead', () => { it('renders regular button instead', () => {
......
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