2022-01-25 12:14:14 +00:00
|
|
|
import Vue, { nextTick } from 'vue';
|
2022-08-26 03:12:38 +00:00
|
|
|
import { GlToggle } from '@gitlab/ui';
|
2021-09-30 15:12:24 +00:00
|
|
|
import VueApollo from 'vue-apollo';
|
2022-08-26 03:12:38 +00:00
|
|
|
import { mountExtended, shallowMountExtended } from 'helpers/vue_test_utils_helper';
|
2021-09-30 15:12:24 +00:00
|
|
|
import createMockApollo from 'helpers/mock_apollo_helper';
|
|
|
|
import waitForPromises from 'helpers/wait_for_promises';
|
2022-08-26 03:12:38 +00:00
|
|
|
import ExceptionsInput from '~/packages_and_registries/settings/group/components/exceptions_input.vue';
|
2021-09-30 15:12:24 +00:00
|
|
|
import component from '~/packages_and_registries/settings/group/components/packages_settings.vue';
|
|
|
|
import {
|
2022-08-26 03:12:38 +00:00
|
|
|
DUPLICATES_TOGGLE_LABEL,
|
2021-09-30 15:12:24 +00:00
|
|
|
PACKAGE_SETTINGS_HEADER,
|
|
|
|
PACKAGE_SETTINGS_DESCRIPTION,
|
|
|
|
} from '~/packages_and_registries/settings/group/constants';
|
|
|
|
|
|
|
|
import updateNamespacePackageSettings from '~/packages_and_registries/settings/group/graphql/mutations/update_group_packages_settings.mutation.graphql';
|
|
|
|
import getGroupPackagesSettingsQuery from '~/packages_and_registries/settings/group/graphql/queries/get_group_packages_settings.query.graphql';
|
|
|
|
import SettingsBlock from '~/vue_shared/components/settings/settings_block.vue';
|
|
|
|
import { updateGroupPackagesSettingsOptimisticResponse } from '~/packages_and_registries/settings/group/graphql/utils/optimistic_responses';
|
|
|
|
import {
|
|
|
|
packageSettings,
|
|
|
|
groupPackageSettingsMock,
|
|
|
|
groupPackageSettingsMutationMock,
|
|
|
|
groupPackageSettingsMutationErrorMock,
|
|
|
|
} from '../mock_data';
|
|
|
|
|
|
|
|
jest.mock('~/flash');
|
|
|
|
jest.mock('~/packages_and_registries/settings/group/graphql/utils/optimistic_responses');
|
|
|
|
|
|
|
|
describe('Packages Settings', () => {
|
|
|
|
let wrapper;
|
|
|
|
let apolloProvider;
|
|
|
|
|
|
|
|
const defaultProvide = {
|
|
|
|
groupPath: 'foo_group_path',
|
|
|
|
};
|
|
|
|
|
|
|
|
const mountComponent = ({
|
2022-08-26 03:12:38 +00:00
|
|
|
mountFn = shallowMountExtended,
|
2021-09-30 15:12:24 +00:00
|
|
|
mutationResolver = jest.fn().mockResolvedValue(groupPackageSettingsMutationMock()),
|
|
|
|
} = {}) => {
|
2022-01-25 12:14:14 +00:00
|
|
|
Vue.use(VueApollo);
|
2021-09-30 15:12:24 +00:00
|
|
|
|
|
|
|
const requestHandlers = [[updateNamespacePackageSettings, mutationResolver]];
|
|
|
|
|
|
|
|
apolloProvider = createMockApollo(requestHandlers);
|
|
|
|
|
2022-08-26 03:12:38 +00:00
|
|
|
wrapper = mountFn(component, {
|
2021-09-30 15:12:24 +00:00
|
|
|
apolloProvider,
|
|
|
|
provide: defaultProvide,
|
|
|
|
propsData: {
|
|
|
|
packageSettings: packageSettings(),
|
|
|
|
},
|
|
|
|
stubs: {
|
|
|
|
SettingsBlock,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
wrapper.destroy();
|
|
|
|
});
|
|
|
|
|
|
|
|
const findSettingsBlock = () => wrapper.findComponent(SettingsBlock);
|
|
|
|
const findDescription = () => wrapper.findByTestId('description');
|
2022-08-26 03:12:38 +00:00
|
|
|
const findMavenSettings = () => wrapper.findByTestId('maven-settings');
|
|
|
|
const findGenericSettings = () => wrapper.findByTestId('generic-settings');
|
|
|
|
|
|
|
|
const findMavenDuplicatedSettingsToggle = () => findMavenSettings().findComponent(GlToggle);
|
|
|
|
const findGenericDuplicatedSettingsToggle = () => findGenericSettings().findComponent(GlToggle);
|
|
|
|
const findMavenDuplicatedSettingsExceptionsInput = () =>
|
|
|
|
findMavenSettings().findComponent(ExceptionsInput);
|
|
|
|
const findGenericDuplicatedSettingsExceptionsInput = () =>
|
|
|
|
findGenericSettings().findComponent(ExceptionsInput);
|
2021-09-30 15:12:24 +00:00
|
|
|
|
|
|
|
const fillApolloCache = () => {
|
|
|
|
apolloProvider.defaultClient.cache.writeQuery({
|
|
|
|
query: getGroupPackagesSettingsQuery,
|
|
|
|
variables: {
|
|
|
|
fullPath: defaultProvide.groupPath,
|
|
|
|
},
|
|
|
|
...groupPackageSettingsMock,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
const emitMavenSettingsUpdate = (override) => {
|
2022-08-26 03:12:38 +00:00
|
|
|
findGenericDuplicatedSettingsExceptionsInput().vm.$emit('update', {
|
2021-09-30 15:12:24 +00:00
|
|
|
mavenDuplicateExceptionRegex: ')',
|
|
|
|
...override,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
it('renders a settings block', () => {
|
|
|
|
mountComponent();
|
|
|
|
|
|
|
|
expect(findSettingsBlock().exists()).toBe(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('has the correct header text', () => {
|
|
|
|
mountComponent();
|
|
|
|
|
|
|
|
expect(wrapper.text()).toContain(PACKAGE_SETTINGS_HEADER);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('has the correct description text', () => {
|
|
|
|
mountComponent();
|
|
|
|
|
|
|
|
expect(findDescription().text()).toMatchInterpolatedText(PACKAGE_SETTINGS_DESCRIPTION);
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('maven settings', () => {
|
|
|
|
it('exists', () => {
|
2022-08-26 03:12:38 +00:00
|
|
|
mountComponent({ mountFn: mountExtended });
|
|
|
|
|
|
|
|
expect(findMavenSettings().find('td').text()).toBe('Maven');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders toggle', () => {
|
|
|
|
mountComponent({ mountFn: mountExtended });
|
2021-09-30 15:12:24 +00:00
|
|
|
|
2022-08-26 03:12:38 +00:00
|
|
|
const { mavenDuplicatesAllowed } = packageSettings();
|
|
|
|
|
|
|
|
expect(findMavenDuplicatedSettingsToggle().exists()).toBe(true);
|
|
|
|
|
|
|
|
expect(findMavenDuplicatedSettingsToggle().props()).toMatchObject({
|
|
|
|
label: DUPLICATES_TOGGLE_LABEL,
|
|
|
|
value: mavenDuplicatesAllowed,
|
|
|
|
disabled: false,
|
|
|
|
labelPosition: 'hidden',
|
|
|
|
});
|
2021-09-30 15:12:24 +00:00
|
|
|
});
|
|
|
|
|
2022-08-26 03:12:38 +00:00
|
|
|
it('renders ExceptionsInput and assigns duplication allowness and exception props', () => {
|
|
|
|
mountComponent({ mountFn: mountExtended });
|
2021-09-30 15:12:24 +00:00
|
|
|
|
|
|
|
const { mavenDuplicatesAllowed, mavenDuplicateExceptionRegex } = packageSettings();
|
|
|
|
|
2022-08-26 03:12:38 +00:00
|
|
|
expect(findMavenDuplicatedSettingsExceptionsInput().exists()).toBe(true);
|
|
|
|
|
|
|
|
expect(findMavenDuplicatedSettingsExceptionsInput().props()).toMatchObject({
|
2021-09-30 15:12:24 +00:00
|
|
|
duplicatesAllowed: mavenDuplicatesAllowed,
|
|
|
|
duplicateExceptionRegex: mavenDuplicateExceptionRegex,
|
|
|
|
duplicateExceptionRegexError: '',
|
|
|
|
loading: false,
|
2022-08-26 03:12:38 +00:00
|
|
|
name: 'mavenDuplicateExceptionRegex',
|
|
|
|
id: 'maven-duplicated-settings-regex-input',
|
2021-09-30 15:12:24 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('on update event calls the mutation', () => {
|
|
|
|
const mutationResolver = jest.fn().mockResolvedValue(groupPackageSettingsMutationMock());
|
2022-08-26 03:12:38 +00:00
|
|
|
mountComponent({ mountFn: mountExtended, mutationResolver });
|
2021-09-30 15:12:24 +00:00
|
|
|
|
|
|
|
fillApolloCache();
|
|
|
|
|
|
|
|
emitMavenSettingsUpdate();
|
|
|
|
|
|
|
|
expect(mutationResolver).toHaveBeenCalledWith({
|
|
|
|
input: { mavenDuplicateExceptionRegex: ')', namespacePath: 'foo_group_path' },
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('generic settings', () => {
|
|
|
|
it('exists', () => {
|
2022-08-26 03:12:38 +00:00
|
|
|
mountComponent({ mountFn: mountExtended });
|
2021-09-30 15:12:24 +00:00
|
|
|
|
2022-08-26 03:12:38 +00:00
|
|
|
expect(findGenericSettings().find('td').text()).toBe('Generic');
|
2021-09-30 15:12:24 +00:00
|
|
|
});
|
|
|
|
|
2022-08-26 03:12:38 +00:00
|
|
|
it('renders toggle', () => {
|
|
|
|
mountComponent({ mountFn: mountExtended });
|
|
|
|
|
|
|
|
const { genericDuplicatesAllowed } = packageSettings();
|
|
|
|
|
|
|
|
expect(findGenericDuplicatedSettingsToggle().exists()).toBe(true);
|
|
|
|
expect(findGenericDuplicatedSettingsToggle().props()).toMatchObject({
|
|
|
|
label: DUPLICATES_TOGGLE_LABEL,
|
|
|
|
value: genericDuplicatesAllowed,
|
|
|
|
disabled: false,
|
|
|
|
labelPosition: 'hidden',
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders ExceptionsInput and assigns duplication allowness and exception props', async () => {
|
|
|
|
mountComponent({ mountFn: mountExtended });
|
2021-09-30 15:12:24 +00:00
|
|
|
|
|
|
|
const { genericDuplicatesAllowed, genericDuplicateExceptionRegex } = packageSettings();
|
|
|
|
|
2022-08-26 03:12:38 +00:00
|
|
|
expect(findGenericDuplicatedSettingsExceptionsInput().props()).toMatchObject({
|
2021-09-30 15:12:24 +00:00
|
|
|
duplicatesAllowed: genericDuplicatesAllowed,
|
|
|
|
duplicateExceptionRegex: genericDuplicateExceptionRegex,
|
|
|
|
duplicateExceptionRegexError: '',
|
|
|
|
loading: false,
|
2022-08-26 03:12:38 +00:00
|
|
|
name: 'genericDuplicateExceptionRegex',
|
|
|
|
id: 'generic-duplicated-settings-regex-input',
|
2021-09-30 15:12:24 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('on update event calls the mutation', async () => {
|
|
|
|
const mutationResolver = jest.fn().mockResolvedValue(groupPackageSettingsMutationMock());
|
2022-08-26 03:12:38 +00:00
|
|
|
mountComponent({ mountFn: mountExtended, mutationResolver });
|
2021-09-30 15:12:24 +00:00
|
|
|
|
|
|
|
fillApolloCache();
|
|
|
|
|
2022-08-26 03:12:38 +00:00
|
|
|
findGenericDuplicatedSettingsExceptionsInput().vm.$emit('update', {
|
2021-09-30 15:12:24 +00:00
|
|
|
genericDuplicateExceptionRegex: ')',
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(mutationResolver).toHaveBeenCalledWith({
|
|
|
|
input: { genericDuplicateExceptionRegex: ')', namespacePath: 'foo_group_path' },
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('settings update', () => {
|
|
|
|
describe('success state', () => {
|
2022-08-26 03:12:38 +00:00
|
|
|
beforeEach(() => {
|
|
|
|
mountComponent({ mountFn: mountExtended });
|
|
|
|
});
|
2021-09-30 15:12:24 +00:00
|
|
|
|
2022-08-26 03:12:38 +00:00
|
|
|
it('emits a success event', async () => {
|
2021-09-30 15:12:24 +00:00
|
|
|
fillApolloCache();
|
|
|
|
emitMavenSettingsUpdate();
|
|
|
|
|
|
|
|
await waitForPromises();
|
|
|
|
|
|
|
|
expect(wrapper.emitted('success')).toEqual([[]]);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('has an optimistic response', () => {
|
|
|
|
const mavenDuplicateExceptionRegex = 'latest[main]something';
|
|
|
|
|
|
|
|
fillApolloCache();
|
|
|
|
|
2022-08-26 03:12:38 +00:00
|
|
|
expect(
|
|
|
|
findGenericDuplicatedSettingsExceptionsInput().props('duplicateExceptionRegex'),
|
|
|
|
).toBe('');
|
2021-09-30 15:12:24 +00:00
|
|
|
|
|
|
|
emitMavenSettingsUpdate({ mavenDuplicateExceptionRegex });
|
|
|
|
|
|
|
|
expect(updateGroupPackagesSettingsOptimisticResponse).toHaveBeenCalledWith({
|
|
|
|
...packageSettings(),
|
|
|
|
mavenDuplicateExceptionRegex,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('errors', () => {
|
|
|
|
it('mutation payload with root level errors', async () => {
|
|
|
|
// note this is a complex test that covers all the path around errors that are shown in the form
|
|
|
|
// it's one single it case, due to the expensive preparation and execution
|
|
|
|
const mutationResolver = jest.fn().mockResolvedValue(groupPackageSettingsMutationErrorMock);
|
2022-08-26 03:12:38 +00:00
|
|
|
mountComponent({ mountFn: mountExtended, mutationResolver });
|
2021-09-30 15:12:24 +00:00
|
|
|
|
|
|
|
fillApolloCache();
|
|
|
|
|
|
|
|
emitMavenSettingsUpdate();
|
|
|
|
|
|
|
|
await waitForPromises();
|
|
|
|
|
|
|
|
// errors are bound to the component
|
2022-08-26 03:12:38 +00:00
|
|
|
expect(
|
|
|
|
findMavenDuplicatedSettingsExceptionsInput().props('duplicateExceptionRegexError'),
|
|
|
|
).toBe(groupPackageSettingsMutationErrorMock.errors[0].extensions.problems[0].message);
|
2021-09-30 15:12:24 +00:00
|
|
|
|
|
|
|
// general error message is shown
|
|
|
|
|
|
|
|
expect(wrapper.emitted('error')).toEqual([[]]);
|
|
|
|
|
|
|
|
emitMavenSettingsUpdate();
|
|
|
|
|
2022-01-25 12:14:14 +00:00
|
|
|
await nextTick();
|
2021-09-30 15:12:24 +00:00
|
|
|
|
|
|
|
// errors are reset on mutation call
|
2022-08-26 03:12:38 +00:00
|
|
|
expect(
|
|
|
|
findMavenDuplicatedSettingsExceptionsInput().props('duplicateExceptionRegexError'),
|
|
|
|
).toBe('');
|
2021-09-30 15:12:24 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it.each`
|
|
|
|
type | mutationResolver
|
|
|
|
${'local'} | ${jest.fn().mockResolvedValue(groupPackageSettingsMutationMock({ errors: ['foo'] }))}
|
|
|
|
${'network'} | ${jest.fn().mockRejectedValue()}
|
|
|
|
`('mutation payload with $type error', async ({ mutationResolver }) => {
|
2022-08-26 03:12:38 +00:00
|
|
|
mountComponent({ mountFn: mountExtended, mutationResolver });
|
2021-09-30 15:12:24 +00:00
|
|
|
|
|
|
|
fillApolloCache();
|
|
|
|
emitMavenSettingsUpdate();
|
|
|
|
|
|
|
|
await waitForPromises();
|
|
|
|
|
|
|
|
expect(wrapper.emitted('error')).toEqual([[]]);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|