summaryrefslogtreecommitdiff
path: root/spec/frontend/packages
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2021-11-26 15:13:11 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2021-11-26 15:13:11 +0000
commit74015980b5259072bbf27b432b9b08fda9d27945 (patch)
treef1bae954429c9a1e0f1f99fd3dccb5be7adfb93e /spec/frontend/packages
parent5343536f2bb402bc767db2d015e45ac87189d7c3 (diff)
downloadgitlab-ce-74015980b5259072bbf27b432b9b08fda9d27945.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/frontend/packages')
-rw-r--r--spec/frontend/packages/list/stores/actions_spec.js277
-rw-r--r--spec/frontend/packages/list/stores/getters_spec.js36
-rw-r--r--spec/frontend/packages/list/stores/mutations_spec.js87
-rw-r--r--spec/frontend/packages/list/utils_spec.js48
-rw-r--r--spec/frontend/packages/mock_data.js210
-rw-r--r--spec/frontend/packages/shared/components/package_tags_spec.js2
-rw-r--r--spec/frontend/packages/shared/components/publish_method_spec.js2
-rw-r--r--spec/frontend/packages/shared/utils_spec.js2
8 files changed, 3 insertions, 661 deletions
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/package_tags_spec.js b/spec/frontend/packages/shared/components/package_tags_spec.js
index d26e4e76b87..881b49cfb06 100644
--- a/spec/frontend/packages/shared/components/package_tags_spec.js
+++ b/spec/frontend/packages/shared/components/package_tags_spec.js
@@ -1,6 +1,6 @@
import { mount } from '@vue/test-utils';
import PackageTags from '~/packages/shared/components/package_tags.vue';
-import { mockTags } from '../../mock_data';
+import { mockTags } from 'jest/packages_and_registries/infrastructure_registry/components/mock_data';
describe('PackageTags', () => {
let wrapper;
diff --git a/spec/frontend/packages/shared/components/publish_method_spec.js b/spec/frontend/packages/shared/components/publish_method_spec.js
index 6014774990c..784776fd3f0 100644
--- a/spec/frontend/packages/shared/components/publish_method_spec.js
+++ b/spec/frontend/packages/shared/components/publish_method_spec.js
@@ -1,6 +1,6 @@
import { shallowMount } from '@vue/test-utils';
import PublishMethod from '~/packages/shared/components/publish_method.vue';
-import { packageList } from '../../mock_data';
+import { packageList } from 'jest/packages_and_registries/infrastructure_registry/components/mock_data';
describe('publish_method', () => {
let wrapper;
diff --git a/spec/frontend/packages/shared/utils_spec.js b/spec/frontend/packages/shared/utils_spec.js
index a1076b729f8..94c16606cf8 100644
--- a/spec/frontend/packages/shared/utils_spec.js
+++ b/spec/frontend/packages/shared/utils_spec.js
@@ -5,7 +5,7 @@ import {
getPackageTypeLabel,
getCommitLink,
} from '~/packages/shared/utils';
-import { packageList } from '../mock_data';
+import { packageList } from 'jest/packages_and_registries/infrastructure_registry/components/mock_data';
describe('Packages shared utils', () => {
describe('packageTypeToTrackCategory', () => {