diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-10-13 00:10:53 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-10-13 00:10:53 +0300 |
commit | 74cb1a1df361969e97d1a85683c1dfca5ac8cad1 (patch) | |
tree | ae688dc2ce754a5115b39d7fad5d171883e723f5 /spec/frontend/invite_members/components | |
parent | 50b113507b3b03bdce4753ba3ff3ffb53d21f756 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/frontend/invite_members/components')
-rw-r--r-- | spec/frontend/invite_members/components/invite_members_modal_spec.js | 64 |
1 files changed, 43 insertions, 21 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 d4fbf54c640..cfc2fd65cc1 100644 --- a/spec/frontend/invite_members/components/invite_members_modal_spec.js +++ b/spec/frontend/invite_members/components/invite_members_modal_spec.js @@ -132,10 +132,10 @@ describe('InviteMembersModal', () => { const findUserLimitAlert = () => wrapper.findComponent(UserLimitNotification); const findAccordion = () => wrapper.findComponent(GlCollapse); const findErrorsIcon = () => wrapper.findComponent(GlIcon); - const findMemberErrorMessage = (element) => - `${Object.keys(invitationsApiResponse.EXPANDED_RESTRICTED.message)[element]}: ${ - Object.values(invitationsApiResponse.EXPANDED_RESTRICTED.message)[element] - }`; + const expectedErrorMessage = (index, errorType) => { + const [username, message] = Object.entries(errorType.parsedMessage)[index]; + return `${username}: ${message}`; + }; const findActionButton = () => wrapper.findByTestId('invite-modal-submit'); const findCancelButton = () => wrapper.findByTestId('invite-modal-cancel'); @@ -317,8 +317,6 @@ describe('InviteMembersModal', () => { mock.onPost(GROUPS_INVITATIONS_PATH).reply(code, data); }; - const expectedEmailRestrictedError = - "The member's email address is not allowed for this project. Go to the Admin area > Sign-up restrictions, and check Allowed domains for sign-ups."; const expectedSyntaxError = 'email contains an invalid email address'; describe('when no invites have been entered in the form and then some are entered', () => { @@ -467,12 +465,16 @@ describe('InviteMembersModal', () => { it('displays the restricted user api message for response with bad request', async () => { mockInvitationsApi(HTTP_STATUS_CREATED, invitationsApiResponse.EMAIL_RESTRICTED); + await triggerMembersTokenSelect([user3]); + clickInviteButton(); await waitForPromises(); expect(findMemberErrorAlert().exists()).toBe(true); - expect(findMemberErrorAlert().text()).toContain(expectedEmailRestrictedError); + expect(findMemberErrorAlert().text()).toContain( + expectedErrorMessage(0, invitationsApiResponse.EMAIL_RESTRICTED), + ); expect(membersFormGroupInvalidFeedback()).toBe(''); expect(findMembersSelect().props('exceptionState')).not.toBe(false); }); @@ -480,19 +482,21 @@ describe('InviteMembersModal', () => { it('displays all errors when there are multiple existing users that are restricted by email', async () => { mockInvitationsApi(HTTP_STATUS_CREATED, invitationsApiResponse.MULTIPLE_RESTRICTED); + await triggerMembersTokenSelect([user3, user4, user5]); + clickInviteButton(); await waitForPromises(); expect(findMemberErrorAlert().exists()).toBe(true); expect(findMemberErrorAlert().text()).toContain( - Object.values(invitationsApiResponse.MULTIPLE_RESTRICTED.message)[0], + expectedErrorMessage(0, invitationsApiResponse.MULTIPLE_RESTRICTED), ); expect(findMemberErrorAlert().text()).toContain( - Object.values(invitationsApiResponse.MULTIPLE_RESTRICTED.message)[1], + expectedErrorMessage(1, invitationsApiResponse.MULTIPLE_RESTRICTED), ); expect(findMemberErrorAlert().text()).toContain( - Object.values(invitationsApiResponse.MULTIPLE_RESTRICTED.message)[2], + expectedErrorMessage(2, invitationsApiResponse.MULTIPLE_RESTRICTED), ); expect(membersFormGroupInvalidFeedback()).toBe(''); expect(findMembersSelect().props('exceptionState')).not.toBe(false); @@ -612,7 +616,9 @@ describe('InviteMembersModal', () => { await waitForPromises(); expect(findMemberErrorAlert().exists()).toBe(true); - expect(findMemberErrorAlert().text()).toContain(expectedEmailRestrictedError); + expect(findMemberErrorAlert().text()).toContain( + expectedErrorMessage(0, invitationsApiResponse.EMAIL_RESTRICTED), + ); expect(membersFormGroupInvalidFeedback()).toBe(''); expect(findMembersSelect().props('exceptionState')).not.toBe(false); expect(findActionButton().props('loading')).toBe(false); @@ -621,19 +627,21 @@ describe('InviteMembersModal', () => { it('displays all errors when there are multiple emails that return a restricted error message', async () => { mockInvitationsApi(HTTP_STATUS_CREATED, invitationsApiResponse.MULTIPLE_RESTRICTED); + await triggerMembersTokenSelect([user3, user4, user5]); + clickInviteButton(); await waitForPromises(); expect(findMemberErrorAlert().exists()).toBe(true); expect(findMemberErrorAlert().text()).toContain( - Object.values(invitationsApiResponse.MULTIPLE_RESTRICTED.message)[0], + expectedErrorMessage(0, invitationsApiResponse.MULTIPLE_RESTRICTED), ); expect(findMemberErrorAlert().text()).toContain( - Object.values(invitationsApiResponse.MULTIPLE_RESTRICTED.message)[1], + expectedErrorMessage(1, invitationsApiResponse.MULTIPLE_RESTRICTED), ); expect(findMemberErrorAlert().text()).toContain( - Object.values(invitationsApiResponse.MULTIPLE_RESTRICTED.message)[2], + expectedErrorMessage(2, invitationsApiResponse.MULTIPLE_RESTRICTED), ); expect(membersFormGroupInvalidFeedback()).toBe(''); expect(findMembersSelect().props('exceptionState')).not.toBe(false); @@ -689,10 +697,18 @@ describe('InviteMembersModal', () => { expect(findMemberErrorAlert().props('title')).toContain( "The following 4 members couldn't be invited", ); - expect(findMemberErrorAlert().text()).toContain(findMemberErrorMessage(0)); - expect(findMemberErrorAlert().text()).toContain(findMemberErrorMessage(1)); - expect(findMemberErrorAlert().text()).toContain(findMemberErrorMessage(2)); - expect(findMemberErrorAlert().text()).toContain(findMemberErrorMessage(3)); + expect(findMemberErrorAlert().text()).toContain( + expectedErrorMessage(0, invitationsApiResponse.EXPANDED_RESTRICTED), + ); + expect(findMemberErrorAlert().text()).toContain( + expectedErrorMessage(1, invitationsApiResponse.EXPANDED_RESTRICTED), + ); + expect(findMemberErrorAlert().text()).toContain( + expectedErrorMessage(2, invitationsApiResponse.EXPANDED_RESTRICTED), + ); + expect(findMemberErrorAlert().text()).toContain( + expectedErrorMessage(3, invitationsApiResponse.EXPANDED_RESTRICTED), + ); expect(findAccordion().exists()).toBe(true); expect(findMoreInviteErrorsButton().text()).toContain('Show more (2)'); expect(findErrorsIcon().attributes('class')).not.toContain('gl-rotate-180'); @@ -715,7 +731,9 @@ describe('InviteMembersModal', () => { expect(findMemberErrorAlert().props('title')).toContain( "The following 3 members couldn't be invited", ); - expect(findMemberErrorAlert().text()).not.toContain(findMemberErrorMessage(0)); + expect(findMemberErrorAlert().text()).not.toContain( + expectedErrorMessage(0, invitationsApiResponse.EXPANDED_RESTRICTED), + ); await removeMembersToken(user6); @@ -723,14 +741,18 @@ describe('InviteMembersModal', () => { expect(findMemberErrorAlert().props('title')).toContain( "The following 2 members couldn't be invited", ); - expect(findMemberErrorAlert().text()).not.toContain(findMemberErrorMessage(2)); + expect(findMemberErrorAlert().text()).not.toContain( + expectedErrorMessage(2, invitationsApiResponse.EXPANDED_RESTRICTED), + ); await removeMembersToken(user4); expect(findMemberErrorAlert().props('title')).toContain( "The following member couldn't be invited", ); - expect(findMemberErrorAlert().text()).not.toContain(findMemberErrorMessage(1)); + expect(findMemberErrorAlert().text()).not.toContain( + expectedErrorMessage(1, invitationsApiResponse.EXPANDED_RESTRICTED), + ); await removeMembersToken(user5); |