Commit 9a23bf3f authored by Paul Slaughter's avatar Paul Slaughter

Resolve EE/CE duplication in invite_modal_base

- https://gitlab.com/gitlab-org/gitlab/-/issues/354003
parent 90c7f9f1
...@@ -11,6 +11,7 @@ import { ...@@ -11,6 +11,7 @@ import {
GlFormInput, GlFormInput,
} from '@gitlab/ui'; } from '@gitlab/ui';
import { sprintf } from '~/locale'; import { sprintf } from '~/locale';
import ContentTransition from '~/vue_shared/components/content_transition.vue';
import { import {
ACCESS_LEVEL, ACCESS_LEVEL,
ACCESS_EXPIRE_DATE, ACCESS_EXPIRE_DATE,
...@@ -20,6 +21,17 @@ import { ...@@ -20,6 +21,17 @@ import {
HEADER_CLOSE_LABEL, HEADER_CLOSE_LABEL,
} from '../constants'; } from '../constants';
const DEFAULT_SLOT = 'default';
const DEFAULT_SLOTS = [
{
key: DEFAULT_SLOT,
attributes: {
class: 'invite-modal-content',
'data-testid': 'invite-modal-initial-content',
},
},
];
export default { export default {
components: { components: {
GlFormGroup, GlFormGroup,
...@@ -31,6 +43,7 @@ export default { ...@@ -31,6 +43,7 @@ export default {
GlSprintf, GlSprintf,
GlButton, GlButton,
GlFormInput, GlFormInput,
ContentTransition,
}, },
inheritAttrs: false, inheritAttrs: false,
props: { props: {
...@@ -86,6 +99,21 @@ export default { ...@@ -86,6 +99,21 @@ export default {
required: false, required: false,
default: '', default: '',
}, },
submitButtonText: {
type: String,
required: false,
default: INVITE_BUTTON_TEXT,
},
currentSlot: {
type: String,
required: false,
default: DEFAULT_SLOT,
},
extraSlots: {
type: Array,
required: false,
default: () => [],
},
}, },
data() { data() {
// Be sure to check out reset! // Be sure to check out reset!
...@@ -110,6 +138,9 @@ export default { ...@@ -110,6 +138,9 @@ export default {
(key) => this.accessLevels[key] === Number(this.selectedAccessLevel), (key) => this.accessLevels[key] === Number(this.selectedAccessLevel),
); );
}, },
contentSlots() {
return [...DEFAULT_SLOTS, ...(this.extraSlots || [])];
},
}, },
watch: { watch: {
selectedAccessLevel: { selectedAccessLevel: {
...@@ -148,6 +179,7 @@ export default { ...@@ -148,6 +179,7 @@ export default {
READ_MORE_TEXT, READ_MORE_TEXT,
INVITE_BUTTON_TEXT, INVITE_BUTTON_TEXT,
CANCEL_BUTTON_TEXT, CANCEL_BUTTON_TEXT,
DEFAULT_SLOT,
}; };
</script> </script>
...@@ -164,6 +196,13 @@ export default { ...@@ -164,6 +196,13 @@ export default {
@close="reset" @close="reset"
@hide="reset" @hide="reset"
> >
<content-transition
class="gl-display-grid"
transition-name="invite-modal-transition"
:slots="contentSlots"
:current-slot="currentSlot"
>
<template #[$options.DEFAULT_SLOT]>
<div class="gl-display-flex" data-testid="modal-base-intro-text"> <div class="gl-display-flex" data-testid="modal-base-intro-text">
<slot name="intro-text-before"></slot> <slot name="intro-text-before"></slot>
<p> <p>
...@@ -227,16 +266,26 @@ export default { ...@@ -227,16 +266,26 @@ export default {
:target="null" :target="null"
> >
<template #default="{ formattedDate }"> <template #default="{ formattedDate }">
<gl-form-input class="gl-w-full" :value="formattedDate" :placeholder="__(`YYYY-MM-DD`)" /> <gl-form-input
class="gl-w-full"
:value="formattedDate"
:placeholder="__(`YYYY-MM-DD`)"
/>
</template> </template>
</gl-datepicker> </gl-datepicker>
</div> </div>
<slot name="form-after"></slot> <slot name="form-after"></slot>
</template>
<template v-for="{ key } in extraSlots" #[key]>
<slot :name="key"></slot>
</template>
</content-transition>
<template #modal-footer> <template #modal-footer>
<slot name="cancel-button">
<gl-button data-testid="cancel-button" @click="closeModal"> <gl-button data-testid="cancel-button" @click="closeModal">
{{ $options.CANCEL_BUTTON_TEXT }} {{ $options.CANCEL_BUTTON_TEXT }}
</gl-button> </gl-button>
</slot>
<gl-button <gl-button
:disabled="submitDisabled" :disabled="submitDisabled"
:loading="isLoading" :loading="isLoading"
...@@ -245,7 +294,7 @@ export default { ...@@ -245,7 +294,7 @@ export default {
data-testid="invite-button" data-testid="invite-button"
@click="submit" @click="submit"
> >
{{ $options.INVITE_BUTTON_TEXT }} {{ submitButtonText }}
</gl-button> </gl-button>
</template> </template>
</gl-modal> </gl-modal>
......
<script>
export default {
props: {
currentSlot: {
type: String,
required: true,
},
slots: {
type: Array,
required: true,
},
transitionName: {
type: String,
required: true,
},
},
methods: {
shouldShow(key) {
return this.currentSlot === key;
},
},
};
</script>
<template>
<div>
<transition v-for="{ key, attributes } in slots" :key="key" :name="transitionName">
<div v-show="shouldShow(key)" v-bind="attributes">
<slot :name="key"></slot>
</div>
</transition>
</div>
</template>
import { import { GlModal, GlSprintf } from '@gitlab/ui';
GlDropdown, import { nextTick } from 'vue';
GlDropdownItem,
GlDatepicker,
GlFormGroup,
GlSprintf,
GlLink,
GlModal,
} from '@gitlab/ui';
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 InviteModalBase from 'ee_else_ce/invite_members/components/invite_modal_base.vue'; import ContentTransition from '~/vue_shared/components/content_transition.vue';
import { CANCEL_BUTTON_TEXT, INVITE_BUTTON_TEXT } from '~/invite_members/constants'; import CEInviteModalBase from '~/invite_members/components/invite_modal_base.vue';
import EEInviteModalBase from 'ee/invite_members/components/invite_modal_base.vue';
import { import {
OVERAGE_MODAL_TITLE, OVERAGE_MODAL_TITLE,
OVERAGE_MODAL_CONTINUE_BUTTON, OVERAGE_MODAL_CONTINUE_BUTTON,
...@@ -18,11 +12,12 @@ import { ...@@ -18,11 +12,12 @@ import {
} from 'ee/invite_members/constants'; } from 'ee/invite_members/constants';
import { propsData } from 'jest/invite_members/mock_data/modal_base'; import { propsData } from 'jest/invite_members/mock_data/modal_base';
describe('InviteModalBase', () => { describe('EEInviteModalBase', () => {
let wrapper; let wrapper;
let listenerSpy;
const createComponent = (props = {}, glFeatures = {}) => { const createComponent = (props = {}, glFeatures = {}) => {
wrapper = shallowMountExtended(InviteModalBase, { wrapper = shallowMountExtended(EEInviteModalBase, {
propsData: { propsData: {
...propsData, ...propsData,
...props, ...props,
...@@ -31,125 +26,103 @@ describe('InviteModalBase', () => { ...@@ -31,125 +26,103 @@ describe('InviteModalBase', () => {
...glFeatures, ...glFeatures,
}, },
stubs: { stubs: {
GlSprintf,
InviteModalBase: CEInviteModalBase,
ContentTransition,
GlModal: stubComponent(GlModal, { GlModal: stubComponent(GlModal, {
template: template:
'<div><slot name="modal-title"></slot><slot></slot><slot name="modal-footer"></slot></div>', '<div><slot name="modal-title"></slot><slot></slot><slot name="modal-footer"></slot></div>',
}), }),
GlDropdown: true, },
GlDropdownItem: true, listeners: {
GlSprintf, submit: (...args) => listenerSpy('submit', ...args),
GlFormGroup: stubComponent(GlFormGroup, { reset: (...args) => listenerSpy('reset', ...args),
props: ['state', 'invalidFeedback', 'description'], foo: (...args) => listenerSpy('foo', ...args),
}),
}, },
}); });
}; };
beforeEach(() => {
listenerSpy = jest.fn();
});
afterEach(() => { afterEach(() => {
wrapper.destroy(); wrapper.destroy();
wrapper = null; wrapper = null;
}); });
const findDropdown = () => wrapper.findComponent(GlDropdown); const findCEBase = () => wrapper.findComponent(CEInviteModalBase);
const findDropdownItems = () => findDropdown().findAllComponents(GlDropdownItem);
const findDatepicker = () => wrapper.findComponent(GlDatepicker);
const findLink = () => wrapper.findComponent(GlLink);
const findIntroText = () => wrapper.findByTestId('modal-base-intro-text').text();
const findCancelButton = () => wrapper.findByTestId('cancel-button');
const findInviteButton = () => wrapper.findByTestId('invite-button'); const findInviteButton = () => wrapper.findByTestId('invite-button');
const findBackButton = () => wrapper.findByTestId('overage-back-button'); const findBackButton = () => wrapper.findByTestId('overage-back-button');
const findOverageInviteButton = () => wrapper.findByTestId('invite-with-overage-button');
const findInitialModalContent = () => wrapper.findByTestId('invite-modal-initial-content'); const findInitialModalContent = () => wrapper.findByTestId('invite-modal-initial-content');
const findOverageModalContent = () => wrapper.findByTestId('invite-modal-overage-content'); const findOverageModalContent = () => wrapper.findByTestId('invite-modal-overage-content');
const findMembersFormGroup = () => wrapper.findByTestId('members-form-group'); const findModalTitle = () => wrapper.findComponent(GlModal).props('title');
const clickInviteButton = () => findInviteButton().vm.$emit('click'); const clickInviteButton = () => findInviteButton().vm.$emit('click');
const clickBackButton = () => findBackButton().vm.$emit('click'); const clickBackButton = () => findBackButton().vm.$emit('click');
describe('rendering the modal', () => { describe('default', () => {
beforeEach(() => { beforeEach(() => {
createComponent(); createComponent();
}); });
it('renders the modal with the correct title', () => { it('passes attrs to CE base', () => {
expect(wrapper.findComponent(GlModal).props('title')).toBe(propsData.modalTitle); expect(findCEBase().props()).toMatchObject({
}); ...propsData,
currentSlot: 'default',
it('displays the introText', () => { extraSlots: EEInviteModalBase.EXTRA_SLOTS,
expect(findIntroText()).toBe(propsData.labelIntroText);
});
it('renders the Cancel button text correctly', () => {
expect(findCancelButton().text()).toBe(CANCEL_BUTTON_TEXT);
}); });
it('renders the Invite button text correctly', () => {
expect(findInviteButton().text()).toBe(INVITE_BUTTON_TEXT);
}); });
it('renders the Invite button modal without isLoading', () => { it("doesn't show the overage content", () => {
expect(findInviteButton().props('loading')).toBe(false); expect(findOverageModalContent().isVisible()).toBe(false);
});
describe('rendering the access levels dropdown', () => {
it('sets the default dropdown text to the default access level name', () => {
expect(findDropdown().attributes('text')).toBe('Guest');
}); });
it('renders dropdown items for each accessLevel', () => { it('when reset is emitted on base, emits reset', () => {
expect(findDropdownItems()).toHaveLength(5); expect(wrapper.emitted('reset')).toBeUndefined();
});
});
it('renders the correct link', () => { findCEBase().vm.$emit('reset');
expect(findLink().attributes('href')).toBe(propsData.helpLink);
});
it('renders the datepicker', () => { expect(wrapper.emitted('reset')).toHaveLength(1);
expect(findDatepicker().exists()).toBe(true);
}); });
it("doesn't show the overage content", () => { describe('(integration) when invite is clicked', () => {
expect(findOverageModalContent().isVisible()).toBe(false); beforeEach(async () => {
clickInviteButton();
await nextTick();
}); });
it('renders the members form group', () => { it('does not change title', () => {
expect(findMembersFormGroup().props()).toEqual({ expect(findModalTitle()).toBe(propsData.modalTitle);
description: propsData.formGroupDescription,
invalidFeedback: '',
state: null,
});
});
}); });
it('with isLoading, shows loading for invite button', () => { it('does not show back button', () => {
createComponent({ expect(findBackButton().exists()).toBe(false);
isLoading: true,
}); });
expect(findInviteButton().props('loading')).toBe(true); it('shows initial modal content', () => {
expect(findInitialModalContent().isVisible()).toBe(true);
}); });
it('with invalidFeedbackMessage, set members form group validation state', () => { it('emits submit', () => {
createComponent({ expect(wrapper.emitted('submit')).toEqual([[{ accessLevel: 10, expiresAt: undefined }]]);
invalidFeedbackMessage: 'invalid message!',
}); });
expect(findMembersFormGroup().props()).toEqual({
description: propsData.formGroupDescription,
invalidFeedback: 'invalid message!',
state: false,
}); });
}); });
describe('displays overage modal', () => { describe('with overageMembersModal feature flag, and invite is clicked ', () => {
beforeEach(() => { beforeEach(async () => {
createComponent({}, { glFeatures: { overageMembersModal: true } }); createComponent({}, { glFeatures: { overageMembersModal: true } });
clickInviteButton(); clickInviteButton();
await nextTick();
});
it('does not emit submit', () => {
expect(wrapper.emitted().submit).toBeUndefined();
}); });
it('renders the modal with the correct title', () => { it('renders the modal with the correct title', () => {
expect(wrapper.findComponent(GlModal).props('title')).toBe(OVERAGE_MODAL_TITLE); expect(findModalTitle()).toBe(OVERAGE_MODAL_TITLE);
}); });
it('renders the Back button text correctly', () => { it('renders the Back button text correctly', () => {
...@@ -157,7 +130,7 @@ describe('InviteModalBase', () => { ...@@ -157,7 +130,7 @@ describe('InviteModalBase', () => {
}); });
it('renders the Continue button text correctly', () => { it('renders the Continue button text correctly', () => {
expect(findOverageInviteButton().text()).toBe(OVERAGE_MODAL_CONTINUE_BUTTON); expect(findInviteButton().text()).toBe(OVERAGE_MODAL_CONTINUE_BUTTON);
}); });
it('shows the info text', () => { it('shows the info text', () => {
...@@ -174,7 +147,7 @@ describe('InviteModalBase', () => { ...@@ -174,7 +147,7 @@ describe('InviteModalBase', () => {
beforeEach(() => clickBackButton()); beforeEach(() => clickBackButton());
it('shows the initial modal', () => { it('shows the initial modal', () => {
expect(wrapper.findComponent(GlModal).props('title')).toBe('_modal_title_'); expect(wrapper.findComponent(GlModal).props('title')).toBe(propsData.modalTitle);
expect(findInitialModalContent().isVisible()).toBe(true); expect(findInitialModalContent().isVisible()).toBe(true);
}); });
......
...@@ -4,6 +4,7 @@ import { shallowMountExtended } from 'helpers/vue_test_utils_helper'; ...@@ -4,6 +4,7 @@ import { shallowMountExtended } from 'helpers/vue_test_utils_helper';
import Api from '~/api'; import Api from '~/api';
import InviteGroupsModal from '~/invite_members/components/invite_groups_modal.vue'; import InviteGroupsModal from '~/invite_members/components/invite_groups_modal.vue';
import InviteModalBase from '~/invite_members/components/invite_modal_base.vue'; import InviteModalBase from '~/invite_members/components/invite_modal_base.vue';
import ContentTransition from '~/vue_shared/components/content_transition.vue';
import GroupSelect from '~/invite_members/components/group_select.vue'; import GroupSelect from '~/invite_members/components/group_select.vue';
import { stubComponent } from 'helpers/stub_component'; import { stubComponent } from 'helpers/stub_component';
import { propsData, sharedGroup } from '../mock_data/group_modal'; import { propsData, sharedGroup } from '../mock_data/group_modal';
...@@ -19,6 +20,7 @@ describe('InviteGroupsModal', () => { ...@@ -19,6 +20,7 @@ describe('InviteGroupsModal', () => {
}, },
stubs: { stubs: {
InviteModalBase, InviteModalBase,
ContentTransition,
GlSprintf, GlSprintf,
GlModal: stubComponent(GlModal, { GlModal: stubComponent(GlModal, {
template: '<div><slot></slot><slot name="modal-footer"></slot></div>', template: '<div><slot></slot><slot name="modal-footer"></slot></div>',
......
...@@ -19,6 +19,7 @@ import { ...@@ -19,6 +19,7 @@ import {
LEARN_GITLAB, LEARN_GITLAB,
} from '~/invite_members/constants'; } from '~/invite_members/constants';
import eventHub from '~/invite_members/event_hub'; import eventHub from '~/invite_members/event_hub';
import ContentTransition from '~/vue_shared/components/content_transition.vue';
import axios from '~/lib/utils/axios_utils'; import axios from '~/lib/utils/axios_utils';
import httpStatus from '~/lib/utils/http_status'; import httpStatus from '~/lib/utils/http_status';
import { getParameterValues } from '~/lib/utils/url_utility'; import { getParameterValues } from '~/lib/utils/url_utility';
...@@ -55,6 +56,7 @@ describe('InviteMembersModal', () => { ...@@ -55,6 +56,7 @@ describe('InviteMembersModal', () => {
}, },
stubs: { stubs: {
InviteModalBase, InviteModalBase,
ContentTransition,
GlSprintf, GlSprintf,
GlModal: stubComponent(GlModal, { GlModal: stubComponent(GlModal, {
template: '<div><slot></slot><slot name="modal-footer"></slot></div>', template: '<div><slot></slot><slot name="modal-footer"></slot></div>',
......
...@@ -10,6 +10,7 @@ import { ...@@ -10,6 +10,7 @@ import {
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 InviteModalBase from '~/invite_members/components/invite_modal_base.vue'; import InviteModalBase from '~/invite_members/components/invite_modal_base.vue';
import ContentTransition from '~/vue_shared/components/content_transition.vue';
import { CANCEL_BUTTON_TEXT, INVITE_BUTTON_TEXT } from '~/invite_members/constants'; import { CANCEL_BUTTON_TEXT, INVITE_BUTTON_TEXT } from '~/invite_members/constants';
import { propsData } from '../mock_data/modal_base'; import { propsData } from '../mock_data/modal_base';
...@@ -23,6 +24,7 @@ describe('InviteModalBase', () => { ...@@ -23,6 +24,7 @@ describe('InviteModalBase', () => {
...props, ...props,
}, },
stubs: { stubs: {
ContentTransition,
GlModal: stubComponent(GlModal, { GlModal: stubComponent(GlModal, {
template: template:
'<div><slot name="modal-title"></slot><slot></slot><slot name="modal-footer"></slot></div>', '<div><slot name="modal-title"></slot><slot></slot><slot name="modal-footer"></slot></div>',
......
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