diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-05-04 21:09:51 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-05-04 21:09:51 +0300 |
commit | bd979acf95124119d41f75d34cab231229f4dd81 (patch) | |
tree | a7ce5127c8ab6d42b27aa8342889c54d2f0090b2 /spec/frontend/invite_members/components | |
parent | 4bdfcf93f224edb9c4daff90d95b0c6c92766ea3 (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 | 121 | ||||
-rw-r--r-- | spec/frontend/invite_members/components/invite_groups_modal_spec.js | 12 |
2 files changed, 97 insertions, 36 deletions
diff --git a/spec/frontend/invite_members/components/group_select_spec.js b/spec/frontend/invite_members/components/group_select_spec.js index a1ca9a69926..e7011f896b6 100644 --- a/spec/frontend/invite_members/components/group_select_spec.js +++ b/spec/frontend/invite_members/components/group_select_spec.js @@ -2,28 +2,29 @@ import { GlAvatarLabeled, GlDropdown, GlSearchBoxByType } from '@gitlab/ui'; import { mount } from '@vue/test-utils'; import waitForPromises from 'helpers/wait_for_promises'; import * as groupsApi from '~/api/groups_api'; +import * as projectsApi from '~/api/projects_api'; import GroupSelect from '~/invite_members/components/group_select.vue'; const group1 = { id: 1, full_name: 'Group One', avatar_url: 'test' }; const group2 = { id: 2, full_name: 'Group Two', avatar_url: 'test' }; const allGroups = [group1, group2]; -const createComponent = (props = {}) => { - return mount(GroupSelect, { - propsData: { - invalidGroups: [], - ...props, - }, - }); -}; - describe('GroupSelect', () => { let wrapper; + const createComponent = (props = {}) => { + wrapper = mount(GroupSelect, { + propsData: { + invalidGroups: [], + sourceId: '1', + isProject: false, + ...props, + }, + }); + }; + beforeEach(() => { jest.spyOn(groupsApi, 'getGroups').mockResolvedValue(allGroups); - - wrapper = createComponent(); }); const findSearchBoxByType = () => wrapper.findComponent(GlSearchBoxByType); @@ -35,48 +36,93 @@ describe('GroupSelect', () => { .wrappers.find((dropdownItemWrapper) => dropdownItemWrapper.props('label') === text); it('renders GlSearchBoxByType with default attributes', () => { + createComponent(); + expect(findSearchBoxByType().exists()).toBe(true); expect(findSearchBoxByType().vm.$attrs).toMatchObject({ placeholder: 'Search groups', }); }); - describe('when user types in the search input', () => { - let resolveApiRequest; + describe('when `isProject` prop is `false`', () => { + describe('when user types in the search input', () => { + let resolveApiRequest; - beforeEach(() => { - jest.spyOn(groupsApi, 'getGroups').mockImplementation( - () => - new Promise((resolve) => { - resolveApiRequest = resolve; - }), - ); + beforeEach(() => { + jest.spyOn(groupsApi, 'getGroups').mockImplementation( + () => + new Promise((resolve) => { + resolveApiRequest = resolve; + }), + ); - findSearchBoxByType().vm.$emit('input', group1.name); - }); + createComponent(); - it('calls the API', () => { - resolveApiRequest({ data: allGroups }); + findSearchBoxByType().vm.$emit('input', group1.name); + }); + + it('calls the API', () => { + resolveApiRequest(allGroups); - expect(groupsApi.getGroups).toHaveBeenCalledWith(group1.name, { - exclude_internal: true, - active: true, - order_by: 'similarity', + expect(groupsApi.getGroups).toHaveBeenCalledWith(group1.name, { + exclude_internal: true, + active: true, + order_by: 'similarity', + }); + }); + + it('displays loading icon while waiting for API call to resolve', async () => { + expect(findSearchBoxByType().props('isLoading')).toBe(true); + + resolveApiRequest(allGroups); + await waitForPromises(); + + expect(findSearchBoxByType().props('isLoading')).toBe(false); }); }); + }); - it('displays loading icon while waiting for API call to resolve', async () => { - expect(findSearchBoxByType().props('isLoading')).toBe(true); + describe('when `isProject` prop is `true`', () => { + describe('when user types in the search input', () => { + let resolveApiRequest; - resolveApiRequest({ data: allGroups }); - await waitForPromises(); + beforeEach(() => { + jest.spyOn(projectsApi, 'getProjectShareLocations').mockImplementation( + () => + new Promise((resolve) => { + resolveApiRequest = resolve; + }), + ); + + createComponent({ isProject: true }); + + findSearchBoxByType().vm.$emit('input', group1.name); + }); + + it('calls the API', () => { + resolveApiRequest({ data: allGroups }); + + expect(projectsApi.getProjectShareLocations).toHaveBeenCalledWith('1', { + search: group1.name, + }); + }); - expect(findSearchBoxByType().props('isLoading')).toBe(false); + it('displays loading icon while waiting for API call to resolve', async () => { + expect(findSearchBoxByType().props('isLoading')).toBe(true); + + resolveApiRequest({ data: allGroups }); + await waitForPromises(); + + expect(findSearchBoxByType().props('isLoading')).toBe(false); + }); }); }); describe('avatar label', () => { - it('includes the correct attributes with name and avatar_url', () => { + it('includes the correct attributes with name and avatar_url', async () => { + createComponent(); + await waitForPromises(); + expect(findAvatarByLabel(group1.full_name).attributes()).toMatchObject({ src: group1.avatar_url, 'entity-id': `${group1.id}`, @@ -87,7 +133,7 @@ describe('GroupSelect', () => { describe('when filtering out the group from results', () => { beforeEach(() => { - wrapper = createComponent({ invalidGroups: [group1.id] }); + createComponent({ invalidGroups: [group1.id] }); }); it('does not find an invalid group', () => { @@ -101,7 +147,10 @@ describe('GroupSelect', () => { }); describe('when group is selected from the dropdown', () => { - beforeEach(() => { + beforeEach(async () => { + createComponent(); + await waitForPromises(); + findAvatarByLabel(group1.full_name).trigger('click'); }); diff --git a/spec/frontend/invite_members/components/invite_groups_modal_spec.js b/spec/frontend/invite_members/components/invite_groups_modal_spec.js index 4f082145562..21e215764e5 100644 --- a/spec/frontend/invite_members/components/invite_groups_modal_spec.js +++ b/spec/frontend/invite_members/components/invite_groups_modal_spec.js @@ -242,4 +242,16 @@ describe('InviteGroupsModal', () => { }); }); }); + + it('renders `GroupSelect` component and passes correct props', () => { + createComponent(); + + expect(findGroupSelect().props()).toEqual({ + groupsFilter: 'all', + sourceId: '1', + parentGroupId: null, + invalidGroups: [], + isProject: false, + }); + }); }); |