2021-08-12 15:09:58 +00:00
|
|
|
import { GlEmptyState, GlBadge, GlTabs, GlTab } from '@gitlab/ui';
|
2022-01-25 12:14:14 +00:00
|
|
|
import Vue, { nextTick } from 'vue';
|
|
|
|
|
2021-07-21 15:08:52 +00:00
|
|
|
import VueApollo from 'vue-apollo';
|
|
|
|
import createMockApollo from 'helpers/mock_apollo_helper';
|
2021-08-09 12:10:09 +00:00
|
|
|
import { useMockLocationHelper } from 'helpers/mock_window_location_helper';
|
|
|
|
import { shallowMountExtended } from 'helpers/vue_test_utils_helper';
|
2021-07-21 15:08:52 +00:00
|
|
|
import waitForPromises from 'helpers/wait_for_promises';
|
|
|
|
import createFlash from '~/flash';
|
2021-07-07 12:08:23 +00:00
|
|
|
|
2021-08-02 18:08:48 +00:00
|
|
|
import AdditionalMetadata from '~/packages_and_registries/package_registry/components/details/additional_metadata.vue';
|
2022-01-14 12:18:55 +00:00
|
|
|
import PackagesApp from '~/packages_and_registries/package_registry/pages/details.vue';
|
2021-08-12 15:09:58 +00:00
|
|
|
import DependencyRow from '~/packages_and_registries/package_registry/components/details/dependency_row.vue';
|
2021-08-06 12:10:15 +00:00
|
|
|
import InstallationCommands from '~/packages_and_registries/package_registry/components/details/installation_commands.vue';
|
2021-08-09 15:09:13 +00:00
|
|
|
import PackageFiles from '~/packages_and_registries/package_registry/components/details/package_files.vue';
|
2021-07-28 18:10:23 +00:00
|
|
|
import PackageHistory from '~/packages_and_registries/package_registry/components/details/package_history.vue';
|
2021-07-21 15:08:52 +00:00
|
|
|
import PackageTitle from '~/packages_and_registries/package_registry/components/details/package_title.vue';
|
2021-08-11 15:10:57 +00:00
|
|
|
import VersionRow from '~/packages_and_registries/package_registry/components/details/version_row.vue';
|
2021-10-29 12:14:45 +00:00
|
|
|
import DeletePackage from '~/packages_and_registries/package_registry/components/functional/delete_package.vue';
|
2021-08-09 12:10:09 +00:00
|
|
|
import {
|
|
|
|
FETCH_PACKAGE_DETAILS_ERROR_MESSAGE,
|
2021-08-09 15:09:13 +00:00
|
|
|
PACKAGE_TYPE_COMPOSER,
|
|
|
|
DELETE_PACKAGE_FILE_SUCCESS_MESSAGE,
|
|
|
|
DELETE_PACKAGE_FILE_ERROR_MESSAGE,
|
2021-08-12 15:09:58 +00:00
|
|
|
PACKAGE_TYPE_NUGET,
|
2021-08-09 12:10:09 +00:00
|
|
|
} from '~/packages_and_registries/package_registry/constants';
|
2021-08-09 15:09:13 +00:00
|
|
|
|
|
|
|
import destroyPackageFileMutation from '~/packages_and_registries/package_registry/graphql/mutations/destroy_package_file.mutation.graphql';
|
2021-07-21 15:08:52 +00:00
|
|
|
import getPackageDetails from '~/packages_and_registries/package_registry/graphql/queries/get_package_details.query.graphql';
|
2021-08-09 12:10:09 +00:00
|
|
|
import {
|
|
|
|
packageDetailsQuery,
|
|
|
|
packageData,
|
2021-08-11 15:10:57 +00:00
|
|
|
packageVersions,
|
2021-08-12 15:09:58 +00:00
|
|
|
dependencyLinks,
|
2021-08-09 12:10:09 +00:00
|
|
|
emptyPackageDetailsQuery,
|
2021-08-09 15:09:13 +00:00
|
|
|
packageFiles,
|
|
|
|
packageDestroyFileMutation,
|
|
|
|
packageDestroyFileMutationError,
|
2022-01-14 12:18:55 +00:00
|
|
|
} from '../mock_data';
|
2021-07-21 15:08:52 +00:00
|
|
|
|
|
|
|
jest.mock('~/flash');
|
2021-08-09 12:10:09 +00:00
|
|
|
useMockLocationHelper();
|
2021-07-21 15:08:52 +00:00
|
|
|
|
2021-07-07 12:08:23 +00:00
|
|
|
describe('PackagesApp', () => {
|
|
|
|
let wrapper;
|
2021-07-21 15:08:52 +00:00
|
|
|
let apolloProvider;
|
|
|
|
|
2022-01-14 12:18:55 +00:00
|
|
|
const breadCrumbState = {
|
|
|
|
updateName: jest.fn(),
|
|
|
|
};
|
|
|
|
|
2021-07-28 18:10:23 +00:00
|
|
|
const provide = {
|
|
|
|
packageId: '111',
|
2022-01-14 12:18:55 +00:00
|
|
|
emptyListIllustration: 'svgPath',
|
2021-07-28 18:10:23 +00:00
|
|
|
projectListUrl: 'projectListUrl',
|
|
|
|
groupListUrl: 'groupListUrl',
|
2022-01-14 12:18:55 +00:00
|
|
|
breadCrumbState,
|
2021-07-28 18:10:23 +00:00
|
|
|
};
|
|
|
|
|
2021-08-09 12:10:09 +00:00
|
|
|
function createComponent({
|
|
|
|
resolver = jest.fn().mockResolvedValue(packageDetailsQuery()),
|
2021-08-09 15:09:13 +00:00
|
|
|
fileDeleteMutationResolver = jest.fn().mockResolvedValue(packageDestroyFileMutation()),
|
2022-01-14 12:18:55 +00:00
|
|
|
routeId = '1',
|
2021-08-09 12:10:09 +00:00
|
|
|
} = {}) {
|
2022-01-25 12:14:14 +00:00
|
|
|
Vue.use(VueApollo);
|
2021-07-21 15:08:52 +00:00
|
|
|
|
2021-08-09 12:10:09 +00:00
|
|
|
const requestHandlers = [
|
|
|
|
[getPackageDetails, resolver],
|
2021-08-09 15:09:13 +00:00
|
|
|
[destroyPackageFileMutation, fileDeleteMutationResolver],
|
2021-08-09 12:10:09 +00:00
|
|
|
];
|
2021-07-21 15:08:52 +00:00
|
|
|
apolloProvider = createMockApollo(requestHandlers);
|
2021-07-07 12:08:23 +00:00
|
|
|
|
2021-08-09 12:10:09 +00:00
|
|
|
wrapper = shallowMountExtended(PackagesApp, {
|
2021-07-21 15:08:52 +00:00
|
|
|
apolloProvider,
|
2021-07-28 18:10:23 +00:00
|
|
|
provide,
|
2021-08-09 15:09:13 +00:00
|
|
|
stubs: {
|
|
|
|
PackageTitle,
|
2021-10-29 12:14:45 +00:00
|
|
|
DeletePackage,
|
2021-08-09 15:09:13 +00:00
|
|
|
GlModal: {
|
|
|
|
template: '<div></div>',
|
|
|
|
methods: {
|
|
|
|
show: jest.fn(),
|
|
|
|
},
|
|
|
|
},
|
2021-08-12 15:09:58 +00:00
|
|
|
GlTabs,
|
|
|
|
GlTab,
|
2021-08-09 15:09:13 +00:00
|
|
|
},
|
2022-01-14 12:18:55 +00:00
|
|
|
mocks: {
|
|
|
|
$route: {
|
|
|
|
params: {
|
|
|
|
id: routeId,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2021-07-07 12:08:23 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-07-21 15:08:52 +00:00
|
|
|
const findEmptyState = () => wrapper.findComponent(GlEmptyState);
|
|
|
|
const findPackageTitle = () => wrapper.findComponent(PackageTitle);
|
2021-07-28 18:10:23 +00:00
|
|
|
const findPackageHistory = () => wrapper.findComponent(PackageHistory);
|
2021-08-02 18:08:48 +00:00
|
|
|
const findAdditionalMetadata = () => wrapper.findComponent(AdditionalMetadata);
|
2021-08-06 12:10:15 +00:00
|
|
|
const findInstallationCommands = () => wrapper.findComponent(InstallationCommands);
|
2021-08-09 15:09:13 +00:00
|
|
|
const findDeleteModal = () => wrapper.findByTestId('delete-modal');
|
2021-08-09 12:10:09 +00:00
|
|
|
const findDeleteButton = () => wrapper.findByTestId('delete-package');
|
2021-08-09 15:09:13 +00:00
|
|
|
const findPackageFiles = () => wrapper.findComponent(PackageFiles);
|
|
|
|
const findDeleteFileModal = () => wrapper.findByTestId('delete-file-modal');
|
2021-08-11 15:10:57 +00:00
|
|
|
const findVersionRows = () => wrapper.findAllComponents(VersionRow);
|
|
|
|
const noVersionsMessage = () => wrapper.findByTestId('no-versions-message');
|
2021-08-12 15:09:58 +00:00
|
|
|
const findDependenciesCountBadge = () => wrapper.findComponent(GlBadge);
|
|
|
|
const findNoDependenciesMessage = () => wrapper.findByTestId('no-dependencies-message');
|
|
|
|
const findDependencyRows = () => wrapper.findAllComponents(DependencyRow);
|
2021-10-29 12:14:45 +00:00
|
|
|
const findDeletePackage = () => wrapper.findComponent(DeletePackage);
|
2021-07-07 12:08:23 +00:00
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
wrapper.destroy();
|
|
|
|
});
|
|
|
|
|
2021-07-28 18:10:23 +00:00
|
|
|
it('renders an empty state component', async () => {
|
|
|
|
createComponent({ resolver: jest.fn().mockResolvedValue(emptyPackageDetailsQuery) });
|
|
|
|
|
|
|
|
await waitForPromises();
|
2021-07-07 12:08:23 +00:00
|
|
|
|
2021-07-21 15:08:52 +00:00
|
|
|
expect(findEmptyState().exists()).toBe(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders the app and displays the package title', async () => {
|
|
|
|
createComponent();
|
|
|
|
|
|
|
|
await waitForPromises();
|
|
|
|
|
|
|
|
expect(findPackageTitle().exists()).toBe(true);
|
|
|
|
expect(findPackageTitle().props()).toMatchObject({
|
|
|
|
packageEntity: expect.objectContaining(packageData()),
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('emits an error message if the load fails', async () => {
|
|
|
|
createComponent({ resolver: jest.fn().mockRejectedValue() });
|
|
|
|
|
|
|
|
await waitForPromises();
|
|
|
|
|
|
|
|
expect(createFlash).toHaveBeenCalledWith(
|
|
|
|
expect.objectContaining({
|
|
|
|
message: FETCH_PACKAGE_DETAILS_ERROR_MESSAGE,
|
|
|
|
}),
|
|
|
|
);
|
2021-07-07 12:08:23 +00:00
|
|
|
});
|
2021-07-28 18:10:23 +00:00
|
|
|
|
|
|
|
it('renders history and has the right props', async () => {
|
|
|
|
createComponent();
|
|
|
|
|
|
|
|
await waitForPromises();
|
|
|
|
|
|
|
|
expect(findPackageHistory().exists()).toBe(true);
|
|
|
|
expect(findPackageHistory().props()).toMatchObject({
|
|
|
|
packageEntity: expect.objectContaining(packageData()),
|
2022-01-11 18:16:38 +00:00
|
|
|
projectName: packageDetailsQuery().data.package.project.name,
|
2021-07-28 18:10:23 +00:00
|
|
|
});
|
|
|
|
});
|
2021-08-02 18:08:48 +00:00
|
|
|
|
2021-08-06 12:10:15 +00:00
|
|
|
it('renders additional metadata and has the right props', async () => {
|
2021-08-02 18:08:48 +00:00
|
|
|
createComponent();
|
|
|
|
|
|
|
|
await waitForPromises();
|
|
|
|
|
|
|
|
expect(findAdditionalMetadata().exists()).toBe(true);
|
|
|
|
expect(findAdditionalMetadata().props()).toMatchObject({
|
|
|
|
packageEntity: expect.objectContaining(packageData()),
|
|
|
|
});
|
|
|
|
});
|
2021-08-06 12:10:15 +00:00
|
|
|
|
|
|
|
it('renders installation commands and has the right props', async () => {
|
|
|
|
createComponent();
|
|
|
|
|
|
|
|
await waitForPromises();
|
|
|
|
|
|
|
|
expect(findInstallationCommands().exists()).toBe(true);
|
|
|
|
expect(findInstallationCommands().props()).toMatchObject({
|
|
|
|
packageEntity: expect.objectContaining(packageData()),
|
|
|
|
});
|
|
|
|
});
|
2021-08-09 12:10:09 +00:00
|
|
|
|
2022-01-14 12:18:55 +00:00
|
|
|
it('calls the appropriate function to set the breadcrumbState', async () => {
|
|
|
|
const { name, version } = packageData();
|
|
|
|
createComponent();
|
|
|
|
|
|
|
|
await waitForPromises();
|
|
|
|
|
|
|
|
expect(breadCrumbState.updateName).toHaveBeenCalledWith(`${name} v ${version}`);
|
|
|
|
});
|
|
|
|
|
2021-08-09 12:10:09 +00:00
|
|
|
describe('delete package', () => {
|
|
|
|
const originalReferrer = document.referrer;
|
2022-01-11 18:16:38 +00:00
|
|
|
const setReferrer = (value = packageDetailsQuery().data.package.project.name) => {
|
2021-08-09 12:10:09 +00:00
|
|
|
Object.defineProperty(document, 'referrer', {
|
|
|
|
value,
|
|
|
|
configurable: true,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
Object.defineProperty(document, 'referrer', {
|
|
|
|
value: originalReferrer,
|
|
|
|
configurable: true,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('shows the delete confirmation modal when delete is clicked', async () => {
|
|
|
|
createComponent();
|
|
|
|
|
|
|
|
await waitForPromises();
|
|
|
|
|
|
|
|
await findDeleteButton().trigger('click');
|
|
|
|
|
|
|
|
expect(findDeleteModal().exists()).toBe(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('successful request', () => {
|
|
|
|
it('when referrer contains project name calls window.replace with project url', async () => {
|
|
|
|
setReferrer();
|
|
|
|
|
|
|
|
createComponent();
|
|
|
|
|
|
|
|
await waitForPromises();
|
|
|
|
|
2021-10-29 12:14:45 +00:00
|
|
|
findDeletePackage().vm.$emit('end');
|
2021-08-09 12:10:09 +00:00
|
|
|
|
|
|
|
expect(window.location.replace).toHaveBeenCalledWith(
|
|
|
|
'projectListUrl?showSuccessDeleteAlert=true',
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('when referrer does not contain project name calls window.replace with group url', async () => {
|
|
|
|
setReferrer('baz');
|
|
|
|
|
|
|
|
createComponent();
|
|
|
|
|
|
|
|
await waitForPromises();
|
|
|
|
|
2021-10-29 12:14:45 +00:00
|
|
|
findDeletePackage().vm.$emit('end');
|
2021-08-09 12:10:09 +00:00
|
|
|
|
|
|
|
expect(window.location.replace).toHaveBeenCalledWith(
|
|
|
|
'groupListUrl?showSuccessDeleteAlert=true',
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2021-08-09 15:09:13 +00:00
|
|
|
|
|
|
|
describe('package files', () => {
|
|
|
|
it('renders the package files component and has the right props', async () => {
|
|
|
|
const expectedFile = { ...packageFiles()[0] };
|
|
|
|
// eslint-disable-next-line no-underscore-dangle
|
|
|
|
delete expectedFile.__typename;
|
|
|
|
createComponent();
|
|
|
|
|
|
|
|
await waitForPromises();
|
|
|
|
|
|
|
|
expect(findPackageFiles().exists()).toBe(true);
|
|
|
|
|
|
|
|
expect(findPackageFiles().props('packageFiles')[0]).toMatchObject(expectedFile);
|
2022-01-11 18:16:38 +00:00
|
|
|
expect(findPackageFiles().props('canDelete')).toBe(packageData().canDestroy);
|
2021-08-09 15:09:13 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it('does not render the package files table when the package is composer', async () => {
|
|
|
|
createComponent({
|
|
|
|
resolver: jest
|
|
|
|
.fn()
|
|
|
|
.mockResolvedValue(packageDetailsQuery({ packageType: PACKAGE_TYPE_COMPOSER })),
|
|
|
|
});
|
|
|
|
|
|
|
|
await waitForPromises();
|
|
|
|
|
|
|
|
expect(findPackageFiles().exists()).toBe(false);
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('deleting a file', () => {
|
|
|
|
const [fileToDelete] = packageFiles();
|
|
|
|
|
|
|
|
const doDeleteFile = () => {
|
|
|
|
findPackageFiles().vm.$emit('delete-file', fileToDelete);
|
|
|
|
|
|
|
|
findDeleteFileModal().vm.$emit('primary');
|
|
|
|
|
|
|
|
return waitForPromises();
|
|
|
|
};
|
|
|
|
|
|
|
|
it('opens a confirmation modal', async () => {
|
|
|
|
createComponent();
|
|
|
|
|
|
|
|
await waitForPromises();
|
|
|
|
|
|
|
|
findPackageFiles().vm.$emit('delete-file', fileToDelete);
|
|
|
|
|
|
|
|
await nextTick();
|
|
|
|
|
|
|
|
expect(findDeleteFileModal().exists()).toBe(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('confirming on the modal deletes the file and shows a success message', async () => {
|
|
|
|
const resolver = jest.fn().mockResolvedValue(packageDetailsQuery());
|
|
|
|
createComponent({ resolver });
|
|
|
|
|
|
|
|
await waitForPromises();
|
|
|
|
|
|
|
|
await doDeleteFile();
|
|
|
|
|
|
|
|
expect(createFlash).toHaveBeenCalledWith(
|
|
|
|
expect.objectContaining({
|
|
|
|
message: DELETE_PACKAGE_FILE_SUCCESS_MESSAGE,
|
|
|
|
}),
|
|
|
|
);
|
|
|
|
// we are re-fetching the package details, so we expect the resolver to have been called twice
|
|
|
|
expect(resolver).toHaveBeenCalledTimes(2);
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('errors', () => {
|
|
|
|
it('shows an error when the mutation request fails', async () => {
|
|
|
|
createComponent({ fileDeleteMutationResolver: jest.fn().mockRejectedValue() });
|
|
|
|
await waitForPromises();
|
|
|
|
|
|
|
|
await doDeleteFile();
|
|
|
|
|
|
|
|
expect(createFlash).toHaveBeenCalledWith(
|
|
|
|
expect.objectContaining({
|
|
|
|
message: DELETE_PACKAGE_FILE_ERROR_MESSAGE,
|
|
|
|
}),
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('shows an error when the mutation request returns an error payload', async () => {
|
|
|
|
createComponent({
|
|
|
|
fileDeleteMutationResolver: jest
|
|
|
|
.fn()
|
|
|
|
.mockResolvedValue(packageDestroyFileMutationError()),
|
|
|
|
});
|
|
|
|
await waitForPromises();
|
|
|
|
|
|
|
|
await doDeleteFile();
|
|
|
|
|
|
|
|
expect(createFlash).toHaveBeenCalledWith(
|
|
|
|
expect.objectContaining({
|
|
|
|
message: DELETE_PACKAGE_FILE_ERROR_MESSAGE,
|
|
|
|
}),
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2021-08-11 15:10:57 +00:00
|
|
|
|
|
|
|
describe('versions', () => {
|
|
|
|
it('displays the correct version count when the package has versions', async () => {
|
|
|
|
createComponent();
|
|
|
|
|
|
|
|
await waitForPromises();
|
|
|
|
|
|
|
|
expect(findVersionRows()).toHaveLength(packageVersions().length);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('binds the correct props', async () => {
|
|
|
|
const [versionPackage] = packageVersions();
|
|
|
|
// eslint-disable-next-line no-underscore-dangle
|
|
|
|
delete versionPackage.__typename;
|
|
|
|
delete versionPackage.tags;
|
|
|
|
|
|
|
|
createComponent();
|
|
|
|
|
|
|
|
await waitForPromises();
|
|
|
|
|
|
|
|
expect(findVersionRows().at(0).props()).toMatchObject({
|
|
|
|
packageEntity: expect.objectContaining(versionPackage),
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('displays the no versions message when there are none', async () => {
|
|
|
|
createComponent({
|
|
|
|
resolver: jest.fn().mockResolvedValue(packageDetailsQuery({ versions: { nodes: [] } })),
|
|
|
|
});
|
|
|
|
|
|
|
|
await waitForPromises();
|
|
|
|
|
|
|
|
expect(noVersionsMessage().exists()).toBe(true);
|
|
|
|
});
|
|
|
|
});
|
2021-08-12 15:09:58 +00:00
|
|
|
describe('dependency links', () => {
|
|
|
|
it('does not show the dependency links for a non nuget package', async () => {
|
|
|
|
createComponent();
|
|
|
|
|
|
|
|
expect(findDependenciesCountBadge().exists()).toBe(false);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('shows the dependencies tab with 0 count when a nuget package with no dependencies', async () => {
|
|
|
|
createComponent({
|
|
|
|
resolver: jest.fn().mockResolvedValue(
|
|
|
|
packageDetailsQuery({
|
|
|
|
packageType: PACKAGE_TYPE_NUGET,
|
|
|
|
dependencyLinks: { nodes: [] },
|
|
|
|
}),
|
|
|
|
),
|
|
|
|
});
|
|
|
|
|
|
|
|
await waitForPromises();
|
|
|
|
|
|
|
|
expect(findDependenciesCountBadge().exists()).toBe(true);
|
|
|
|
expect(findDependenciesCountBadge().text()).toBe('0');
|
|
|
|
expect(findNoDependenciesMessage().exists()).toBe(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders the correct number of dependency rows for a nuget package', async () => {
|
|
|
|
createComponent({
|
|
|
|
resolver: jest.fn().mockResolvedValue(
|
|
|
|
packageDetailsQuery({
|
|
|
|
packageType: PACKAGE_TYPE_NUGET,
|
|
|
|
}),
|
|
|
|
),
|
|
|
|
});
|
|
|
|
await waitForPromises();
|
|
|
|
|
|
|
|
expect(findDependenciesCountBadge().exists()).toBe(true);
|
|
|
|
expect(findDependenciesCountBadge().text()).toBe(dependencyLinks().length.toString());
|
|
|
|
expect(findDependencyRows()).toHaveLength(dependencyLinks().length);
|
|
|
|
});
|
|
|
|
});
|
2021-07-07 12:08:23 +00:00
|
|
|
});
|