2020-09-30 12:09:53 +00:00
|
|
|
import { shallowMount, createLocalVue } from '@vue/test-utils';
|
|
|
|
import VueApollo from 'vue-apollo';
|
2020-04-15 15:09:17 +00:00
|
|
|
import { GlAlert, GlSprintf, GlLink } from '@gitlab/ui';
|
2020-09-30 12:09:53 +00:00
|
|
|
import createMockApollo from 'jest/helpers/mock_apollo_helper';
|
2019-12-05 12:07:43 +00:00
|
|
|
import component from '~/registry/settings/components/registry_settings_app.vue';
|
2020-09-30 12:09:53 +00:00
|
|
|
import expirationPolicyQuery from '~/registry/settings/graphql/queries/get_expiration_policy.graphql';
|
2020-01-24 15:09:00 +00:00
|
|
|
import SettingsForm from '~/registry/settings/components/settings_form.vue';
|
2020-02-03 09:08:42 +00:00
|
|
|
import { FETCH_SETTINGS_ERROR_MESSAGE } from '~/registry/shared/constants';
|
2020-07-06 09:09:20 +00:00
|
|
|
import {
|
|
|
|
UNAVAILABLE_FEATURE_INTRO_TEXT,
|
|
|
|
UNAVAILABLE_USER_FEATURE_TEXT,
|
|
|
|
} from '~/registry/settings/constants';
|
|
|
|
|
2020-10-05 09:08:17 +00:00
|
|
|
import { expirationPolicyPayload, emptyExpirationPolicyPayload } from '../mock_data';
|
2020-09-30 12:09:53 +00:00
|
|
|
|
|
|
|
const localVue = createLocalVue();
|
2019-12-05 12:07:43 +00:00
|
|
|
|
2019-12-19 12:07:35 +00:00
|
|
|
describe('Registry Settings App', () => {
|
2019-12-05 12:07:43 +00:00
|
|
|
let wrapper;
|
2020-09-30 12:09:53 +00:00
|
|
|
let fakeApollo;
|
|
|
|
|
|
|
|
const defaultProvidedValues = {
|
|
|
|
projectPath: 'path',
|
|
|
|
isAdmin: false,
|
|
|
|
adminSettingsPath: 'settingsPath',
|
|
|
|
enableHistoricEntries: false,
|
|
|
|
};
|
2019-12-05 12:07:43 +00:00
|
|
|
|
2020-01-24 15:09:00 +00:00
|
|
|
const findSettingsComponent = () => wrapper.find(SettingsForm);
|
|
|
|
const findAlert = () => wrapper.find(GlAlert);
|
2019-12-05 12:07:43 +00:00
|
|
|
|
2020-09-30 12:09:53 +00:00
|
|
|
const mountComponent = (provide = defaultProvidedValues, config) => {
|
2019-12-19 12:07:35 +00:00
|
|
|
wrapper = shallowMount(component, {
|
2020-04-15 15:09:17 +00:00
|
|
|
stubs: {
|
|
|
|
GlSprintf,
|
|
|
|
},
|
2020-01-21 18:07:31 +00:00
|
|
|
mocks: {
|
|
|
|
$toast: {
|
|
|
|
show: jest.fn(),
|
|
|
|
},
|
2019-12-19 12:07:35 +00:00
|
|
|
},
|
2020-09-30 12:09:53 +00:00
|
|
|
provide,
|
|
|
|
...config,
|
2019-12-05 12:07:43 +00:00
|
|
|
});
|
2019-12-19 12:07:35 +00:00
|
|
|
};
|
2019-12-05 12:07:43 +00:00
|
|
|
|
2020-09-30 12:09:53 +00:00
|
|
|
const mountComponentWithApollo = ({ provide = defaultProvidedValues, resolver } = {}) => {
|
|
|
|
localVue.use(VueApollo);
|
|
|
|
|
|
|
|
const requestHandlers = [[expirationPolicyQuery, resolver]];
|
|
|
|
|
|
|
|
fakeApollo = createMockApollo(requestHandlers);
|
|
|
|
mountComponent(provide, {
|
|
|
|
localVue,
|
|
|
|
apolloProvider: fakeApollo,
|
|
|
|
});
|
|
|
|
|
|
|
|
return requestHandlers.map(request => request[1]);
|
|
|
|
};
|
2020-04-15 15:09:17 +00:00
|
|
|
|
2019-12-05 12:07:43 +00:00
|
|
|
afterEach(() => {
|
|
|
|
wrapper.destroy();
|
|
|
|
});
|
|
|
|
|
2020-09-30 12:09:53 +00:00
|
|
|
it('renders the setting form', async () => {
|
|
|
|
const requests = mountComponentWithApollo({
|
|
|
|
resolver: jest.fn().mockResolvedValue(expirationPolicyPayload()),
|
|
|
|
});
|
|
|
|
await Promise.all(requests);
|
2019-12-19 12:07:35 +00:00
|
|
|
|
|
|
|
expect(findSettingsComponent().exists()).toBe(true);
|
2019-12-05 12:07:43 +00:00
|
|
|
});
|
2020-01-24 15:09:00 +00:00
|
|
|
|
2020-04-15 15:09:17 +00:00
|
|
|
describe('the form is disabled', () => {
|
2020-09-30 12:09:53 +00:00
|
|
|
it('the form is hidden', () => {
|
2020-04-15 15:09:17 +00:00
|
|
|
mountComponent();
|
2020-01-24 15:09:00 +00:00
|
|
|
|
|
|
|
expect(findSettingsComponent().exists()).toBe(false);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('shows an alert', () => {
|
2020-09-30 12:09:53 +00:00
|
|
|
mountComponent();
|
|
|
|
|
2020-04-15 15:09:17 +00:00
|
|
|
const text = findAlert().text();
|
2020-07-06 09:09:20 +00:00
|
|
|
expect(text).toContain(UNAVAILABLE_FEATURE_INTRO_TEXT);
|
|
|
|
expect(text).toContain(UNAVAILABLE_USER_FEATURE_TEXT);
|
2020-04-15 15:09:17 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('an admin is visiting the page', () => {
|
|
|
|
it('shows the admin part of the alert message', () => {
|
2020-09-30 12:09:53 +00:00
|
|
|
mountComponent({ ...defaultProvidedValues, isAdmin: true });
|
|
|
|
|
2020-04-15 15:09:17 +00:00
|
|
|
const sprintf = findAlert().find(GlSprintf);
|
|
|
|
expect(sprintf.text()).toBe('administration settings');
|
2020-09-30 12:09:53 +00:00
|
|
|
expect(sprintf.find(GlLink).attributes('href')).toBe(
|
|
|
|
defaultProvidedValues.adminSettingsPath,
|
|
|
|
);
|
2020-04-15 15:09:17 +00:00
|
|
|
});
|
2020-03-16 09:09:29 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('fetchSettingsError', () => {
|
|
|
|
beforeEach(() => {
|
2020-09-30 12:09:53 +00:00
|
|
|
const requests = mountComponentWithApollo({
|
|
|
|
resolver: jest.fn().mockRejectedValue(new Error('GraphQL error')),
|
|
|
|
});
|
|
|
|
return Promise.all(requests);
|
2020-03-16 09:09:29 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it('the form is hidden', () => {
|
|
|
|
expect(findSettingsComponent().exists()).toBe(false);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('shows an alert', () => {
|
|
|
|
expect(findAlert().html()).toContain(FETCH_SETTINGS_ERROR_MESSAGE);
|
2020-01-24 15:09:00 +00:00
|
|
|
});
|
|
|
|
});
|
2020-10-05 09:08:17 +00:00
|
|
|
|
|
|
|
describe('empty API response', () => {
|
|
|
|
it.each`
|
|
|
|
enableHistoricEntries | isShown
|
|
|
|
${true} | ${true}
|
|
|
|
${false} | ${false}
|
|
|
|
`('is $isShown that the form is shown', async ({ enableHistoricEntries, isShown }) => {
|
|
|
|
const requests = mountComponentWithApollo({
|
|
|
|
provide: {
|
|
|
|
...defaultProvidedValues,
|
|
|
|
enableHistoricEntries,
|
|
|
|
},
|
|
|
|
resolver: jest.fn().mockResolvedValue(emptyExpirationPolicyPayload()),
|
|
|
|
});
|
|
|
|
await Promise.all(requests);
|
|
|
|
|
|
|
|
expect(findSettingsComponent().exists()).toBe(isShown);
|
|
|
|
});
|
|
|
|
});
|
2019-12-05 12:07:43 +00:00
|
|
|
});
|