diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-04-20 13:00:54 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-04-20 13:00:54 +0300 |
commit | 3cccd102ba543e02725d247893729e5c73b38295 (patch) | |
tree | f36a04ec38517f5deaaacb5acc7d949688d1e187 /spec/frontend/invite_members/components/invite_members_modal_spec.js | |
parent | 205943281328046ef7b4528031b90fbda70c75ac (diff) |
Add latest changes from gitlab-org/gitlab@14-10-stable-eev14.10.0-rc42
Diffstat (limited to 'spec/frontend/invite_members/components/invite_members_modal_spec.js')
-rw-r--r-- | spec/frontend/invite_members/components/invite_members_modal_spec.js | 131 |
1 files changed, 42 insertions, 89 deletions
diff --git a/spec/frontend/invite_members/components/invite_members_modal_spec.js b/spec/frontend/invite_members/components/invite_members_modal_spec.js index dd16bb48cb8..84317da39e6 100644 --- a/spec/frontend/invite_members/components/invite_members_modal_spec.js +++ b/spec/frontend/invite_members/components/invite_members_modal_spec.js @@ -23,7 +23,7 @@ import ContentTransition from '~/vue_shared/components/content_transition.vue'; import axios from '~/lib/utils/axios_utils'; import httpStatus from '~/lib/utils/http_status'; import { getParameterValues } from '~/lib/utils/url_utility'; -import { apiPaths, membersApiResponse, invitationsApiResponse } from '../mock_data/api_responses'; +import { GROUPS_INVITATIONS_PATH, invitationsApiResponse } from '../mock_data/api_responses'; import { propsData, inviteSource, @@ -85,12 +85,13 @@ describe('InviteMembersModal', () => { mock.restore(); }); + const findModal = () => wrapper.findComponent(GlModal); const findBase = () => wrapper.findComponent(InviteModalBase); const findIntroText = () => wrapper.findByTestId('modal-base-intro-text').text(); - const findCancelButton = () => wrapper.findByTestId('cancel-button'); - const findInviteButton = () => wrapper.findByTestId('invite-button'); - const clickInviteButton = () => findInviteButton().vm.$emit('click'); - const clickCancelButton = () => findCancelButton().vm.$emit('click'); + const emitEventFromModal = (eventName) => () => + findModal().vm.$emit(eventName, { preventDefault: jest.fn() }); + const clickInviteButton = emitEventFromModal('primary'); + const clickCancelButton = emitEventFromModal('cancel'); const findMembersFormGroup = () => wrapper.findByTestId('members-form-group'); const membersFormGroupInvalidFeedback = () => findMembersFormGroup().attributes('invalid-feedback'); @@ -276,7 +277,7 @@ describe('InviteMembersModal', () => { }); it('renders the modal with the correct title', () => { - expect(wrapper.findComponent(GlModal).props('title')).toBe(MEMBERS_MODAL_CELEBRATE_TITLE); + expect(findModal().props('title')).toBe(MEMBERS_MODAL_CELEBRATE_TITLE); }); it('includes the correct celebration text and emoji', () => { @@ -300,11 +301,8 @@ describe('InviteMembersModal', () => { }); describe('submitting the invite form', () => { - const mockMembersApi = (code, data) => { - mock.onPost(apiPaths.GROUPS_MEMBERS).reply(code, data); - }; const mockInvitationsApi = (code, data) => { - mock.onPost(apiPaths.GROUPS_INVITATIONS).reply(code, data); + mock.onPost(GROUPS_INVITATIONS_PATH).reply(code, data); }; const expectedEmailRestrictedError = @@ -328,7 +326,7 @@ describe('InviteMembersModal', () => { await triggerMembersTokenSelect([user1, user2]); wrapper.vm.$toast = { show: jest.fn() }; - jest.spyOn(Api, 'addGroupMembersByUserId').mockResolvedValue({ data: postData }); + jest.spyOn(Api, 'inviteGroupMembers').mockResolvedValue({ data: postData }); }); describe('when triggered from regular mounting', () => { @@ -336,12 +334,8 @@ describe('InviteMembersModal', () => { clickInviteButton(); }); - it('sets isLoading on the Invite button when it is clicked', () => { - expect(findInviteButton().props('loading')).toBe(true); - }); - - it('calls Api addGroupMembersByUserId with the correct params', () => { - expect(Api.addGroupMembersByUserId).toHaveBeenCalledWith(propsData.id, postData); + it('calls Api inviteGroupMembers with the correct params', () => { + expect(Api.inviteGroupMembers).toHaveBeenCalledWith(propsData.id, postData); }); it('displays the successful toastMessage', () => { @@ -371,21 +365,9 @@ describe('InviteMembersModal', () => { await triggerMembersTokenSelect([user1]); }); - it('displays "Member already exists" api message for http status conflict', async () => { - mockMembersApi(httpStatus.CONFLICT, membersApiResponse.MEMBER_ALREADY_EXISTS); - - clickInviteButton(); - - await waitForPromises(); - - expect(membersFormGroupInvalidFeedback()).toBe('Member already exists'); - expect(findMembersSelect().props('validationState')).toBe(false); - expect(findInviteButton().props('loading')).toBe(false); - }); - describe('clearing the invalid state and message', () => { beforeEach(async () => { - mockMembersApi(httpStatus.CONFLICT, membersApiResponse.MEMBER_ALREADY_EXISTS); + mockInvitationsApi(httpStatus.CREATED, invitationsApiResponse.EMAIL_TAKEN); clickInviteButton(); @@ -393,7 +375,9 @@ describe('InviteMembersModal', () => { }); it('clears the error when the list of members to invite is cleared', async () => { - expect(membersFormGroupInvalidFeedback()).toBe('Member already exists'); + expect(membersFormGroupInvalidFeedback()).toBe( + Object.values(invitationsApiResponse.EMAIL_TAKEN.message)[0], + ); expect(findMembersSelect().props('validationState')).toBe(false); findMembersSelect().vm.$emit('clear'); @@ -414,7 +398,7 @@ describe('InviteMembersModal', () => { }); it('clears the error when the modal is hidden', async () => { - wrapper.findComponent(GlModal).vm.$emit('hide'); + findModal().vm.$emit('hidden'); await nextTick(); @@ -424,15 +408,17 @@ describe('InviteMembersModal', () => { }); it('clears the invalid state and message once the list of members to invite is cleared', async () => { - mockMembersApi(httpStatus.CONFLICT, membersApiResponse.MEMBER_ALREADY_EXISTS); + mockInvitationsApi(httpStatus.CREATED, invitationsApiResponse.EMAIL_TAKEN); clickInviteButton(); await waitForPromises(); - expect(membersFormGroupInvalidFeedback()).toBe('Member already exists'); + expect(membersFormGroupInvalidFeedback()).toBe( + Object.values(invitationsApiResponse.EMAIL_TAKEN.message)[0], + ); expect(findMembersSelect().props('validationState')).toBe(false); - expect(findInviteButton().props('loading')).toBe(false); + expect(findModal().props('actionPrimary').attributes.loading).toBe(false); findMembersSelect().vm.$emit('clear'); @@ -440,11 +426,14 @@ describe('InviteMembersModal', () => { expect(membersFormGroupInvalidFeedback()).toBe(''); expect(findMembersSelect().props('validationState')).toBe(null); - expect(findInviteButton().props('loading')).toBe(false); + expect(findModal().props('actionPrimary').attributes.loading).toBe(false); }); it('displays the generic error for http server error', async () => { - mockMembersApi(httpStatus.INTERNAL_SERVER_ERROR, 'Request failed with status code 500'); + mockInvitationsApi( + httpStatus.INTERNAL_SERVER_ERROR, + 'Request failed with status code 500', + ); clickInviteButton(); @@ -454,7 +443,7 @@ describe('InviteMembersModal', () => { }); it('displays the restricted user api message for response with bad request', async () => { - mockMembersApi(httpStatus.BAD_REQUEST, membersApiResponse.SINGLE_USER_RESTRICTED); + mockInvitationsApi(httpStatus.CREATED, invitationsApiResponse.EMAIL_RESTRICTED); clickInviteButton(); @@ -464,7 +453,7 @@ describe('InviteMembersModal', () => { }); it('displays the first part of the error when multiple existing users are restricted by email', async () => { - mockMembersApi(httpStatus.CREATED, membersApiResponse.MULTIPLE_USERS_RESTRICTED); + mockInvitationsApi(httpStatus.CREATED, invitationsApiResponse.MULTIPLE_RESTRICTED); clickInviteButton(); @@ -475,19 +464,6 @@ describe('InviteMembersModal', () => { ); expect(findMembersSelect().props('validationState')).toBe(false); }); - - it('displays an access_level error message received for the existing user', async () => { - mockMembersApi(httpStatus.BAD_REQUEST, membersApiResponse.SINGLE_USER_ACCESS_LEVEL); - - clickInviteButton(); - - await waitForPromises(); - - expect(membersFormGroupInvalidFeedback()).toBe( - 'should be greater than or equal to Owner inherited membership from group Gitlab Org', - ); - expect(findMembersSelect().props('validationState')).toBe(false); - }); }); }); @@ -508,7 +484,7 @@ describe('InviteMembersModal', () => { await triggerMembersTokenSelect([user3]); wrapper.vm.$toast = { show: jest.fn() }; - jest.spyOn(Api, 'inviteGroupMembersByEmail').mockResolvedValue({ data: postData }); + jest.spyOn(Api, 'inviteGroupMembers').mockResolvedValue({ data: postData }); }); describe('when triggered from regular mounting', () => { @@ -516,8 +492,8 @@ describe('InviteMembersModal', () => { clickInviteButton(); }); - it('calls Api inviteGroupMembersByEmail with the correct params', () => { - expect(Api.inviteGroupMembersByEmail).toHaveBeenCalledWith(propsData.id, postData); + it('calls Api inviteGroupMembers with the correct params', () => { + expect(Api.inviteGroupMembers).toHaveBeenCalledWith(propsData.id, postData); }); it('displays the successful toastMessage', () => { @@ -542,7 +518,7 @@ describe('InviteMembersModal', () => { expect(membersFormGroupInvalidFeedback()).toBe(expectedSyntaxError); expect(findMembersSelect().props('validationState')).toBe(false); - expect(findInviteButton().props('loading')).toBe(false); + expect(findModal().props('actionPrimary').attributes.loading).toBe(false); }); it('displays the restricted email error when restricted email is invited', async () => { @@ -554,23 +530,11 @@ describe('InviteMembersModal', () => { expect(membersFormGroupInvalidFeedback()).toContain(expectedEmailRestrictedError); expect(findMembersSelect().props('validationState')).toBe(false); - expect(findInviteButton().props('loading')).toBe(false); - }); - - it('displays the successful toast message when email has already been invited', async () => { - mockInvitationsApi(httpStatus.CREATED, invitationsApiResponse.EMAIL_TAKEN); - wrapper.vm.$toast = { show: jest.fn() }; - - clickInviteButton(); - - await waitForPromises(); - - expect(wrapper.vm.$toast.show).toHaveBeenCalledWith('Members were successfully added'); - expect(findMembersSelect().props('validationState')).toBe(null); + expect(findModal().props('actionPrimary').attributes.loading).toBe(false); }); it('displays the first error message when multiple emails return a restricted error message', async () => { - mockInvitationsApi(httpStatus.CREATED, invitationsApiResponse.MULTIPLE_EMAIL_RESTRICTED); + mockInvitationsApi(httpStatus.CREATED, invitationsApiResponse.MULTIPLE_RESTRICTED); clickInviteButton(); @@ -617,19 +581,17 @@ describe('InviteMembersModal', () => { format: 'json', tasks_to_be_done: [], tasks_project_id: '', + user_id: '1', + email: 'email@example.com', }; - const emailPostData = { ...postData, email: 'email@example.com' }; - const idPostData = { ...postData, user_id: '1' }; - describe('when invites are sent successfully', () => { beforeEach(async () => { createComponent(); await triggerMembersTokenSelect([user1, user3]); wrapper.vm.$toast = { show: jest.fn() }; - jest.spyOn(Api, 'inviteGroupMembersByEmail').mockResolvedValue({ data: postData }); - jest.spyOn(Api, 'addGroupMembersByUserId').mockResolvedValue({ data: postData }); + jest.spyOn(Api, 'inviteGroupMembers').mockResolvedValue({ data: postData }); }); describe('when triggered from regular mounting', () => { @@ -637,12 +599,8 @@ describe('InviteMembersModal', () => { clickInviteButton(); }); - it('calls Api inviteGroupMembersByEmail with the correct params', () => { - expect(Api.inviteGroupMembersByEmail).toHaveBeenCalledWith(propsData.id, emailPostData); - }); - - it('calls Api addGroupMembersByUserId with the correct params', () => { - expect(Api.addGroupMembersByUserId).toHaveBeenCalledWith(propsData.id, idPostData); + it('calls Api inviteGroupMembers with the correct params', () => { + expect(Api.inviteGroupMembers).toHaveBeenCalledWith(propsData.id, postData); }); it('displays the successful toastMessage', () => { @@ -655,12 +613,8 @@ describe('InviteMembersModal', () => { clickInviteButton(); - expect(Api.inviteGroupMembersByEmail).toHaveBeenCalledWith(propsData.id, { - ...emailPostData, - invite_source: '_invite_source_', - }); - expect(Api.addGroupMembersByUserId).toHaveBeenCalledWith(propsData.id, { - ...idPostData, + expect(Api.inviteGroupMembers).toHaveBeenCalledWith(propsData.id, { + ...postData, invite_source: '_invite_source_', }); }); @@ -673,7 +627,6 @@ describe('InviteMembersModal', () => { await triggerMembersTokenSelect([user1, user3]); mockInvitationsApi(httpStatus.BAD_REQUEST, invitationsApiResponse.EMAIL_INVALID); - mockMembersApi(httpStatus.OK, '200 OK'); clickInviteButton(); }); @@ -692,7 +645,7 @@ describe('InviteMembersModal', () => { await triggerMembersTokenSelect([user3]); wrapper.vm.$toast = { show: jest.fn() }; - jest.spyOn(Api, 'inviteGroupMembersByEmail').mockResolvedValue({}); + jest.spyOn(Api, 'inviteGroupMembers').mockResolvedValue({}); }); it('tracks the view for learn_gitlab source', () => { |