Commit b6299666 authored by Jacques Erasmus's avatar Jacques Erasmus

Merge branch 'delete-blob-spec-mount' into 'master'

Update Delete Blob  Modal to use GlForm

See merge request gitlab-org/gitlab!66590
parents 53f6388a bad40dd2
<script> <script>
import { GlModal, GlFormGroup, GlFormInput, GlFormTextarea, GlToggle } from '@gitlab/ui'; import { GlModal, GlFormGroup, GlFormInput, GlFormTextarea, GlToggle, GlForm } from '@gitlab/ui';
import csrf from '~/lib/utils/csrf'; import csrf from '~/lib/utils/csrf';
import { __ } from '~/locale'; import { __ } from '~/locale';
import { import {
...@@ -17,6 +17,7 @@ export default { ...@@ -17,6 +17,7 @@ export default {
GlFormInput, GlFormInput,
GlFormTextarea, GlFormTextarea,
GlToggle, GlToggle,
GlForm,
}, },
i18n: { i18n: {
PRIMARY_OPTIONS_TEXT: __('Delete file'), PRIMARY_OPTIONS_TEXT: __('Delete file'),
...@@ -102,7 +103,7 @@ export default { ...@@ -102,7 +103,7 @@ export default {
submitForm(e) { submitForm(e) {
e.preventDefault(); // Prevent modal from closing e.preventDefault(); // Prevent modal from closing
this.loading = true; this.loading = true;
this.$refs.form.submit(); this.$refs.form.$el.submit();
}, },
}, },
}; };
...@@ -110,13 +111,15 @@ export default { ...@@ -110,13 +111,15 @@ export default {
<template> <template>
<gl-modal <gl-modal
v-bind="$attrs"
data-testid="modal-delete"
:modal-id="modalId" :modal-id="modalId"
:title="modalTitle" :title="modalTitle"
:action-primary="primaryOptions" :action-primary="primaryOptions"
:action-cancel="cancelOptions" :action-cancel="cancelOptions"
@primary="submitForm" @primary="submitForm"
> >
<form ref="form" :action="deletePath" method="post"> <gl-form ref="form" :action="deletePath" method="post">
<input type="hidden" name="_method" value="delete" /> <input type="hidden" name="_method" value="delete" />
<input :value="$options.csrf.token" type="hidden" name="authenticity_token" /> <input :value="$options.csrf.token" type="hidden" name="authenticity_token" />
<template v-if="emptyRepo"> <template v-if="emptyRepo">
...@@ -146,6 +149,6 @@ export default { ...@@ -146,6 +149,6 @@ export default {
:label="$options.i18n.TOGGLE_CREATE_MR_LABEL" :label="$options.i18n.TOGGLE_CREATE_MR_LABEL"
/> />
</template> </template>
</form> </gl-form>
</gl-modal> </gl-modal>
</template> </template>
import { GlFormTextarea, GlModal, GlFormInput, GlToggle } from '@gitlab/ui'; import { GlFormTextarea, GlModal, GlFormInput, GlToggle, GlForm } from '@gitlab/ui';
import { shallowMount } from '@vue/test-utils'; import { shallowMount, mount } from '@vue/test-utils';
import { nextTick } from 'vue'; import { nextTick } from 'vue';
import DeleteBlobModal from '~/repository/components/delete_blob_modal.vue'; import DeleteBlobModal from '~/repository/components/delete_blob_modal.vue';
...@@ -19,17 +19,24 @@ const initialProps = { ...@@ -19,17 +19,24 @@ const initialProps = {
describe('DeleteBlobModal', () => { describe('DeleteBlobModal', () => {
let wrapper; let wrapper;
const createComponent = (props = {}) => { const createComponentFactory = (mountFn) => (props = {}) => {
wrapper = shallowMount(DeleteBlobModal, { wrapper = mountFn(DeleteBlobModal, {
propsData: { propsData: {
...initialProps, ...initialProps,
...props, ...props,
}, },
attrs: {
static: true,
visible: true,
},
}); });
}; };
const createComponent = createComponentFactory(shallowMount);
const createFullComponent = createComponentFactory(mount);
const findModal = () => wrapper.findComponent(GlModal); const findModal = () => wrapper.findComponent(GlModal);
const findForm = () => wrapper.findComponent({ ref: 'form' }); const findForm = () => findModal().findComponent(GlForm);
afterEach(() => { afterEach(() => {
wrapper.destroy(); wrapper.destroy();
...@@ -59,7 +66,8 @@ describe('DeleteBlobModal', () => { ...@@ -59,7 +66,8 @@ describe('DeleteBlobModal', () => {
}); });
it('submits the form', async () => { it('submits the form', async () => {
createComponent(); createFullComponent();
await nextTick();
const submitSpy = jest.spyOn(findForm().element, 'submit'); const submitSpy = jest.spyOn(findForm().element, 'submit');
findModal().vm.$emit('primary', { preventDefault: () => {} }); findModal().vm.$emit('primary', { preventDefault: () => {} });
......
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