diff options
Diffstat (limited to 'spec/frontend/packages')
17 files changed, 0 insertions, 1937 deletions
diff --git a/spec/frontend/packages/list/components/__snapshots__/packages_list_app_spec.js.snap b/spec/frontend/packages/list/components/__snapshots__/packages_list_app_spec.js.snap deleted file mode 100644 index 67e2594d29f..00000000000 --- a/spec/frontend/packages/list/components/__snapshots__/packages_list_app_spec.js.snap +++ /dev/null @@ -1,68 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`packages_list_app renders 1`] = ` -<div> - <infrastructure-title-stub - helpurl="foo" - /> - - <infrastructure-search-stub /> - - <div> - <section - class="row empty-state text-center" - > - <div - class="col-12" - > - <div - class="svg-250 svg-content" - > - <img - alt="" - class="gl-max-w-full" - role="img" - src="helpSvg" - /> - </div> - </div> - - <div - class="col-12" - > - <div - class="text-content gl-mx-auto gl-my-0 gl-p-5" - > - <h1 - class="h4" - > - There are no packages yet - </h1> - - <p> - Learn how to - <b-link-stub - class="gl-link" - event="click" - href="helpUrl" - routertag="a" - target="_blank" - > - publish and share your packages - </b-link-stub> - with GitLab. - </p> - - <div - class="gl-display-flex gl-flex-wrap gl-justify-content-center" - > - <!----> - - <!----> - </div> - </div> - </div> - </section> - </div> -</div> -`; diff --git a/spec/frontend/packages/list/components/packages_list_app_spec.js b/spec/frontend/packages/list/components/packages_list_app_spec.js deleted file mode 100644 index 5f7555a3a2b..00000000000 --- a/spec/frontend/packages/list/components/packages_list_app_spec.js +++ /dev/null @@ -1,236 +0,0 @@ -import { GlEmptyState, GlSprintf, GlLink } from '@gitlab/ui'; -import { shallowMount, createLocalVue } from '@vue/test-utils'; -import Vuex from 'vuex'; -import setWindowLocation from 'helpers/set_window_location_helper'; -import createFlash from '~/flash'; -import * as commonUtils from '~/lib/utils/common_utils'; -import PackageListApp from '~/packages/list/components/packages_list_app.vue'; -import { DELETE_PACKAGE_SUCCESS_MESSAGE } from '~/packages/list/constants'; -import { SHOW_DELETE_SUCCESS_ALERT } from '~/packages/shared/constants'; -import { FILTERED_SEARCH_TERM } from '~/packages_and_registries/shared/constants'; -import * as packageUtils from '~/packages_and_registries/shared/utils'; -import InfrastructureSearch from '~/packages_and_registries/infrastructure_registry/components/infrastructure_search.vue'; - -jest.mock('~/lib/utils/common_utils'); -jest.mock('~/flash'); - -const localVue = createLocalVue(); -localVue.use(Vuex); - -describe('packages_list_app', () => { - let wrapper; - let store; - - const PackageList = { - name: 'package-list', - template: '<div><slot name="empty-state"></slot></div>', - }; - const GlLoadingIcon = { name: 'gl-loading-icon', template: '<div>loading</div>' }; - - const emptyListHelpUrl = 'helpUrl'; - const findEmptyState = () => wrapper.find(GlEmptyState); - const findListComponent = () => wrapper.find(PackageList); - const findInfrastructureSearch = () => wrapper.find(InfrastructureSearch); - - const createStore = (filter = []) => { - store = new Vuex.Store({ - state: { - isLoading: false, - config: { - resourceId: 'project_id', - emptyListIllustration: 'helpSvg', - emptyListHelpUrl, - packageHelpUrl: 'foo', - }, - filter, - }, - }); - store.dispatch = jest.fn(); - }; - - const mountComponent = (provide) => { - wrapper = shallowMount(PackageListApp, { - localVue, - store, - stubs: { - GlEmptyState, - GlLoadingIcon, - PackageList, - GlSprintf, - GlLink, - }, - provide, - }); - }; - - beforeEach(() => { - createStore(); - jest.spyOn(packageUtils, 'getQueryParams').mockReturnValue({}); - }); - - afterEach(() => { - wrapper.destroy(); - }); - - it('renders', () => { - mountComponent(); - expect(wrapper.element).toMatchSnapshot(); - }); - - it('call requestPackagesList on page:changed', () => { - mountComponent(); - store.dispatch.mockClear(); - - const list = findListComponent(); - list.vm.$emit('page:changed', 1); - expect(store.dispatch).toHaveBeenCalledWith('requestPackagesList', { page: 1 }); - }); - - it('call requestDeletePackage on package:delete', () => { - mountComponent(); - - const list = findListComponent(); - list.vm.$emit('package:delete', 'foo'); - expect(store.dispatch).toHaveBeenCalledWith('requestDeletePackage', 'foo'); - }); - - it('does call requestPackagesList only one time on render', () => { - mountComponent(); - - expect(store.dispatch).toHaveBeenCalledTimes(3); - expect(store.dispatch).toHaveBeenNthCalledWith(1, 'setSorting', expect.any(Object)); - expect(store.dispatch).toHaveBeenNthCalledWith(2, 'setFilter', expect.any(Array)); - expect(store.dispatch).toHaveBeenNthCalledWith(3, 'requestPackagesList'); - }); - - describe('url query string handling', () => { - const defaultQueryParamsMock = { - search: [1, 2], - type: 'npm', - sort: 'asc', - orderBy: 'created', - }; - - it('calls setSorting with the query string based sorting', () => { - jest.spyOn(packageUtils, 'getQueryParams').mockReturnValue(defaultQueryParamsMock); - - mountComponent(); - - expect(store.dispatch).toHaveBeenNthCalledWith(1, 'setSorting', { - orderBy: defaultQueryParamsMock.orderBy, - sort: defaultQueryParamsMock.sort, - }); - }); - - it('calls setFilter with the query string based filters', () => { - jest.spyOn(packageUtils, 'getQueryParams').mockReturnValue(defaultQueryParamsMock); - - mountComponent(); - - expect(store.dispatch).toHaveBeenNthCalledWith(2, 'setFilter', [ - { type: 'type', value: { data: defaultQueryParamsMock.type } }, - { type: FILTERED_SEARCH_TERM, value: { data: defaultQueryParamsMock.search[0] } }, - { type: FILTERED_SEARCH_TERM, value: { data: defaultQueryParamsMock.search[1] } }, - ]); - }); - - it('calls setSorting and setFilters with the results of extractFilterAndSorting', () => { - jest - .spyOn(packageUtils, 'extractFilterAndSorting') - .mockReturnValue({ filters: ['foo'], sorting: { sort: 'desc' } }); - - mountComponent(); - - expect(store.dispatch).toHaveBeenNthCalledWith(1, 'setSorting', { sort: 'desc' }); - expect(store.dispatch).toHaveBeenNthCalledWith(2, 'setFilter', ['foo']); - }); - }); - - describe('empty state', () => { - it('generate the correct empty list link', () => { - mountComponent(); - - const link = findListComponent().find(GlLink); - - expect(link.attributes('href')).toBe(emptyListHelpUrl); - expect(link.text()).toBe('publish and share your packages'); - }); - - it('includes the right content on the default tab', () => { - mountComponent(); - - const heading = findEmptyState().find('h1'); - - expect(heading.text()).toBe('There are no packages yet'); - }); - }); - - describe('filter without results', () => { - beforeEach(() => { - createStore([{ type: 'something' }]); - mountComponent(); - }); - - it('should show specific empty message', () => { - expect(findEmptyState().text()).toContain('Sorry, your filter produced no results'); - expect(findEmptyState().text()).toContain( - 'To widen your search, change or remove the filters above', - ); - }); - }); - - describe('Search', () => { - it('exists', () => { - mountComponent(); - - expect(findInfrastructureSearch().exists()).toBe(true); - }); - - it('on update fetches data from the store', () => { - mountComponent(); - store.dispatch.mockClear(); - - findInfrastructureSearch().vm.$emit('update'); - - expect(store.dispatch).toHaveBeenCalledWith('requestPackagesList'); - }); - }); - - describe('delete alert handling', () => { - const originalLocation = window.location.href; - const search = `?${SHOW_DELETE_SUCCESS_ALERT}=true`; - - beforeEach(() => { - createStore(); - jest.spyOn(commonUtils, 'historyReplaceState').mockImplementation(() => {}); - setWindowLocation(search); - }); - - afterEach(() => { - setWindowLocation(originalLocation); - }); - - it(`creates a flash if the query string contains ${SHOW_DELETE_SUCCESS_ALERT}`, () => { - mountComponent(); - - expect(createFlash).toHaveBeenCalledWith({ - message: DELETE_PACKAGE_SUCCESS_MESSAGE, - type: 'notice', - }); - }); - - it('calls historyReplaceState with a clean url', () => { - mountComponent(); - - expect(commonUtils.historyReplaceState).toHaveBeenCalledWith(originalLocation); - }); - - it(`does nothing if the query string does not contain ${SHOW_DELETE_SUCCESS_ALERT}`, () => { - setWindowLocation('?'); - mountComponent(); - - expect(createFlash).not.toHaveBeenCalled(); - expect(commonUtils.historyReplaceState).not.toHaveBeenCalled(); - }); - }); -}); diff --git a/spec/frontend/packages/list/components/packages_list_spec.js b/spec/frontend/packages/list/components/packages_list_spec.js deleted file mode 100644 index b1478a5e6dc..00000000000 --- a/spec/frontend/packages/list/components/packages_list_spec.js +++ /dev/null @@ -1,217 +0,0 @@ -import { GlTable, GlPagination, GlModal } from '@gitlab/ui'; -import { mount, createLocalVue } from '@vue/test-utils'; -import { last } from 'lodash'; -import Vuex from 'vuex'; -import stubChildren from 'helpers/stub_children'; -import PackagesList from '~/packages/list/components/packages_list.vue'; -import PackagesListRow from '~/packages/shared/components/package_list_row.vue'; -import PackagesListLoader from '~/packages/shared/components/packages_list_loader.vue'; -import { TrackingActions } from '~/packages/shared/constants'; -import * as SharedUtils from '~/packages/shared/utils'; -import Tracking from '~/tracking'; -import { packageList } from '../../mock_data'; - -const localVue = createLocalVue(); -localVue.use(Vuex); - -describe('packages_list', () => { - let wrapper; - let store; - - const EmptySlotStub = { name: 'empty-slot-stub', template: '<div>bar</div>' }; - - const findPackagesListLoader = () => wrapper.find(PackagesListLoader); - const findPackageListPagination = () => wrapper.find(GlPagination); - const findPackageListDeleteModal = () => wrapper.find(GlModal); - const findEmptySlot = () => wrapper.find(EmptySlotStub); - const findPackagesListRow = () => wrapper.find(PackagesListRow); - - const createStore = (isGroupPage, packages, isLoading) => { - const state = { - isLoading, - packages, - pagination: { - perPage: 1, - total: 1, - page: 1, - }, - config: { - isGroupPage, - }, - sorting: { - orderBy: 'version', - sort: 'desc', - }, - }; - store = new Vuex.Store({ - state, - getters: { - getList: () => packages, - }, - }); - store.dispatch = jest.fn(); - }; - - const mountComponent = ({ - isGroupPage = false, - packages = packageList, - isLoading = false, - ...options - } = {}) => { - createStore(isGroupPage, packages, isLoading); - - wrapper = mount(PackagesList, { - localVue, - store, - stubs: { - ...stubChildren(PackagesList), - GlTable, - GlModal, - }, - ...options, - }); - }; - - afterEach(() => { - wrapper.destroy(); - wrapper = null; - }); - - describe('when is loading', () => { - beforeEach(() => { - mountComponent({ - packages: [], - isLoading: true, - }); - }); - - it('shows skeleton loader when loading', () => { - expect(findPackagesListLoader().exists()).toBe(true); - }); - }); - - describe('when is not loading', () => { - beforeEach(() => { - mountComponent(); - }); - - it('does not show skeleton loader when not loading', () => { - expect(findPackagesListLoader().exists()).toBe(false); - }); - }); - - describe('layout', () => { - beforeEach(() => { - mountComponent(); - }); - - it('contains a pagination component', () => { - const sorting = findPackageListPagination(); - expect(sorting.exists()).toBe(true); - }); - - it('contains a modal component', () => { - const sorting = findPackageListDeleteModal(); - expect(sorting.exists()).toBe(true); - }); - }); - - describe('when the user can destroy the package', () => { - beforeEach(() => { - mountComponent(); - }); - - it('setItemToBeDeleted sets itemToBeDeleted and open the modal', () => { - const mockModalShow = jest.spyOn(wrapper.vm.$refs.packageListDeleteModal, 'show'); - const item = last(wrapper.vm.list); - - findPackagesListRow().vm.$emit('packageToDelete', item); - - return wrapper.vm.$nextTick().then(() => { - expect(wrapper.vm.itemToBeDeleted).toEqual(item); - expect(mockModalShow).toHaveBeenCalled(); - }); - }); - - it('deleteItemConfirmation resets itemToBeDeleted', () => { - wrapper.setData({ itemToBeDeleted: 1 }); - wrapper.vm.deleteItemConfirmation(); - expect(wrapper.vm.itemToBeDeleted).toEqual(null); - }); - - it('deleteItemConfirmation emit package:delete', () => { - const itemToBeDeleted = { id: 2 }; - wrapper.setData({ itemToBeDeleted }); - wrapper.vm.deleteItemConfirmation(); - return wrapper.vm.$nextTick(() => { - expect(wrapper.emitted('package:delete')[0]).toEqual([itemToBeDeleted]); - }); - }); - - it('deleteItemCanceled resets itemToBeDeleted', () => { - wrapper.setData({ itemToBeDeleted: 1 }); - wrapper.vm.deleteItemCanceled(); - expect(wrapper.vm.itemToBeDeleted).toEqual(null); - }); - }); - - describe('when the list is empty', () => { - beforeEach(() => { - mountComponent({ - packages: [], - slots: { - 'empty-state': EmptySlotStub, - }, - }); - }); - - it('show the empty slot', () => { - const emptySlot = findEmptySlot(); - expect(emptySlot.exists()).toBe(true); - }); - }); - - describe('pagination component', () => { - let pagination; - let modelEvent; - - beforeEach(() => { - mountComponent(); - pagination = findPackageListPagination(); - // retrieve the event used by v-model, a more sturdy approach than hardcoding it - modelEvent = pagination.vm.$options.model.event; - }); - - it('emits page:changed events when the page changes', () => { - pagination.vm.$emit(modelEvent, 2); - expect(wrapper.emitted('page:changed')).toEqual([[2]]); - }); - }); - - describe('tracking', () => { - let eventSpy; - let utilSpy; - const category = 'foo'; - - beforeEach(() => { - mountComponent(); - eventSpy = jest.spyOn(Tracking, 'event'); - utilSpy = jest.spyOn(SharedUtils, 'packageTypeToTrackCategory').mockReturnValue(category); - wrapper.setData({ itemToBeDeleted: { package_type: 'conan' } }); - }); - - it('tracking category calls packageTypeToTrackCategory', () => { - expect(wrapper.vm.tracking.category).toBe(category); - expect(utilSpy).toHaveBeenCalledWith('conan'); - }); - - it('deleteItemConfirmation calls event', () => { - wrapper.vm.deleteItemConfirmation(); - expect(eventSpy).toHaveBeenCalledWith( - category, - TrackingActions.DELETE_PACKAGE, - expect.any(Object), - ); - }); - }); -}); diff --git a/spec/frontend/packages/list/stores/actions_spec.js b/spec/frontend/packages/list/stores/actions_spec.js deleted file mode 100644 index adccb7436e1..00000000000 --- a/spec/frontend/packages/list/stores/actions_spec.js +++ /dev/null @@ -1,277 +0,0 @@ -import axios from 'axios'; -import MockAdapter from 'axios-mock-adapter'; -import testAction from 'helpers/vuex_action_helper'; -import Api from '~/api'; -import createFlash from '~/flash'; -import { MISSING_DELETE_PATH_ERROR } from '~/packages/list/constants'; -import * as actions from '~/packages/list/stores/actions'; -import * as types from '~/packages/list/stores/mutation_types'; -import { DELETE_PACKAGE_ERROR_MESSAGE } from '~/packages/shared/constants'; - -jest.mock('~/flash.js'); -jest.mock('~/api.js'); - -describe('Actions Package list store', () => { - const headers = 'bar'; - let mock; - - beforeEach(() => { - Api.projectPackages = jest.fn().mockResolvedValue({ data: 'foo', headers }); - Api.groupPackages = jest.fn().mockResolvedValue({ data: 'baz', headers }); - mock = new MockAdapter(axios); - }); - - afterEach(() => { - mock.restore(); - }); - - describe('requestPackagesList', () => { - const sorting = { - sort: 'asc', - orderBy: 'version', - }; - - const filter = []; - it('should fetch the project packages list when isGroupPage is false', (done) => { - testAction( - actions.requestPackagesList, - undefined, - { config: { isGroupPage: false, resourceId: 1 }, sorting, filter }, - [], - [ - { type: 'setLoading', payload: true }, - { type: 'receivePackagesListSuccess', payload: { data: 'foo', headers } }, - { type: 'setLoading', payload: false }, - ], - () => { - expect(Api.projectPackages).toHaveBeenCalledWith(1, { - params: { page: 1, per_page: 20, sort: sorting.sort, order_by: sorting.orderBy }, - }); - done(); - }, - ); - }); - - it('should fetch the group packages list when isGroupPage is true', (done) => { - testAction( - actions.requestPackagesList, - undefined, - { config: { isGroupPage: true, resourceId: 2 }, sorting, filter }, - [], - [ - { type: 'setLoading', payload: true }, - { type: 'receivePackagesListSuccess', payload: { data: 'baz', headers } }, - { type: 'setLoading', payload: false }, - ], - () => { - expect(Api.groupPackages).toHaveBeenCalledWith(2, { - params: { page: 1, per_page: 20, sort: sorting.sort, order_by: sorting.orderBy }, - }); - done(); - }, - ); - }); - - it('should fetch packages of a certain type when a filter with a type is present', (done) => { - const packageType = 'maven'; - - testAction( - actions.requestPackagesList, - undefined, - { - config: { isGroupPage: false, resourceId: 1 }, - sorting, - filter: [{ type: 'type', value: { data: 'maven' } }], - }, - [], - [ - { type: 'setLoading', payload: true }, - { type: 'receivePackagesListSuccess', payload: { data: 'foo', headers } }, - { type: 'setLoading', payload: false }, - ], - () => { - expect(Api.projectPackages).toHaveBeenCalledWith(1, { - params: { - page: 1, - per_page: 20, - sort: sorting.sort, - order_by: sorting.orderBy, - package_type: packageType, - }, - }); - done(); - }, - ); - }); - - it('should create flash on API error', (done) => { - Api.projectPackages = jest.fn().mockRejectedValue(); - testAction( - actions.requestPackagesList, - undefined, - { config: { isGroupPage: false, resourceId: 2 }, sorting, filter }, - [], - [ - { type: 'setLoading', payload: true }, - { type: 'setLoading', payload: false }, - ], - () => { - expect(createFlash).toHaveBeenCalled(); - done(); - }, - ); - }); - - it('should force the terraform_module type when forceTerraform is true', (done) => { - testAction( - actions.requestPackagesList, - undefined, - { config: { isGroupPage: false, resourceId: 1, forceTerraform: true }, sorting, filter }, - [], - [ - { type: 'setLoading', payload: true }, - { type: 'receivePackagesListSuccess', payload: { data: 'foo', headers } }, - { type: 'setLoading', payload: false }, - ], - () => { - expect(Api.projectPackages).toHaveBeenCalledWith(1, { - params: { - page: 1, - per_page: 20, - sort: sorting.sort, - order_by: sorting.orderBy, - package_type: 'terraform_module', - }, - }); - done(); - }, - ); - }); - }); - - describe('receivePackagesListSuccess', () => { - it('should set received packages', (done) => { - const data = 'foo'; - - testAction( - actions.receivePackagesListSuccess, - { data, headers }, - null, - [ - { type: types.SET_PACKAGE_LIST_SUCCESS, payload: data }, - { type: types.SET_PAGINATION, payload: headers }, - ], - [], - done, - ); - }); - }); - - describe('setInitialState', () => { - it('should commit setInitialState', (done) => { - testAction( - actions.setInitialState, - '1', - null, - [{ type: types.SET_INITIAL_STATE, payload: '1' }], - [], - done, - ); - }); - }); - - describe('setLoading', () => { - it('should commit set main loading', (done) => { - testAction( - actions.setLoading, - true, - null, - [{ type: types.SET_MAIN_LOADING, payload: true }], - [], - done, - ); - }); - }); - - describe('requestDeletePackage', () => { - const payload = { - _links: { - delete_api_path: 'foo', - }, - }; - it('should perform a delete operation on _links.delete_api_path', (done) => { - mock.onDelete(payload._links.delete_api_path).replyOnce(200); - Api.projectPackages = jest.fn().mockResolvedValue({ data: 'foo' }); - - testAction( - actions.requestDeletePackage, - payload, - { pagination: { page: 1 } }, - [], - [ - { type: 'setLoading', payload: true }, - { type: 'requestPackagesList', payload: { page: 1 } }, - ], - done, - ); - }); - - it('should stop the loading and call create flash on api error', (done) => { - mock.onDelete(payload._links.delete_api_path).replyOnce(400); - testAction( - actions.requestDeletePackage, - payload, - null, - [], - [ - { type: 'setLoading', payload: true }, - { type: 'setLoading', payload: false }, - ], - () => { - expect(createFlash).toHaveBeenCalled(); - done(); - }, - ); - }); - - it.each` - property | actionPayload - ${'_links'} | ${{}} - ${'delete_api_path'} | ${{ _links: {} }} - `('should reject and createFlash when $property is missing', ({ actionPayload }, done) => { - testAction(actions.requestDeletePackage, actionPayload, null, [], []).catch((e) => { - expect(e).toEqual(new Error(MISSING_DELETE_PATH_ERROR)); - expect(createFlash).toHaveBeenCalledWith({ - message: DELETE_PACKAGE_ERROR_MESSAGE, - }); - done(); - }); - }); - }); - - describe('setSorting', () => { - it('should commit SET_SORTING', (done) => { - testAction( - actions.setSorting, - 'foo', - null, - [{ type: types.SET_SORTING, payload: 'foo' }], - [], - done, - ); - }); - }); - - describe('setFilter', () => { - it('should commit SET_FILTER', (done) => { - testAction( - actions.setFilter, - 'foo', - null, - [{ type: types.SET_FILTER, payload: 'foo' }], - [], - done, - ); - }); - }); -}); diff --git a/spec/frontend/packages/list/stores/getters_spec.js b/spec/frontend/packages/list/stores/getters_spec.js deleted file mode 100644 index 080bbc21d9f..00000000000 --- a/spec/frontend/packages/list/stores/getters_spec.js +++ /dev/null @@ -1,36 +0,0 @@ -import getList from '~/packages/list/stores/getters'; -import { packageList } from '../../mock_data'; - -describe('Getters registry list store', () => { - let state; - - const setState = ({ isGroupPage = false } = {}) => { - state = { - packages: packageList, - config: { - isGroupPage, - }, - }; - }; - - beforeEach(() => setState()); - - afterEach(() => { - state = null; - }); - - describe('getList', () => { - it('returns a list of packages', () => { - const result = getList(state); - - expect(result).toHaveLength(packageList.length); - expect(result[0].name).toBe('Test package'); - }); - - it('adds projectPathName', () => { - const result = getList(state); - - expect(result[0].projectPathName).toMatchInlineSnapshot(`"foo / bar / baz"`); - }); - }); -}); diff --git a/spec/frontend/packages/list/stores/mutations_spec.js b/spec/frontend/packages/list/stores/mutations_spec.js deleted file mode 100644 index 2ddf3a1da33..00000000000 --- a/spec/frontend/packages/list/stores/mutations_spec.js +++ /dev/null @@ -1,87 +0,0 @@ -import * as commonUtils from '~/lib/utils/common_utils'; -import * as types from '~/packages/list/stores/mutation_types'; -import mutations from '~/packages/list/stores/mutations'; -import createState from '~/packages/list/stores/state'; -import { npmPackage, mavenPackage } from '../../mock_data'; - -describe('Mutations Registry Store', () => { - let mockState; - beforeEach(() => { - mockState = createState(); - }); - - describe('SET_INITIAL_STATE', () => { - it('should set the initial state', () => { - const config = { - resourceId: '1', - pageType: 'groups', - userCanDelete: '', - emptyListIllustration: 'foo', - emptyListHelpUrl: 'baz', - }; - - const expectedState = { - ...mockState, - config: { - ...config, - isGroupPage: true, - canDestroyPackage: true, - }, - }; - mutations[types.SET_INITIAL_STATE](mockState, config); - - expect(mockState.projectId).toEqual(expectedState.projectId); - }); - }); - - describe('SET_PACKAGE_LIST_SUCCESS', () => { - it('should set a packages list', () => { - const payload = [npmPackage, mavenPackage]; - const expectedState = { ...mockState, packages: payload }; - mutations[types.SET_PACKAGE_LIST_SUCCESS](mockState, payload); - - expect(mockState.packages).toEqual(expectedState.packages); - }); - }); - - describe('SET_MAIN_LOADING', () => { - it('should set main loading', () => { - mutations[types.SET_MAIN_LOADING](mockState, true); - - expect(mockState.isLoading).toEqual(true); - }); - }); - - describe('SET_PAGINATION', () => { - const mockPagination = { perPage: 10, page: 1 }; - beforeEach(() => { - commonUtils.normalizeHeaders = jest.fn().mockReturnValue('baz'); - commonUtils.parseIntPagination = jest.fn().mockReturnValue(mockPagination); - }); - it('should set a parsed pagination', () => { - mutations[types.SET_PAGINATION](mockState, 'foo'); - expect(commonUtils.normalizeHeaders).toHaveBeenCalledWith('foo'); - expect(commonUtils.parseIntPagination).toHaveBeenCalledWith('baz'); - expect(mockState.pagination).toEqual(mockPagination); - }); - }); - - describe('SET_SORTING', () => { - it('should merge the sorting object with sort value', () => { - mutations[types.SET_SORTING](mockState, { sort: 'desc' }); - expect(mockState.sorting).toEqual({ ...mockState.sorting, sort: 'desc' }); - }); - - it('should merge the sorting object with order_by value', () => { - mutations[types.SET_SORTING](mockState, { orderBy: 'foo' }); - expect(mockState.sorting).toEqual({ ...mockState.sorting, orderBy: 'foo' }); - }); - }); - - describe('SET_FILTER', () => { - it('should set the filter query', () => { - mutations[types.SET_FILTER](mockState, 'foo'); - expect(mockState.filter).toEqual('foo'); - }); - }); -}); diff --git a/spec/frontend/packages/list/utils_spec.js b/spec/frontend/packages/list/utils_spec.js deleted file mode 100644 index 4e4f7b8a723..00000000000 --- a/spec/frontend/packages/list/utils_spec.js +++ /dev/null @@ -1,48 +0,0 @@ -import { SORT_FIELDS } from '~/packages/list/constants'; -import { getNewPaginationPage, sortableFields } from '~/packages/list/utils'; - -describe('Packages list utils', () => { - describe('sortableFields', () => { - it('returns the correct list when is a project page', () => { - expect(sortableFields()).toEqual(SORT_FIELDS.filter((f) => f.orderBy !== 'project_path')); - }); - it('returns the full list on the group page', () => { - expect(sortableFields(true)).toEqual(SORT_FIELDS); - }); - }); - describe('packageTypeDisplay', () => { - it('returns the current page when total items exceeds pagniation', () => { - expect(getNewPaginationPage(2, 20, 21)).toBe(2); - }); - - it('returns the previous page when total items is lower than or equal to pagination', () => { - expect(getNewPaginationPage(2, 20, 20)).toBe(1); - }); - - it('returns the first page when totalItems is lower than or equal to perPage', () => { - expect(getNewPaginationPage(4, 20, 20)).toBe(1); - }); - - describe('works when a different perPage is used', () => { - it('returns the current page', () => { - expect(getNewPaginationPage(2, 10, 11)).toBe(2); - }); - - it('returns the previous page', () => { - expect(getNewPaginationPage(2, 10, 10)).toBe(1); - }); - }); - - describe.each` - currentPage | totalItems | expectedResult - ${1} | ${20} | ${1} - ${2} | ${20} | ${1} - ${3} | ${40} | ${2} - ${4} | ${60} | ${3} - `(`works across numerious pages`, ({ currentPage, totalItems, expectedResult }) => { - it(`when currentPage is ${currentPage} return to the previous page ${expectedResult}`, () => { - expect(getNewPaginationPage(currentPage, 20, totalItems)).toBe(expectedResult); - }); - }); - }); -}); diff --git a/spec/frontend/packages/mock_data.js b/spec/frontend/packages/mock_data.js deleted file mode 100644 index 33b47cca68b..00000000000 --- a/spec/frontend/packages/mock_data.js +++ /dev/null @@ -1,210 +0,0 @@ -const _links = { - web_path: 'foo', - delete_api_path: 'bar', -}; - -export const mockPipelineInfo = { - id: 1, - ref: 'branch-name', - sha: 'sha-baz', - user: { - name: 'foo', - }, - project: { - name: 'foo-project', - web_url: 'foo-project-link', - commit_url: 'foo-commit-link', - pipeline_url: 'foo-pipeline-link', - }, - created_at: '2015-12-10', -}; - -export const mavenPackage = { - created_at: '2015-12-10', - id: 1, - maven_metadatum: { - app_group: 'com.test.app', - app_name: 'test-app', - app_version: '1.0-SNAPSHOT', - }, - name: 'Test package', - package_type: 'maven', - project_path: 'foo/bar/baz', - projectPathName: 'foo/bar/baz', - project_id: 1, - updated_at: '2015-12-10', - version: '1.0.0', - _links, -}; - -export const mavenFiles = [ - { - created_at: '2015-12-10', - file_name: 'File one', - id: 1, - size: 100, - download_path: '/-/package_files/1/download', - }, - { - created_at: '2015-12-10', - file_name: 'File two', - id: 2, - size: 200, - download_path: '/-/package_files/2/download', - }, -]; - -export const npmPackage = { - created_at: '2015-12-10', - id: 2, - name: '@Test/package', - package_type: 'npm', - project_path: 'foo/bar/baz', - projectPathName: 'foo/bar/baz', - project_id: 1, - updated_at: '2015-12-10', - version: '', - versions: [], - _links, - pipeline: mockPipelineInfo, -}; - -export const npmFiles = [ - { - created_at: '2015-12-10', - file_name: '@test/test-package-1.0.0.tgz', - id: 2, - size: 200, - download_path: '/-/package_files/2/download', - pipelines: [ - { id: 1, project: { commit_url: 'http://foo.bar' }, git_commit_message: 'foo bar baz?' }, - ], - file_sha256: 'file_sha256', - file_md5: 'file_md5', - file_sha1: 'file_sha1', - }, -]; - -export const conanPackage = { - conan_metadatum: { - package_channel: 'stable', - package_username: 'conan+conan-package', - }, - conan_package_name: 'conan-package', - created_at: '2015-12-10', - id: 3, - name: 'conan-package/1.0.0@conan+conan-package/stable', - project_path: 'foo/bar/baz', - projectPathName: 'foo/bar/baz', - package_files: [], - package_type: 'conan', - project_id: 1, - updated_at: '2015-12-10', - version: '1.0.0', - _links, -}; - -export const dependencyLinks = { - withoutFramework: { name: 'Moqi', version_pattern: '2.5.6' }, - withoutVersion: { name: 'Castle.Core', version_pattern: '' }, - fullLink: { - name: 'Test.Dependency', - version_pattern: '2.3.7', - target_framework: '.NETStandard2.0', - }, - anotherFullLink: { - name: 'Newtonsoft.Json', - version_pattern: '12.0.3', - target_framework: '.NETStandard2.0', - }, -}; - -export const nugetPackage = { - created_at: '2015-12-10', - id: 4, - name: 'NugetPackage1', - package_files: [], - package_type: 'nuget', - project_id: 1, - tags: [], - updated_at: '2015-12-10', - version: '1.0.0', - dependency_links: Object.values(dependencyLinks), - nuget_metadatum: { - icon_url: 'fake-icon', - project_url: 'project-foo-url', - license_url: 'license-foo-url', - }, -}; - -export const rubygemsPackage = { - created_at: '2015-12-10', - id: 4, - name: 'RubyGem1', - package_files: [], - package_type: 'rubygems', - project_id: 1, - tags: [], - updated_at: '2015-12-10', - version: '1.0.0', - rubygems_metadatum: { - author: 'Fake Name', - summary: 'My gem', - email: 'tanuki@fake.com', - }, -}; - -export const pypiPackage = { - created_at: '2015-12-10', - id: 5, - name: 'PyPiPackage', - package_files: [], - package_type: 'pypi', - project_id: 1, - tags: [], - updated_at: '2015-12-10', - version: '1.0.0', -}; - -export const composerPackage = { - created_at: '2015-12-10', - id: 5, - name: 'ComposerPackage', - package_files: [], - package_type: 'composer', - project_id: 1, - tags: [], - updated_at: '2015-12-10', - version: '1.0.0', -}; - -export const terraformModule = { - created_at: '2015-12-10', - id: 2, - name: 'Test/system-22', - package_type: 'terraform_module', - project_path: 'foo/bar/baz', - projectPathName: 'foo/bar/baz', - project_id: 1, - updated_at: '2015-12-10', - version: '0.1', - versions: [], - _links, -}; - -export const mockTags = [ - { - name: 'foo-1', - }, - { - name: 'foo-2', - }, - { - name: 'foo-3', - }, - { - name: 'foo-4', - }, -]; - -export const packageList = [mavenPackage, { ...npmPackage, tags: mockTags }, conanPackage]; diff --git a/spec/frontend/packages/shared/components/__snapshots__/package_list_row_spec.js.snap b/spec/frontend/packages/shared/components/__snapshots__/package_list_row_spec.js.snap deleted file mode 100644 index b576f1b2553..00000000000 --- a/spec/frontend/packages/shared/components/__snapshots__/package_list_row_spec.js.snap +++ /dev/null @@ -1,118 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`packages_list_row renders 1`] = ` -<div - class="gl-display-flex gl-flex-direction-column gl-border-b-solid gl-border-t-solid gl-border-t-1 gl-border-b-1 gl-border-t-transparent gl-border-b-gray-100" - data-qa-selector="package_row" -> - <div - class="gl-display-flex gl-align-items-center gl-py-3 gl-px-5" - > - <!----> - - <div - class="gl-display-flex gl-xs-flex-direction-column gl-justify-content-space-between gl-align-items-stretch gl-flex-grow-1" - > - <div - class="gl-display-flex gl-flex-direction-column gl-xs-mb-3 gl-min-w-0 gl-flex-grow-1" - > - <div - class="gl-display-flex gl-align-items-center gl-text-body gl-font-weight-bold gl-min-h-6 gl-min-w-0" - > - <div - class="gl-display-flex gl-align-items-center gl-mr-3 gl-min-w-0" - > - <gl-link-stub - class="gl-text-body gl-min-w-0" - data-qa-selector="package_link" - href="foo" - > - <gl-truncate-stub - position="end" - text="Test package" - /> - </gl-link-stub> - - <!----> - - <!----> - </div> - - <!----> - </div> - - <div - class="gl-display-flex gl-align-items-center gl-text-gray-500 gl-min-h-6 gl-min-w-0 gl-flex-grow-1" - > - <div - class="gl-display-flex" - > - <span> - 1.0.0 - </span> - - <!----> - - <div /> - - <package-path-stub - path="foo/bar/baz" - /> - </div> - </div> - </div> - - <div - class="gl-display-flex gl-flex-direction-column gl-sm-align-items-flex-end gl-justify-content-space-between gl-text-gray-500 gl-flex-shrink-0" - > - <div - class="gl-display-flex gl-align-items-center gl-sm-text-body gl-sm-font-weight-bold gl-min-h-6" - > - <publish-method-stub - packageentity="[object Object]" - /> - </div> - - <div - class="gl-display-flex gl-align-items-center gl-min-h-6" - > - <span> - <gl-sprintf-stub - message="Created %{timestamp}" - /> - </span> - </div> - </div> - </div> - - <div - class="gl-w-9 gl-display-none gl-sm-display-flex gl-justify-content-end gl-pr-1" - > - <gl-button-stub - aria-label="Remove package" - buttontextclasses="" - category="secondary" - data-testid="action-delete" - icon="remove" - size="medium" - title="Remove package" - variant="danger" - /> - </div> - </div> - - <div - class="gl-display-flex" - > - <div - class="gl-w-7" - /> - - <!----> - - <div - class="gl-w-9" - /> - </div> -</div> -`; diff --git a/spec/frontend/packages/shared/components/__snapshots__/publish_method_spec.js.snap b/spec/frontend/packages/shared/components/__snapshots__/publish_method_spec.js.snap deleted file mode 100644 index acdf7c49ebd..00000000000 --- a/spec/frontend/packages/shared/components/__snapshots__/publish_method_spec.js.snap +++ /dev/null @@ -1,42 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`publish_method renders 1`] = ` -<div - class="gl-display-flex gl-align-items-center" -> - <gl-icon-stub - class="gl-mr-2" - name="git-merge" - size="16" - /> - - <span - class="gl-mr-2" - data-testid="pipeline-ref" - > - branch-name - </span> - - <gl-icon-stub - class="gl-mr-2" - name="commit" - size="16" - /> - - <gl-link-stub - class="gl-mr-2" - data-testid="pipeline-sha" - href="../commit/sha-baz" - > - sha-baz - </gl-link-stub> - - <clipboard-button-stub - category="tertiary" - size="small" - text="sha-baz" - title="Copy commit SHA" - tooltipplacement="top" - /> -</div> -`; diff --git a/spec/frontend/packages/shared/components/package_icon_and_name_spec.js b/spec/frontend/packages/shared/components/package_icon_and_name_spec.js deleted file mode 100644 index c96a570a29c..00000000000 --- a/spec/frontend/packages/shared/components/package_icon_and_name_spec.js +++ /dev/null @@ -1,32 +0,0 @@ -import { GlIcon } from '@gitlab/ui'; -import { shallowMount } from '@vue/test-utils'; -import PackageIconAndName from '~/packages/shared/components/package_icon_and_name.vue'; - -describe('PackageIconAndName', () => { - let wrapper; - - const findIcon = () => wrapper.find(GlIcon); - - const mountComponent = () => { - wrapper = shallowMount(PackageIconAndName, { - slots: { - default: 'test', - }, - }); - }; - - it('has an icon', () => { - mountComponent(); - - const icon = findIcon(); - - expect(icon.exists()).toBe(true); - expect(icon.props('name')).toBe('package'); - }); - - it('renders the slot content', () => { - mountComponent(); - - expect(wrapper.text()).toBe('test'); - }); -}); diff --git a/spec/frontend/packages/shared/components/package_list_row_spec.js b/spec/frontend/packages/shared/components/package_list_row_spec.js deleted file mode 100644 index 5f2fc8ddfbd..00000000000 --- a/spec/frontend/packages/shared/components/package_list_row_spec.js +++ /dev/null @@ -1,185 +0,0 @@ -import { GlLink } from '@gitlab/ui'; -import { shallowMountExtended } from 'helpers/vue_test_utils_helper'; -import { createMockDirective, getBinding } from 'helpers/vue_mock_directive'; - -import PackagesListRow from '~/packages/shared/components/package_list_row.vue'; -import PackagePath from '~/packages/shared/components/package_path.vue'; -import PackageTags from '~/packages/shared/components/package_tags.vue'; -import { PACKAGE_ERROR_STATUS } from '~/packages/shared/constants'; - -import ListItem from '~/vue_shared/components/registry/list_item.vue'; -import { packageList } from '../../mock_data'; - -describe('packages_list_row', () => { - let wrapper; - let store; - - const [packageWithoutTags, packageWithTags] = packageList; - - const InfrastructureIconAndName = { name: 'InfrastructureIconAndName', template: '<div></div>' }; - const PackageIconAndName = { name: 'PackageIconAndName', template: '<div></div>' }; - - const findPackageTags = () => wrapper.findComponent(PackageTags); - const findPackagePath = () => wrapper.findComponent(PackagePath); - const findDeleteButton = () => wrapper.findByTestId('action-delete'); - const findPackageIconAndName = () => wrapper.findComponent(PackageIconAndName); - const findInfrastructureIconAndName = () => wrapper.findComponent(InfrastructureIconAndName); - const findListItem = () => wrapper.findComponent(ListItem); - const findPackageLink = () => wrapper.findComponent(GlLink); - const findWarningIcon = () => wrapper.findByTestId('warning-icon'); - - const mountComponent = ({ - isGroup = false, - packageEntity = packageWithoutTags, - showPackageType = true, - disableDelete = false, - provide, - } = {}) => { - wrapper = shallowMountExtended(PackagesListRow, { - store, - provide, - stubs: { - ListItem, - InfrastructureIconAndName, - PackageIconAndName, - }, - propsData: { - packageLink: 'foo', - packageEntity, - isGroup, - showPackageType, - disableDelete, - }, - directives: { - GlTooltip: createMockDirective(), - }, - }); - }; - - afterEach(() => { - wrapper.destroy(); - wrapper = null; - }); - - it('renders', () => { - mountComponent(); - expect(wrapper.element).toMatchSnapshot(); - }); - - describe('tags', () => { - it('renders package tags when a package has tags', () => { - mountComponent({ isGroup: false, packageEntity: packageWithTags }); - - expect(findPackageTags().exists()).toBe(true); - }); - - it('does not render when there are no tags', () => { - mountComponent(); - - expect(findPackageTags().exists()).toBe(false); - }); - }); - - describe('when is is group', () => { - it('has a package path component', () => { - mountComponent({ isGroup: true }); - - expect(findPackagePath().exists()).toBe(true); - expect(findPackagePath().props()).toMatchObject({ path: 'foo/bar/baz' }); - }); - }); - - describe('showPackageType', () => { - it('shows the type when set', () => { - mountComponent(); - - expect(findPackageIconAndName().exists()).toBe(true); - }); - - it('does not show the type when not set', () => { - mountComponent({ showPackageType: false }); - - expect(findPackageIconAndName().exists()).toBe(false); - }); - }); - - describe('deleteAvailable', () => { - it('does not show when not set', () => { - mountComponent({ disableDelete: true }); - - expect(findDeleteButton().exists()).toBe(false); - }); - }); - - describe('delete button', () => { - it('exists and has the correct props', () => { - mountComponent({ packageEntity: packageWithoutTags }); - - expect(findDeleteButton().exists()).toBe(true); - expect(findDeleteButton().attributes()).toMatchObject({ - icon: 'remove', - category: 'secondary', - variant: 'danger', - title: 'Remove package', - }); - }); - - it('emits the packageToDelete event when the delete button is clicked', async () => { - mountComponent({ packageEntity: packageWithoutTags }); - - findDeleteButton().vm.$emit('click'); - - await wrapper.vm.$nextTick(); - expect(wrapper.emitted('packageToDelete')).toBeTruthy(); - expect(wrapper.emitted('packageToDelete')[0]).toEqual([packageWithoutTags]); - }); - }); - - describe('Infrastructure config', () => { - it('defaults to package registry components', () => { - mountComponent(); - - expect(findPackageIconAndName().exists()).toBe(true); - expect(findInfrastructureIconAndName().exists()).toBe(false); - }); - - it('mounts different component based on the provided values', () => { - mountComponent({ - provide: { - iconComponent: 'InfrastructureIconAndName', - }, - }); - - expect(findPackageIconAndName().exists()).toBe(false); - - expect(findInfrastructureIconAndName().exists()).toBe(true); - }); - }); - - describe(`when the package is in ${PACKAGE_ERROR_STATUS} status`, () => { - beforeEach(() => { - mountComponent({ packageEntity: { ...packageWithoutTags, status: PACKAGE_ERROR_STATUS } }); - }); - - it('list item has a disabled prop', () => { - expect(findListItem().props('disabled')).toBe(true); - }); - - it('details link is disabled', () => { - expect(findPackageLink().attributes('disabled')).toBe('true'); - }); - - it('has a warning icon', () => { - const icon = findWarningIcon(); - const tooltip = getBinding(icon.element, 'gl-tooltip'); - expect(icon.props('icon')).toBe('warning'); - expect(tooltip.value).toMatchObject({ - title: 'Invalid Package: failed metadata extraction', - }); - }); - - it('delete button is disabled', () => { - expect(findDeleteButton().props('disabled')).toBe(true); - }); - }); -}); diff --git a/spec/frontend/packages/shared/components/package_path_spec.js b/spec/frontend/packages/shared/components/package_path_spec.js deleted file mode 100644 index edbdd55c1d7..00000000000 --- a/spec/frontend/packages/shared/components/package_path_spec.js +++ /dev/null @@ -1,104 +0,0 @@ -import { shallowMount } from '@vue/test-utils'; -import { createMockDirective, getBinding } from 'helpers/vue_mock_directive'; -import PackagePath from '~/packages/shared/components/package_path.vue'; - -describe('PackagePath', () => { - let wrapper; - - const mountComponent = (propsData = { path: 'foo' }) => { - wrapper = shallowMount(PackagePath, { - propsData, - directives: { - GlTooltip: createMockDirective(), - }, - }); - }; - - const BASE_ICON = 'base-icon'; - const ROOT_LINK = 'root-link'; - const ROOT_CHEVRON = 'root-chevron'; - const ELLIPSIS_ICON = 'ellipsis-icon'; - const ELLIPSIS_CHEVRON = 'ellipsis-chevron'; - const LEAF_LINK = 'leaf-link'; - - const findItem = (name) => wrapper.find(`[data-testid="${name}"]`); - const findTooltip = (w) => getBinding(w.element, 'gl-tooltip'); - - afterEach(() => { - wrapper.destroy(); - wrapper = null; - }); - - describe.each` - path | rootUrl | shouldExist | shouldNotExist - ${'foo/bar'} | ${'/foo/bar'} | ${[]} | ${[ROOT_CHEVRON, ELLIPSIS_ICON, ELLIPSIS_CHEVRON, LEAF_LINK]} - ${'foo/bar/baz'} | ${'/foo/bar'} | ${[ROOT_CHEVRON, LEAF_LINK]} | ${[ELLIPSIS_ICON, ELLIPSIS_CHEVRON]} - ${'foo/bar/baz/baz2'} | ${'/foo/bar'} | ${[ROOT_CHEVRON, LEAF_LINK, ELLIPSIS_ICON, ELLIPSIS_CHEVRON]} | ${[]} - ${'foo/bar/baz/baz2/bar2'} | ${'/foo/bar'} | ${[ROOT_CHEVRON, LEAF_LINK, ELLIPSIS_ICON, ELLIPSIS_CHEVRON]} | ${[]} - `('given path $path', ({ path, shouldExist, shouldNotExist, rootUrl }) => { - const pathPieces = path.split('/').slice(1); - const hasTooltip = shouldExist.includes(ELLIPSIS_ICON); - - describe('not disabled component', () => { - beforeEach(() => { - mountComponent({ path }); - }); - - it('should have a base icon', () => { - expect(findItem(BASE_ICON).exists()).toBe(true); - }); - - it('should have a root link', () => { - const root = findItem(ROOT_LINK); - expect(root.exists()).toBe(true); - expect(root.attributes('href')).toBe(rootUrl); - }); - - if (hasTooltip) { - it('should have a tooltip', () => { - const tooltip = findTooltip(findItem(ELLIPSIS_ICON)); - expect(tooltip).toBeDefined(); - expect(tooltip.value).toMatchObject({ - title: path, - }); - }); - } - - if (shouldExist.length) { - it.each(shouldExist)(`should have %s`, (element) => { - expect(findItem(element).exists()).toBe(true); - }); - } - - if (shouldNotExist.length) { - it.each(shouldNotExist)(`should not have %s`, (element) => { - expect(findItem(element).exists()).toBe(false); - }); - } - - if (shouldExist.includes(LEAF_LINK)) { - it('the last link should be the last piece of the path', () => { - const leaf = findItem(LEAF_LINK); - expect(leaf.attributes('href')).toBe(`/${path}`); - expect(leaf.text()).toBe(pathPieces[pathPieces.length - 1]); - }); - } - }); - - describe('disabled component', () => { - beforeEach(() => { - mountComponent({ path, disabled: true }); - }); - - it('root link is disabled', () => { - expect(findItem(ROOT_LINK).attributes('disabled')).toBe('true'); - }); - - if (shouldExist.includes(LEAF_LINK)) { - it('the last link is disabled', () => { - expect(findItem(LEAF_LINK).attributes('disabled')).toBe('true'); - }); - } - }); - }); -}); diff --git a/spec/frontend/packages/shared/components/package_tags_spec.js b/spec/frontend/packages/shared/components/package_tags_spec.js deleted file mode 100644 index d26e4e76b87..00000000000 --- a/spec/frontend/packages/shared/components/package_tags_spec.js +++ /dev/null @@ -1,107 +0,0 @@ -import { mount } from '@vue/test-utils'; -import PackageTags from '~/packages/shared/components/package_tags.vue'; -import { mockTags } from '../../mock_data'; - -describe('PackageTags', () => { - let wrapper; - - function createComponent(tags = [], props = {}) { - const propsData = { - tags, - ...props, - }; - - wrapper = mount(PackageTags, { - propsData, - }); - } - - const tagLabel = () => wrapper.find('[data-testid="tagLabel"]'); - const tagBadges = () => wrapper.findAll('[data-testid="tagBadge"]'); - const moreBadge = () => wrapper.find('[data-testid="moreBadge"]'); - - afterEach(() => { - if (wrapper) wrapper.destroy(); - }); - - describe('tag label', () => { - it('shows the tag label by default', () => { - createComponent(); - - expect(tagLabel().exists()).toBe(true); - }); - - it('hides when hideLabel prop is set to true', () => { - createComponent(mockTags, { hideLabel: true }); - - expect(tagLabel().exists()).toBe(false); - }); - }); - - it('renders the correct number of tags', () => { - createComponent(mockTags.slice(0, 2)); - - expect(tagBadges()).toHaveLength(2); - expect(moreBadge().exists()).toBe(false); - }); - - it('does not render more than the configured tagDisplayLimit', () => { - createComponent(mockTags); - - expect(tagBadges()).toHaveLength(2); - }); - - it('renders the more tags badge if there are more than the configured limit', () => { - createComponent(mockTags); - - expect(tagBadges()).toHaveLength(2); - expect(moreBadge().exists()).toBe(true); - expect(moreBadge().text()).toContain('2'); - }); - - it('renders the configured tagDisplayLimit when set in props', () => { - createComponent(mockTags, { tagDisplayLimit: 1 }); - - expect(tagBadges()).toHaveLength(1); - expect(moreBadge().exists()).toBe(true); - expect(moreBadge().text()).toContain('3'); - }); - - describe('tagBadgeStyle', () => { - const defaultStyle = ['badge', 'badge-info', 'gl-display-none']; - - it('shows tag badge when there is only one', () => { - createComponent([mockTags[0]]); - - const expectedStyle = [...defaultStyle, 'gl-display-flex', 'gl-ml-3']; - - expect(tagBadges().at(0).classes()).toEqual(expect.arrayContaining(expectedStyle)); - }); - - it('shows tag badge for medium or heigher resolutions', () => { - createComponent(mockTags); - - const expectedStyle = [...defaultStyle, 'd-md-flex']; - - expect(tagBadges().at(1).classes()).toEqual(expect.arrayContaining(expectedStyle)); - }); - - it('correctly prepends left and appends right when there is more than one tag', () => { - createComponent(mockTags, { - tagDisplayLimit: 4, - }); - - const expectedStyleWithoutAppend = [...defaultStyle, 'd-md-flex']; - const expectedStyleWithAppend = [...expectedStyleWithoutAppend, 'gl-mr-2']; - - const allBadges = tagBadges(); - - expect(allBadges.at(0).classes()).toEqual( - expect.arrayContaining([...expectedStyleWithAppend, 'gl-ml-3']), - ); - expect(allBadges.at(1).classes()).toEqual(expect.arrayContaining(expectedStyleWithAppend)); - expect(allBadges.at(2).classes()).toEqual(expect.arrayContaining(expectedStyleWithAppend)); - expect(allBadges.at(3).classes()).toEqual(expect.arrayContaining(expectedStyleWithoutAppend)); - }); - }); -}); diff --git a/spec/frontend/packages/shared/components/packages_list_loader_spec.js b/spec/frontend/packages/shared/components/packages_list_loader_spec.js deleted file mode 100644 index 4ff01068f92..00000000000 --- a/spec/frontend/packages/shared/components/packages_list_loader_spec.js +++ /dev/null @@ -1,51 +0,0 @@ -import { mount } from '@vue/test-utils'; -import PackagesListLoader from '~/packages/shared/components/packages_list_loader.vue'; - -describe('PackagesListLoader', () => { - let wrapper; - - const createComponent = (props = {}) => { - wrapper = mount(PackagesListLoader, { - propsData: { - ...props, - }, - }); - }; - - const findDesktopShapes = () => wrapper.find('[data-testid="desktop-loader"]'); - const findMobileShapes = () => wrapper.find('[data-testid="mobile-loader"]'); - - beforeEach(createComponent); - - afterEach(() => { - wrapper.destroy(); - wrapper = null; - }); - - describe('desktop loader', () => { - it('produces the right loader', () => { - expect(findDesktopShapes().findAll('rect[width="1000"]')).toHaveLength(20); - }); - - it('has the correct classes', () => { - expect(findDesktopShapes().classes()).toEqual([ - 'gl-display-none', - 'gl-sm-display-flex', - 'gl-flex-direction-column', - ]); - }); - }); - - describe('mobile loader', () => { - it('produces the right loader', () => { - expect(findMobileShapes().findAll('rect[height="170"]')).toHaveLength(5); - }); - - it('has the correct classes', () => { - expect(findMobileShapes().classes()).toEqual([ - 'gl-flex-direction-column', - 'gl-sm-display-none', - ]); - }); - }); -}); diff --git a/spec/frontend/packages/shared/components/publish_method_spec.js b/spec/frontend/packages/shared/components/publish_method_spec.js deleted file mode 100644 index 6014774990c..00000000000 --- a/spec/frontend/packages/shared/components/publish_method_spec.js +++ /dev/null @@ -1,50 +0,0 @@ -import { shallowMount } from '@vue/test-utils'; -import PublishMethod from '~/packages/shared/components/publish_method.vue'; -import { packageList } from '../../mock_data'; - -describe('publish_method', () => { - let wrapper; - - const [packageWithoutPipeline, packageWithPipeline] = packageList; - - const findPipelineRef = () => wrapper.find('[data-testid="pipeline-ref"]'); - const findPipelineSha = () => wrapper.find('[data-testid="pipeline-sha"]'); - const findManualPublish = () => wrapper.find('[data-testid="manually-published"]'); - - const mountComponent = (packageEntity = {}, isGroup = false) => { - wrapper = shallowMount(PublishMethod, { - propsData: { - packageEntity, - isGroup, - }, - }); - }; - - afterEach(() => { - wrapper.destroy(); - wrapper = null; - }); - - it('renders', () => { - mountComponent(packageWithPipeline); - expect(wrapper.element).toMatchSnapshot(); - }); - - describe('pipeline information', () => { - it('displays branch and commit when pipeline info exists', () => { - mountComponent(packageWithPipeline); - - expect(findPipelineRef().exists()).toBe(true); - expect(findPipelineSha().exists()).toBe(true); - }); - - it('does not show any pipeline details when no information exists', () => { - mountComponent(packageWithoutPipeline); - - expect(findPipelineRef().exists()).toBe(false); - expect(findPipelineSha().exists()).toBe(false); - expect(findManualPublish().exists()).toBe(true); - expect(findManualPublish().text()).toBe('Manually Published'); - }); - }); -}); diff --git a/spec/frontend/packages/shared/utils_spec.js b/spec/frontend/packages/shared/utils_spec.js deleted file mode 100644 index a1076b729f8..00000000000 --- a/spec/frontend/packages/shared/utils_spec.js +++ /dev/null @@ -1,69 +0,0 @@ -import { PackageType, TrackingCategories } from '~/packages/shared/constants'; -import { - packageTypeToTrackCategory, - beautifyPath, - getPackageTypeLabel, - getCommitLink, -} from '~/packages/shared/utils'; -import { packageList } from '../mock_data'; - -describe('Packages shared utils', () => { - describe('packageTypeToTrackCategory', () => { - it('prepend UI to package category', () => { - expect(packageTypeToTrackCategory()).toMatchInlineSnapshot(`"UI::undefined"`); - }); - - it.each(Object.keys(PackageType))('returns a correct category string for %s', (packageKey) => { - const packageName = PackageType[packageKey]; - expect(packageTypeToTrackCategory(packageName)).toBe( - `UI::${TrackingCategories[packageName]}`, - ); - }); - }); - - describe('beautifyPath', () => { - it('returns a string with spaces around /', () => { - expect(beautifyPath('foo/bar')).toBe('foo / bar'); - }); - it('does not fail for empty string', () => { - expect(beautifyPath()).toBe(''); - }); - }); - - describe('getPackageTypeLabel', () => { - describe.each` - packageType | expectedResult - ${'conan'} | ${'Conan'} - ${'maven'} | ${'Maven'} - ${'npm'} | ${'npm'} - ${'nuget'} | ${'NuGet'} - ${'pypi'} | ${'PyPI'} - ${'rubygems'} | ${'RubyGems'} - ${'composer'} | ${'Composer'} - ${'debian'} | ${'Debian'} - ${'helm'} | ${'Helm'} - ${'foo'} | ${null} - `(`package type`, ({ packageType, expectedResult }) => { - it(`${packageType} should show as ${expectedResult}`, () => { - expect(getPackageTypeLabel(packageType)).toBe(expectedResult); - }); - }); - }); - - describe('getCommitLink', () => { - it('returns a relative link when isGroup is false', () => { - const link = getCommitLink(packageList[0], false); - - expect(link).toContain('../commit'); - }); - - describe('when isGroup is true', () => { - it('returns an absolute link matching project path', () => { - const mavenPackage = packageList[0]; - const link = getCommitLink(mavenPackage, true); - - expect(link).toContain(`/${mavenPackage.project_path}/commit`); - }); - }); - }); -}); |