diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-04-14 09:18:27 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-04-14 09:18:27 +0300 |
commit | c192f26df39e9a2ab122c2d097b86e461599bde8 (patch) | |
tree | 405f7ce164bcf33ce178699048b137a8712990a0 /spec/frontend/packages_and_registries | |
parent | 361def36660a93176d8cb32fb47412dbb1100c2b (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/frontend/packages_and_registries')
4 files changed, 135 insertions, 22 deletions
diff --git a/spec/frontend/packages_and_registries/package_registry/components/delete_modal_spec.js b/spec/frontend/packages_and_registries/package_registry/components/delete_modal_spec.js index d0817a8678e..b0fc9ef0f0c 100644 --- a/spec/frontend/packages_and_registries/package_registry/components/delete_modal_spec.js +++ b/spec/frontend/packages_and_registries/package_registry/components/delete_modal_spec.js @@ -1,7 +1,14 @@ -import { GlModal as RealGlModal } from '@gitlab/ui'; +import { GlModal as RealGlModal, GlSprintf } from '@gitlab/ui'; import { shallowMountExtended } from 'helpers/vue_test_utils_helper'; import { stubComponent } from 'helpers/stub_component'; import DeleteModal from '~/packages_and_registries/package_registry/components/delete_modal.vue'; +import { + DELETE_PACKAGE_MODAL_PRIMARY_ACTION, + DELETE_PACKAGE_REQUEST_FORWARDING_MODAL_CONTENT, + DELETE_PACKAGE_WITH_REQUEST_FORWARDING_PRIMARY_ACTION, + DELETE_PACKAGES_REQUEST_FORWARDING_MODAL_CONTENT, + DELETE_PACKAGES_WITH_REQUEST_FORWARDING_PRIMARY_ACTION, +} from '~/packages_and_registries/package_registry/constants'; const GlModal = stubComponent(RealGlModal, { methods: { @@ -15,21 +22,28 @@ describe('DeleteModal', () => { const defaultItemsToBeDeleted = [ { name: 'package 01', + version: '1.0.0', }, { name: 'package 02', + version: '1.0.0', }, ]; const findModal = () => wrapper.findComponent(GlModal); - const mountComponent = ({ itemsToBeDeleted = defaultItemsToBeDeleted } = {}) => { + const mountComponent = ({ + itemsToBeDeleted = defaultItemsToBeDeleted, + showRequestForwardingContent = false, + } = {}) => { wrapper = shallowMountExtended(DeleteModal, { propsData: { itemsToBeDeleted, + showRequestForwardingContent, }, stubs: { GlModal, + GlSprintf, }, }); }; @@ -50,11 +64,64 @@ describe('DeleteModal', () => { }); it('renders description', () => { - expect(findModal().text()).toContain( + expect(findModal().text()).toMatchInterpolatedText( 'You are about to delete 2 packages. This operation is irreversible.', ); }); + it('with only one item to be deleted renders correct description', () => { + mountComponent({ itemsToBeDeleted: [defaultItemsToBeDeleted[0]] }); + + expect(findModal().text()).toMatchInterpolatedText( + 'You are about to delete version 1.0.0 of package 01. Are you sure?', + ); + }); + + it('sets the right action primary text', () => { + expect(findModal().props('actionPrimary')).toMatchObject({ + text: DELETE_PACKAGE_MODAL_PRIMARY_ACTION, + }); + }); + + describe('when showRequestForwardingContent is set', () => { + it('renders correct description', () => { + mountComponent({ showRequestForwardingContent: true }); + + expect(findModal().text()).toMatchInterpolatedText( + DELETE_PACKAGES_REQUEST_FORWARDING_MODAL_CONTENT, + ); + }); + + it('sets the right action primary text', () => { + mountComponent({ showRequestForwardingContent: true }); + + expect(findModal().props('actionPrimary')).toMatchObject({ + text: DELETE_PACKAGES_WITH_REQUEST_FORWARDING_PRIMARY_ACTION, + }); + }); + + describe('and only one item to be deleted', () => { + beforeEach(() => { + mountComponent({ + showRequestForwardingContent: true, + itemsToBeDeleted: [defaultItemsToBeDeleted[0]], + }); + }); + + it('renders correct description', () => { + expect(findModal().text()).toMatchInterpolatedText( + DELETE_PACKAGE_REQUEST_FORWARDING_MODAL_CONTENT, + ); + }); + + it('sets the right action primary text', () => { + expect(findModal().props('actionPrimary')).toMatchObject({ + text: DELETE_PACKAGE_WITH_REQUEST_FORWARDING_PRIMARY_ACTION, + }); + }); + }); + }); + it('emits confirm when primary event is emitted', () => { expect(wrapper.emitted('confirm')).toBeUndefined(); diff --git a/spec/frontend/packages_and_registries/package_registry/components/list/packages_list_spec.js b/spec/frontend/packages_and_registries/package_registry/components/list/packages_list_spec.js index 433d04017dc..483b7a9383d 100644 --- a/spec/frontend/packages_and_registries/package_registry/components/list/packages_list_spec.js +++ b/spec/frontend/packages_and_registries/package_registry/components/list/packages_list_spec.js @@ -4,7 +4,6 @@ import { shallowMountExtended } from 'helpers/vue_test_utils_helper'; import { stubComponent } from 'helpers/stub_component'; import PackagesListRow from '~/packages_and_registries/package_registry/components/list/package_list_row.vue'; import PackagesListLoader from '~/packages_and_registries/shared/components/packages_list_loader.vue'; -import DeletePackageModal from '~/packages_and_registries/shared/components/delete_package_modal.vue'; import DeleteModal from '~/packages_and_registries/package_registry/components/delete_modal.vue'; import RegistryList from '~/packages_and_registries/shared/components/registry_list.vue'; import { @@ -17,7 +16,7 @@ import { } from '~/packages_and_registries/package_registry/constants'; import PackagesList from '~/packages_and_registries/package_registry/components/list/packages_list.vue'; import Tracking from '~/tracking'; -import { packageData } from '../../mock_data'; +import { defaultPackageGroupSettings, packageData } from '../../mock_data'; describe('packages_list', () => { let wrapper; @@ -39,18 +38,20 @@ describe('packages_list', () => { list: [firstPackage, secondPackage], isLoading: false, pageInfo: {}, + groupSettings: defaultPackageGroupSettings, }; const EmptySlotStub = { name: 'empty-slot-stub', template: '<div>bar</div>' }; const findPackagesListLoader = () => wrapper.findComponent(PackagesListLoader); - const findPackageListDeleteModal = () => wrapper.findComponent(DeletePackageModal); const findEmptySlot = () => wrapper.findComponent(EmptySlotStub); const findRegistryList = () => wrapper.findComponent(RegistryList); const findPackagesListRow = () => wrapper.findComponent(PackagesListRow); const findErrorPackageAlert = () => wrapper.findComponent(GlAlert); const findDeletePackagesModal = () => wrapper.findComponent(DeleteModal); + const showMock = jest.fn(); + const mountComponent = (props) => { wrapper = shallowMountExtended(PackagesList, { propsData: { @@ -58,10 +59,9 @@ describe('packages_list', () => { ...props, }, stubs: { - DeletePackageModal, DeleteModal: stubComponent(DeleteModal, { methods: { - show: jest.fn(), + show: showMock, }, }), GlSprintf, @@ -119,15 +119,20 @@ describe('packages_list', () => { }); describe('layout', () => { - it("doesn't contain a visible modal component", () => { + beforeEach(() => { mountComponent(); + }); - expect(findPackageListDeleteModal().props('itemToBeDeleted')).toBeNull(); + it('modal component is not shown', () => { + expect(showMock).not.toHaveBeenCalled(); }); - it('does not have an error alert displayed', () => { - mountComponent(); + it('modal component props is empty', () => { + expect(findDeletePackagesModal().props('itemsToBeDeleted')).toEqual([]); + expect(findDeletePackagesModal().props('showRequestForwardingContent')).toBe(false); + }); + it('does not have an error alert displayed', () => { expect(findErrorPackageAlert().exists()).toBe(false); }); }); @@ -146,8 +151,8 @@ describe('packages_list', () => { finderFunction().vm.$emit('delete', deletePayload); }); - it('passes itemToBeDeleted to the modal', () => { - expect(findPackageListDeleteModal().props('itemToBeDeleted')).toStrictEqual(firstPackage); + it('passes itemsToBeDeleted to the modal', () => { + expect(findDeletePackagesModal().props('itemsToBeDeleted')).toStrictEqual([firstPackage]); }); it('requesting delete tracks the right action', () => { @@ -158,9 +163,13 @@ describe('packages_list', () => { ); }); + it('modal component is shown', () => { + expect(showMock).toHaveBeenCalledTimes(1); + }); + describe('when modal confirms', () => { beforeEach(() => { - findPackageListDeleteModal().vm.$emit('ok'); + findDeletePackagesModal().vm.$emit('confirm'); }); it('emits delete when modal confirms', () => { @@ -176,14 +185,14 @@ describe('packages_list', () => { }); }); - it.each(['ok', 'cancel'])('resets itemToBeDeleted when modal emits %s', async (event) => { - await findPackageListDeleteModal().vm.$emit(event); + it.each(['confirm', 'cancel'])('resets itemsToBeDeleted when modal emits %s', async (event) => { + await findDeletePackagesModal().vm.$emit(event); - expect(findPackageListDeleteModal().props('itemToBeDeleted')).toBeNull(); + expect(findDeletePackagesModal().props('itemsToBeDeleted')).toEqual([]); }); it('canceling delete tracks the right action', () => { - findPackageListDeleteModal().vm.$emit('cancel'); + findDeletePackagesModal().vm.$emit('cancel'); expect(eventSpy).toHaveBeenCalledWith( category, @@ -237,7 +246,7 @@ describe('packages_list', () => { it.each(['confirm', 'cancel'])('resets itemsToBeDeleted when modal emits %s', async (event) => { await findDeletePackagesModal().vm.$emit(event); - expect(findDeletePackagesModal().props('itemsToBeDeleted')).toHaveLength(0); + expect(findDeletePackagesModal().props('itemsToBeDeleted')).toEqual([]); }); it('canceling delete tracks the right action', () => { @@ -273,7 +282,9 @@ describe('packages_list', () => { await nextTick(); - expect(findPackageListDeleteModal().text()).toContain(errorPackage.name); + expect(showMock).toHaveBeenCalledTimes(1); + + expect(findDeletePackagesModal().props('itemsToBeDeleted')).toStrictEqual([errorPackage]); }); }); diff --git a/spec/frontend/packages_and_registries/package_registry/mock_data.js b/spec/frontend/packages_and_registries/package_registry/mock_data.js index d568cfe6221..9054e4998bb 100644 --- a/spec/frontend/packages_and_registries/package_registry/mock_data.js +++ b/spec/frontend/packages_and_registries/package_registry/mock_data.js @@ -103,6 +103,13 @@ export const linksData = { }, }; +export const defaultPackageGroupSettings = { + mavenPackageRequestsForwarding: true, + npmPackageRequestsForwarding: true, + pypiPackageRequestsForwarding: true, + __typename: 'PackageSettings', +}; + export const packageVersions = () => [ { createdAt: '2021-08-10T09:33:54Z', @@ -381,7 +388,12 @@ export const packageDestroyFilesMutationError = () => ({ ], }); -export const packagesListQuery = ({ type = 'group', extend = {}, extendPagination = {} } = {}) => ({ +export const packagesListQuery = ({ + type = 'group', + extend = {}, + extendPagination = {}, + packageSettings = defaultPackageGroupSettings, +} = {}) => ({ data: { [type]: { id: '1', @@ -408,6 +420,14 @@ export const packagesListQuery = ({ type = 'group', extend = {}, extendPaginatio pageInfo: pagination(extendPagination), __typename: 'PackageConnection', }, + ...(type === 'group' && { packageSettings }), + ...(type === 'project' && { + group: { + id: '1', + packageSettings, + __typename: 'Group', + }, + }), ...extend, __typename: capitalize(type), }, diff --git a/spec/frontend/packages_and_registries/package_registry/pages/list_spec.js b/spec/frontend/packages_and_registries/package_registry/pages/list_spec.js index d2996bad97c..2ee24200ed3 100644 --- a/spec/frontend/packages_and_registries/package_registry/pages/list_spec.js +++ b/spec/frontend/packages_and_registries/package_registry/pages/list_spec.js @@ -195,6 +195,11 @@ describe('PackagesListApp', () => { list: expect.arrayContaining([expect.objectContaining({ id: packageData().id })]), isLoading: false, pageInfo: expect.objectContaining({ endCursor: pagination().endCursor }), + groupSettings: expect.objectContaining({ + mavenPackageRequestsForwarding: true, + npmPackageRequestsForwarding: true, + pypiPackageRequestsForwarding: true, + }), }); }); @@ -245,6 +250,16 @@ describe('PackagesListApp', () => { expect.objectContaining({ isGroupPage, [sortType]: 'NAME_DESC' }), ); }); + + it('list component has group settings prop set', () => { + expect(findListComponent().props()).toMatchObject({ + groupSettings: expect.objectContaining({ + mavenPackageRequestsForwarding: true, + npmPackageRequestsForwarding: true, + pypiPackageRequestsForwarding: true, + }), + }); + }); }); describe.each` |