Skip to content
代码片段 群组 项目
提交 c0f82c6f 编辑于 作者: Doug Stull's avatar Doug Stull 提交者: Eduardo Sanz García
浏览文件

Fix invite project members modal closing on error

- keep modal open if the request failed

Changelog: fixed
上级 275bb8a2
No related branches found
No related tags found
无相关合并请求
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
import { GlFormGroup, GlModal, GlSprintf } from '@gitlab/ui'; import { GlFormGroup, GlModal, GlSprintf } from '@gitlab/ui';
import { uniqueId } from 'lodash'; import { uniqueId } from 'lodash';
import { importProjectMembers } from '~/api/projects_api'; import { importProjectMembers } from '~/api/projects_api';
import { BV_SHOW_MODAL } from '~/lib/utils/constants'; import { BV_SHOW_MODAL, BV_HIDE_MODAL } from '~/lib/utils/constants';
import { s__, __, sprintf } from '~/locale'; import { s__, __, sprintf } from '~/locale';
import eventHub from '../event_hub'; import eventHub from '../event_hub';
import { import {
...@@ -80,11 +80,17 @@ export default { ...@@ -80,11 +80,17 @@ export default {
openModal() { openModal() {
this.$root.$emit(BV_SHOW_MODAL, this.$options.modalId); this.$root.$emit(BV_SHOW_MODAL, this.$options.modalId);
}, },
closeModal() {
this.$root.$emit(BV_HIDE_MODAL, this.$options.modalId);
},
resetFields() { resetFields() {
this.invalidFeedbackMessage = ''; this.invalidFeedbackMessage = '';
this.projectToBeImported = {}; this.projectToBeImported = {};
}, },
submitImport() { submitImport(e) {
// We never want to hide when submitting
e.preventDefault();
this.isLoading = true; this.isLoading = true;
return importProjectMembers(this.projectId, this.projectToBeImported.id) return importProjectMembers(this.projectId, this.projectToBeImported.id)
.then(this.onInviteSuccess) .then(this.onInviteSuccess)
......
import { GlFormGroup, GlSprintf, GlModal } from '@gitlab/ui'; import { GlFormGroup, GlSprintf, GlModal } from '@gitlab/ui';
import MockAdapter from 'axios-mock-adapter'; import MockAdapter from 'axios-mock-adapter';
import { nextTick } from 'vue'; import { nextTick } from 'vue';
import { createWrapper } from '@vue/test-utils';
import { BV_HIDE_MODAL } from '~/lib/utils/constants';
import { stubComponent } from 'helpers/stub_component'; import { stubComponent } from 'helpers/stub_component';
import { shallowMountExtended } from 'helpers/vue_test_utils_helper'; import { shallowMountExtended } from 'helpers/vue_test_utils_helper';
import waitForPromises from 'helpers/wait_for_promises'; import waitForPromises from 'helpers/wait_for_promises';
...@@ -107,6 +109,15 @@ describe('ImportProjectMembersModal', () => { ...@@ -107,6 +109,15 @@ describe('ImportProjectMembersModal', () => {
}); });
describe('submitting the import', () => { describe('submitting the import', () => {
it('prevents closing', () => {
const evt = { preventDefault: jest.fn() };
createComponent();
findGlModal().vm.$emit('primary', evt);
expect(evt.preventDefault).toHaveBeenCalledTimes(1);
});
describe('when the import is successful with reloadPageOnSubmit', () => { describe('when the import is successful with reloadPageOnSubmit', () => {
beforeEach(() => { beforeEach(() => {
createComponent({ createComponent({
...@@ -161,6 +172,12 @@ describe('ImportProjectMembersModal', () => { ...@@ -161,6 +172,12 @@ describe('ImportProjectMembersModal', () => {
); );
}); });
it('hides the modal', () => {
const rootWrapper = createWrapper(wrapper.vm.$root);
expect(rootWrapper.emitted(BV_HIDE_MODAL)).toHaveLength(1);
});
it('does not call displaySuccessfulInvitationAlert on mount', () => { it('does not call displaySuccessfulInvitationAlert on mount', () => {
expect(displaySuccessfulInvitationAlert).not.toHaveBeenCalled(); expect(displaySuccessfulInvitationAlert).not.toHaveBeenCalled();
}); });
......
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册