diff options
Diffstat (limited to 'spec/frontend/groups')
5 files changed, 100 insertions, 53 deletions
diff --git a/spec/frontend/groups/components/app_spec.js b/spec/frontend/groups/components/app_spec.js index 9e4666ffc70..a6bbea648d2 100644 --- a/spec/frontend/groups/components/app_spec.js +++ b/spec/frontend/groups/components/app_spec.js @@ -85,30 +85,6 @@ describe('AppComponent', () => { await nextTick(); }); - describe('computed', () => { - describe('groups', () => { - it('should return list of groups from store', () => { - jest.spyOn(vm.store, 'getGroups').mockImplementation(() => {}); - - const { groups } = vm; - - expect(vm.store.getGroups).toHaveBeenCalled(); - expect(groups).not.toBeDefined(); - }); - }); - - describe('pageInfo', () => { - it('should return pagination info from store', () => { - jest.spyOn(vm.store, 'getPaginationInfo').mockImplementation(() => {}); - - const { pageInfo } = vm; - - expect(vm.store.getPaginationInfo).toHaveBeenCalled(); - expect(pageInfo).not.toBeDefined(); - }); - }); - }); - describe('methods', () => { describe('fetchGroups', () => { it('should call `getGroups` with all the params provided', () => { diff --git a/spec/frontend/groups/components/group_item_spec.js b/spec/frontend/groups/components/group_item_spec.js index 0bc80df6535..9906f62878f 100644 --- a/spec/frontend/groups/components/group_item_spec.js +++ b/spec/frontend/groups/components/group_item_spec.js @@ -6,19 +6,20 @@ import ItemActions from '~/groups/components/item_actions.vue'; import eventHub from '~/groups/event_hub'; import { getGroupItemMicrodata } from '~/groups/store/utils'; import * as urlUtilities from '~/lib/utils/url_utility'; +import { ITEM_TYPE } from '~/groups/constants'; import { - ITEM_TYPE, - VISIBILITY_INTERNAL, - VISIBILITY_PRIVATE, - VISIBILITY_PUBLIC, -} from '~/groups/constants'; -import { mountExtended } from 'helpers/vue_test_utils_helper'; + VISIBILITY_LEVEL_PRIVATE, + VISIBILITY_LEVEL_INTERNAL, + VISIBILITY_LEVEL_PUBLIC, +} from '~/visibility_level/constants'; +import { helpPagePath } from '~/helpers/help_page_helper'; +import { mountExtended, extendedWrapper } from 'helpers/vue_test_utils_helper'; import { mockParentGroupItem, mockChildren } from '../mock_data'; const createComponent = ( propsData = { group: mockParentGroupItem, parentGroup: mockChildren[0] }, provide = { - currentGroupVisibility: VISIBILITY_PRIVATE, + currentGroupVisibility: VISIBILITY_LEVEL_PRIVATE, }, ) => { return mountExtended(GroupItem, { @@ -289,7 +290,7 @@ describe('GroupItemComponent', () => { }); describe('visibility warning popover', () => { - const findPopover = () => wrapper.findComponent(GlPopover); + const findPopover = () => extendedWrapper(wrapper.findComponent(GlPopover)); const itDoesNotRenderVisibilityWarningPopover = () => { it('does not render visibility warning popover', () => { @@ -319,13 +320,16 @@ describe('GroupItemComponent', () => { describe('when showing projects', () => { describe.each` - itemVisibility | currentGroupVisibility | isPopoverShown - ${VISIBILITY_PRIVATE} | ${VISIBILITY_PUBLIC} | ${false} - ${VISIBILITY_INTERNAL} | ${VISIBILITY_PUBLIC} | ${false} - ${VISIBILITY_PUBLIC} | ${VISIBILITY_PUBLIC} | ${false} - ${VISIBILITY_PRIVATE} | ${VISIBILITY_PRIVATE} | ${false} - ${VISIBILITY_INTERNAL} | ${VISIBILITY_PRIVATE} | ${true} - ${VISIBILITY_PUBLIC} | ${VISIBILITY_PRIVATE} | ${true} + itemVisibility | currentGroupVisibility | isPopoverShown + ${VISIBILITY_LEVEL_PRIVATE} | ${VISIBILITY_LEVEL_PUBLIC} | ${false} + ${VISIBILITY_LEVEL_INTERNAL} | ${VISIBILITY_LEVEL_PUBLIC} | ${false} + ${VISIBILITY_LEVEL_PUBLIC} | ${VISIBILITY_LEVEL_PUBLIC} | ${false} + ${VISIBILITY_LEVEL_PRIVATE} | ${VISIBILITY_LEVEL_PRIVATE} | ${false} + ${VISIBILITY_LEVEL_INTERNAL} | ${VISIBILITY_LEVEL_PRIVATE} | ${true} + ${VISIBILITY_LEVEL_PUBLIC} | ${VISIBILITY_LEVEL_PRIVATE} | ${true} + ${VISIBILITY_LEVEL_PRIVATE} | ${VISIBILITY_LEVEL_INTERNAL} | ${false} + ${VISIBILITY_LEVEL_INTERNAL} | ${VISIBILITY_LEVEL_INTERNAL} | ${false} + ${VISIBILITY_LEVEL_PUBLIC} | ${VISIBILITY_LEVEL_INTERNAL} | ${true} `( 'when item visibility is $itemVisibility and parent group visibility is $currentGroupVisibility', ({ itemVisibility, currentGroupVisibility, isPopoverShown }) => { @@ -347,8 +351,17 @@ describe('GroupItemComponent', () => { }); if (isPopoverShown) { - it('renders visibility warning popover', () => { - expect(findPopover().exists()).toBe(true); + it('renders visibility warning popover with `Learn more` link', () => { + const popover = findPopover(); + + expect(popover.exists()).toBe(true); + expect( + popover.findByRole('link', { name: GroupItem.i18n.learnMore }).attributes('href'), + ).toBe( + helpPagePath('user/project/members/share_project_with_groups', { + anchor: 'sharing-projects-with-groups-of-a-higher-restrictive-visibility-level', + }), + ); }); } else { itDoesNotRenderVisibilityWarningPopover(); @@ -361,7 +374,7 @@ describe('GroupItemComponent', () => { wrapper = createComponent({ group: { ...mockParentGroupItem, - visibility: VISIBILITY_PUBLIC, + visibility: VISIBILITY_LEVEL_PUBLIC, type: ITEM_TYPE.PROJECT, }, parentGroup: mockChildren[0], diff --git a/spec/frontend/groups/components/group_name_and_path_spec.js b/spec/frontend/groups/components/group_name_and_path_spec.js index 9c9bdead6fa..823d2ed286a 100644 --- a/spec/frontend/groups/components/group_name_and_path_spec.js +++ b/spec/frontend/groups/components/group_name_and_path_spec.js @@ -1,18 +1,23 @@ -import { nextTick } from 'vue'; +import Vue, { nextTick } from 'vue'; +import VueApollo from 'vue-apollo'; import { merge } from 'lodash'; -import { GlAlert } from '@gitlab/ui'; +import { GlAlert, GlDropdown, GlTruncate, GlDropdownItem } from '@gitlab/ui'; import { mountExtended, extendedWrapper } from 'helpers/vue_test_utils_helper'; import waitForPromises from 'helpers/wait_for_promises'; +import createMockApollo from 'helpers/mock_apollo_helper'; import GroupNameAndPath from '~/groups/components/group_name_and_path.vue'; import { getGroupPathAvailability } from '~/rest_api'; import { createAlert } from '~/flash'; import { helpPagePath } from '~/helpers/help_page_helper'; +import searchGroupsWhereUserCanCreateSubgroups from '~/groups/queries/search_groups_where_user_can_create_subgroups.query.graphql'; jest.mock('~/flash'); jest.mock('~/rest_api', () => ({ getGroupPathAvailability: jest.fn(), })); +Vue.use(VueApollo); + describe('GroupNameAndPath', () => { let wrapper; @@ -20,6 +25,17 @@ describe('GroupNameAndPath', () => { const mockGroupUrl = 'my-awesome-group'; const mockGroupUrlSuggested = 'my-awesome-group1'; + const mockQueryResponse = jest.fn().mockResolvedValue({ + data: { + currentUser: { + id: '1', + groups: { + nodes: [{ id: '2', fullPath: '/path2' }], + }, + }, + }, + }); + const defaultProvide = { basePath: 'http://gitlab.com/', fields: { @@ -32,13 +48,20 @@ describe('GroupNameAndPath', () => { pattern: '[a-zA-Z0-9_\\.][a-zA-Z0-9_\\-\\.]*[a-zA-Z0-9_\\-]|[a-zA-Z0-9_]', }, parentId: { name: 'group[parent_id]', id: 'group_parent_id', value: '1' }, + parentFullPath: { name: 'group[parent_full_path]', id: 'group_full_path', value: '/path1' }, groupId: { name: 'group[id]', id: 'group_id', value: '' }, }, + newSubgroup: false, mattermostEnabled: false, }; const createComponent = ({ provide = {} } = {}) => { - wrapper = mountExtended(GroupNameAndPath, { provide: merge({}, defaultProvide, provide) }); + wrapper = mountExtended(GroupNameAndPath, { + provide: merge({}, defaultProvide, provide), + apolloProvider: createMockApollo([ + [searchGroupsWhereUserCanCreateSubgroups, mockQueryResponse], + ]), + }); }; const createComponentEditGroup = ({ path = mockGroupUrl } = {}) => { createComponent({ @@ -46,8 +69,11 @@ describe('GroupNameAndPath', () => { }); }; - const findGroupNameField = () => wrapper.findByLabelText(GroupNameAndPath.i18n.inputs.name.label); - const findGroupUrlField = () => wrapper.findByLabelText(GroupNameAndPath.i18n.inputs.path.label); + const findGroupNameField = () => wrapper.findByLabelText('Group name'); + const findGroupUrlField = () => wrapper.findByLabelText('Group URL'); + const findSubgroupNameField = () => wrapper.findByLabelText('Subgroup name'); + const findSubgroupSlugField = () => wrapper.findByLabelText('Subgroup slug'); + const findSelectedGroup = () => wrapper.findComponent(GlTruncate); const findAlert = () => extendedWrapper(wrapper.findComponent(GlAlert)); const apiMockAvailablePath = () => { @@ -79,6 +105,41 @@ describe('GroupNameAndPath', () => { }); }); + describe('when creating a new subgroup', () => { + beforeEach(() => { + createComponent({ provide: { newSubgroup: true } }); + }); + + it('updates `Subgroup slug` field as user types', async () => { + await findSubgroupNameField().setValue(mockGroupName); + + expect(findSubgroupSlugField().element.value).toBe(mockGroupUrl); + }); + + describe('when user selects parent group', () => { + it('updates `Subgroup URL` dropdown and calls API', async () => { + expect(findSelectedGroup().text()).toContain('/path1'); + + await findSubgroupNameField().setValue(mockGroupName); + + wrapper.findComponent(GlDropdown).vm.$emit('shown'); + await wrapper.vm.$apollo.queries.currentUserGroups.refetch(); + jest.runOnlyPendingTimers(); + await waitForPromises(); + + wrapper.findComponent(GlDropdownItem).vm.$emit('click'); + await nextTick(); + + expect(findSelectedGroup().text()).toContain('/path2'); + expect(getGroupPathAvailability).toHaveBeenCalled(); + + expect(wrapper.findByText(GroupNameAndPath.i18n.inputs.path.validFeedback).exists()).toBe( + true, + ); + }); + }); + }); + describe('when editing a group', () => { it('does not update `Group URL` field and does not call API', async () => { const groupUrl = 'foo-bar'; @@ -346,9 +407,7 @@ describe('GroupNameAndPath', () => { it('shows `Group ID` field', () => { createComponentEditGroup(); - expect( - wrapper.findByLabelText(GroupNameAndPath.i18n.inputs.groupId.label).element.value, - ).toBe('1'); + expect(wrapper.findByLabelText('Group ID').element.value).toBe('1'); }); }); }); diff --git a/spec/frontend/groups/components/groups_spec.js b/spec/frontend/groups/components/groups_spec.js index 48a2319cf96..6c1eb373b7e 100644 --- a/spec/frontend/groups/components/groups_spec.js +++ b/spec/frontend/groups/components/groups_spec.js @@ -6,7 +6,7 @@ import GroupItemComponent from '~/groups/components/group_item.vue'; import PaginationLinks from '~/vue_shared/components/pagination_links.vue'; import GroupsComponent from '~/groups/components/groups.vue'; import eventHub from '~/groups/event_hub'; -import { VISIBILITY_PRIVATE } from '~/groups/constants'; +import { VISIBILITY_LEVEL_PRIVATE } from '~/visibility_level/constants'; import { mockGroups, mockPageInfo } from '../mock_data'; describe('GroupsComponent', () => { @@ -26,7 +26,7 @@ describe('GroupsComponent', () => { ...propsData, }, provide: { - currentGroupVisibility: VISIBILITY_PRIVATE, + currentGroupVisibility: VISIBILITY_LEVEL_PRIVATE, }, }); }; diff --git a/spec/frontend/groups/components/transfer_group_form_spec.js b/spec/frontend/groups/components/transfer_group_form_spec.js index 6dc760f4f7c..8cfe8ce8e18 100644 --- a/spec/frontend/groups/components/transfer_group_form_spec.js +++ b/spec/frontend/groups/components/transfer_group_form_spec.js @@ -82,7 +82,6 @@ describe('Transfer group form', () => { it('sets the confirm danger properties', () => { expect(findConfirmDanger().props()).toMatchObject({ - buttonClass: 'qa-transfer-button', disabled: true, buttonText: confirmButtonText, phrase: confirmationPhrase, |