2021-09-30 15:12:24 +00:00
|
|
|
import { GlAlert } from '@gitlab/ui';
|
2022-01-25 12:14:14 +00:00
|
|
|
import { shallowMount } from '@vue/test-utils';
|
|
|
|
import Vue, { nextTick } from 'vue';
|
2021-01-20 12:11:06 +00:00
|
|
|
import VueApollo from 'vue-apollo';
|
2022-01-25 12:14:14 +00:00
|
|
|
|
2021-01-20 12:11:06 +00:00
|
|
|
import createMockApollo from 'helpers/mock_apollo_helper';
|
2021-02-05 12:09:31 +00:00
|
|
|
import waitForPromises from 'helpers/wait_for_promises';
|
2021-09-30 15:12:24 +00:00
|
|
|
import PackagesSettings from '~/packages_and_registries/settings/group/components/packages_settings.vue';
|
2021-10-13 15:12:51 +00:00
|
|
|
import DependencyProxySettings from '~/packages_and_registries/settings/group/components/dependency_proxy_settings.vue';
|
2021-09-30 15:12:24 +00:00
|
|
|
|
2021-02-05 12:09:31 +00:00
|
|
|
import component from '~/packages_and_registries/settings/group/components/group_settings_app.vue';
|
2021-09-30 15:12:24 +00:00
|
|
|
|
2021-02-14 18:09:20 +00:00
|
|
|
import getGroupPackagesSettingsQuery from '~/packages_and_registries/settings/group/graphql/queries/get_group_packages_settings.query.graphql';
|
2021-12-07 21:14:42 +00:00
|
|
|
import {
|
|
|
|
groupPackageSettingsMock,
|
|
|
|
packageSettings,
|
|
|
|
dependencyProxySettings,
|
|
|
|
dependencyProxyImageTtlPolicy,
|
|
|
|
} from '../mock_data';
|
2021-02-05 12:09:31 +00:00
|
|
|
|
|
|
|
jest.mock('~/flash');
|
2021-01-20 12:11:06 +00:00
|
|
|
|
|
|
|
describe('Group Settings App', () => {
|
|
|
|
let wrapper;
|
|
|
|
let apolloProvider;
|
2021-02-09 18:09:59 +00:00
|
|
|
let show;
|
2021-01-20 12:11:06 +00:00
|
|
|
|
|
|
|
const defaultProvide = {
|
|
|
|
groupPath: 'foo_group_path',
|
|
|
|
};
|
|
|
|
|
|
|
|
const mountComponent = ({
|
|
|
|
resolver = jest.fn().mockResolvedValue(groupPackageSettingsMock),
|
2021-10-13 15:12:51 +00:00
|
|
|
provide = defaultProvide,
|
2021-01-20 12:11:06 +00:00
|
|
|
} = {}) => {
|
2022-01-25 12:14:14 +00:00
|
|
|
Vue.use(VueApollo);
|
2021-01-20 12:11:06 +00:00
|
|
|
|
2021-09-30 15:12:24 +00:00
|
|
|
const requestHandlers = [[getGroupPackagesSettingsQuery, resolver]];
|
2021-01-20 12:11:06 +00:00
|
|
|
|
|
|
|
apolloProvider = createMockApollo(requestHandlers);
|
|
|
|
|
|
|
|
wrapper = shallowMount(component, {
|
|
|
|
apolloProvider,
|
2021-10-13 15:12:51 +00:00
|
|
|
provide,
|
2021-02-09 18:09:59 +00:00
|
|
|
mocks: {
|
|
|
|
$toast: {
|
|
|
|
show,
|
|
|
|
},
|
|
|
|
},
|
2021-01-20 12:11:06 +00:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2021-02-09 18:09:59 +00:00
|
|
|
beforeEach(() => {
|
|
|
|
show = jest.fn();
|
|
|
|
});
|
|
|
|
|
2021-01-20 12:11:06 +00:00
|
|
|
afterEach(() => {
|
|
|
|
wrapper.destroy();
|
|
|
|
});
|
|
|
|
|
2021-05-12 12:10:24 +00:00
|
|
|
const findAlert = () => wrapper.findComponent(GlAlert);
|
2021-09-30 15:12:24 +00:00
|
|
|
const findPackageSettings = () => wrapper.findComponent(PackagesSettings);
|
2021-10-13 15:12:51 +00:00
|
|
|
const findDependencyProxySettings = () => wrapper.findComponent(DependencyProxySettings);
|
2021-02-05 12:09:31 +00:00
|
|
|
|
|
|
|
const waitForApolloQueryAndRender = async () => {
|
|
|
|
await waitForPromises();
|
2021-09-30 15:12:24 +00:00
|
|
|
await nextTick();
|
2021-02-05 12:09:31 +00:00
|
|
|
};
|
2021-01-20 12:11:06 +00:00
|
|
|
|
2021-12-07 21:14:42 +00:00
|
|
|
const packageSettingsProps = { packageSettings: packageSettings() };
|
|
|
|
const dependencyProxyProps = {
|
|
|
|
dependencyProxySettings: dependencyProxySettings(),
|
|
|
|
dependencyProxyImageTtlPolicy: dependencyProxyImageTtlPolicy(),
|
|
|
|
};
|
|
|
|
|
2021-09-30 15:12:24 +00:00
|
|
|
describe.each`
|
2021-12-07 21:14:42 +00:00
|
|
|
finder | entitySpecificProps | successMessage | errorMessage
|
|
|
|
${findPackageSettings} | ${packageSettingsProps} | ${'Settings saved successfully'} | ${'An error occurred while saving the settings'}
|
|
|
|
${findDependencyProxySettings} | ${dependencyProxyProps} | ${'Setting saved successfully'} | ${'An error occurred while saving the setting'}
|
|
|
|
`('settings blocks', ({ finder, entitySpecificProps, successMessage, errorMessage }) => {
|
2021-09-30 15:12:24 +00:00
|
|
|
beforeEach(() => {
|
2021-05-12 12:10:24 +00:00
|
|
|
mountComponent();
|
2021-09-30 15:12:24 +00:00
|
|
|
return waitForApolloQueryAndRender();
|
2021-05-12 12:10:24 +00:00
|
|
|
});
|
|
|
|
|
2021-09-30 15:12:24 +00:00
|
|
|
it('renders the settings block', () => {
|
|
|
|
expect(finder().exists()).toBe(true);
|
2021-05-12 12:10:24 +00:00
|
|
|
});
|
|
|
|
|
2021-09-30 15:12:24 +00:00
|
|
|
it('binds the correctProps', () => {
|
|
|
|
expect(finder().props()).toMatchObject({
|
|
|
|
isLoading: false,
|
2021-12-07 21:14:42 +00:00
|
|
|
...entitySpecificProps,
|
2021-05-12 12:10:24 +00:00
|
|
|
});
|
|
|
|
});
|
2021-02-05 12:09:31 +00:00
|
|
|
|
2021-09-30 15:12:24 +00:00
|
|
|
describe('success event', () => {
|
|
|
|
it('shows a success toast', () => {
|
|
|
|
finder().vm.$emit('success');
|
2021-10-13 15:12:51 +00:00
|
|
|
expect(show).toHaveBeenCalledWith(successMessage);
|
2021-02-05 12:09:31 +00:00
|
|
|
});
|
|
|
|
|
2021-09-30 15:12:24 +00:00
|
|
|
it('hides the error alert', async () => {
|
|
|
|
finder().vm.$emit('error');
|
|
|
|
await nextTick();
|
2021-02-05 12:09:31 +00:00
|
|
|
|
2021-02-09 18:09:59 +00:00
|
|
|
expect(findAlert().exists()).toBe(true);
|
2021-02-05 12:09:31 +00:00
|
|
|
|
2021-09-30 15:12:24 +00:00
|
|
|
finder().vm.$emit('success');
|
|
|
|
await nextTick();
|
2021-02-09 18:09:59 +00:00
|
|
|
|
2021-09-30 15:12:24 +00:00
|
|
|
expect(findAlert().exists()).toBe(false);
|
2021-02-05 12:09:31 +00:00
|
|
|
});
|
2021-09-30 15:12:24 +00:00
|
|
|
});
|
2021-02-05 12:09:31 +00:00
|
|
|
|
2021-09-30 15:12:24 +00:00
|
|
|
describe('error event', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
finder().vm.$emit('error');
|
|
|
|
return nextTick();
|
2021-02-05 12:09:31 +00:00
|
|
|
});
|
|
|
|
|
2021-09-30 15:12:24 +00:00
|
|
|
it('shows an alert', () => {
|
2021-02-09 18:09:59 +00:00
|
|
|
expect(findAlert().exists()).toBe(true);
|
|
|
|
});
|
|
|
|
|
2021-09-30 15:12:24 +00:00
|
|
|
it('alert has the right text', () => {
|
2021-10-13 15:12:51 +00:00
|
|
|
expect(findAlert().text()).toBe(errorMessage);
|
2021-09-30 15:12:24 +00:00
|
|
|
});
|
2021-02-09 18:09:59 +00:00
|
|
|
|
2021-09-30 15:12:24 +00:00
|
|
|
it('dismissing the alert removes it', async () => {
|
2021-02-09 18:09:59 +00:00
|
|
|
expect(findAlert().exists()).toBe(true);
|
|
|
|
|
|
|
|
findAlert().vm.$emit('dismiss');
|
|
|
|
|
2021-09-30 15:12:24 +00:00
|
|
|
await nextTick();
|
2021-02-09 18:09:59 +00:00
|
|
|
|
|
|
|
expect(findAlert().exists()).toBe(false);
|
2021-02-05 12:09:31 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2021-01-20 12:11:06 +00:00
|
|
|
});
|