diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-08-12 03:10:38 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-08-12 03:10:38 +0300 |
commit | e57da6ba898df025f93bf8d3a896c7c2ba2ab830 (patch) | |
tree | 0eb1feedb28db1bbf9a695aae76b025a65105404 /spec/frontend/invite_members/components | |
parent | 23790cda2b4145294d71591515acfe892d4c99a7 (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/group_select_spec.js | 46 |
1 files changed, 40 insertions, 6 deletions
diff --git a/spec/frontend/invite_members/components/group_select_spec.js b/spec/frontend/invite_members/components/group_select_spec.js index bd90832f497..60501bfbd6a 100644 --- a/spec/frontend/invite_members/components/group_select_spec.js +++ b/spec/frontend/invite_members/components/group_select_spec.js @@ -1,6 +1,7 @@ import { nextTick } from 'vue'; import { GlAvatarLabeled, GlCollapsibleListbox } from '@gitlab/ui'; import { mount } from '@vue/test-utils'; +import axios from 'axios'; import waitForPromises from 'helpers/wait_for_promises'; import { getGroups } from '~/api/groups_api'; import GroupSelect from '~/invite_members/components/group_select.vue'; @@ -49,16 +50,23 @@ describe('GroupSelect', () => { await waitForPromises(); getGroups.mockClear(); getGroups.mockReturnValueOnce(new Promise(() => {})); - findListbox().vm.$emit('search', group1.name); + findListbox().vm.$emit('search', group1.full_name); await nextTick(); }); it('calls the API', () => { - expect(getGroups).toHaveBeenCalledWith(group1.name, { - exclude_internal: true, - active: true, - order_by: 'similarity', - }); + expect(getGroups).toHaveBeenCalledWith( + group1.full_name, + { + exclude_internal: true, + active: true, + order_by: 'similarity', + }, + undefined, + { + signal: expect.any(AbortSignal), + }, + ); }); it('displays loading icon while waiting for API call to resolve', () => { @@ -182,7 +190,33 @@ describe('GroupSelect', () => { expect(wrapper.emitted('error')).toEqual([[GroupSelect.i18n.errorMessage]]); }); + + it('does not emit `error` event if error is from request cancellation', async () => { + createComponent(); + await waitForPromises(); + + getGroups.mockRejectedValueOnce(new axios.Cancel()); + + findListbox().vm.$emit('bottom-reached'); + await waitForPromises(); + + expect(wrapper.emitted('error')).toEqual(undefined); + }); }); }); }); + + describe('when multiple API calls are in-flight', () => { + it('aborts the first API call and resolves second API call', async () => { + const abortSpy = jest.spyOn(AbortController.prototype, 'abort'); + + createComponent(); + await waitForPromises(); + + findListbox().vm.$emit('search', group1.full_name); + + expect(abortSpy).toHaveBeenCalledTimes(1); + expect(wrapper.emitted('error')).toEqual(undefined); + }); + }); }); |