Commit 9d7a4e31 authored by Natalia Tepluhina's avatar Natalia Tepluhina

Merge branch '325429-container-registry-cleanup-policy-wiped-all-images' into 'master'

Always save default on empty values in Exp Policies

See merge request gitlab-org/gitlab!57470
parents 6febe89a f4134d95
...@@ -110,12 +110,12 @@ export default { ...@@ -110,12 +110,12 @@ export default {
mutationVariables() { mutationVariables() {
return { return {
projectPath: this.projectPath, projectPath: this.projectPath,
enabled: this.value.enabled, enabled: this.prefilledForm.enabled,
cadence: this.value.cadence, cadence: this.prefilledForm.cadence,
olderThan: this.value.olderThan, olderThan: this.prefilledForm.olderThan,
keepN: this.value.keepN, keepN: this.prefilledForm.keepN,
nameRegex: this.value.nameRegex, nameRegex: this.prefilledForm.nameRegex,
nameRegexKeep: this.value.nameRegexKeep, nameRegexKeep: this.prefilledForm.nameRegexKeep,
}; };
}, },
}, },
......
---
title: Always save default on empty values in Exp Policies
merge_request: 57470
author:
type: fixed
...@@ -77,33 +77,47 @@ describe('Settings Form', () => { ...@@ -77,33 +77,47 @@ describe('Settings Form', () => {
}); });
}; };
const mountComponentWithApollo = ({ provide = defaultProvidedValues, resolver } = {}) => { const mountComponentWithApollo = ({
provide = defaultProvidedValues,
mutationResolver,
queryPayload = expirationPolicyPayload(),
} = {}) => {
localVue.use(VueApollo); localVue.use(VueApollo);
const requestHandlers = [ const requestHandlers = [
[updateContainerExpirationPolicyMutation, resolver], [updateContainerExpirationPolicyMutation, mutationResolver],
[expirationPolicyQuery, jest.fn().mockResolvedValue(expirationPolicyPayload())], [expirationPolicyQuery, jest.fn().mockResolvedValue(queryPayload)],
]; ];
fakeApollo = createMockApollo(requestHandlers); fakeApollo = createMockApollo(requestHandlers);
// This component does not do the query directly, but we need a proper cache to update
fakeApollo.defaultClient.cache.writeQuery({ fakeApollo.defaultClient.cache.writeQuery({
query: expirationPolicyQuery, query: expirationPolicyQuery,
variables: { variables: {
projectPath: provide.projectPath, projectPath: provide.projectPath,
}, },
...expirationPolicyPayload(), ...queryPayload,
}); });
// we keep in sync what prop we pass to the component with the cache
const {
data: {
project: { containerExpirationPolicy: value },
},
} = queryPayload;
mountComponent({ mountComponent({
provide, provide,
props: {
...defaultProps,
value,
},
config: { config: {
localVue, localVue,
apolloProvider: fakeApollo, apolloProvider: fakeApollo,
}, },
}); });
return requestHandlers.map((resolvers) => resolvers[1]);
}; };
beforeEach(() => { beforeEach(() => {
...@@ -253,19 +267,44 @@ describe('Settings Form', () => { ...@@ -253,19 +267,44 @@ describe('Settings Form', () => {
expect(findSaveButton().attributes('type')).toBe('submit'); expect(findSaveButton().attributes('type')).toBe('submit');
}); });
it('dispatches the correct apollo mutation', async () => { it('dispatches the correct apollo mutation', () => {
const [expirationPolicyMutationResolver] = mountComponentWithApollo({ const mutationResolver = jest.fn().mockResolvedValue(expirationPolicyMutationPayload());
resolver: jest.fn().mockResolvedValue(expirationPolicyMutationPayload()), mountComponentWithApollo({
mutationResolver,
}); });
findForm().trigger('submit'); findForm().trigger('submit');
await expirationPolicyMutationResolver();
expect(expirationPolicyMutationResolver).toHaveBeenCalled(); expect(mutationResolver).toHaveBeenCalled();
});
it('saves the default values when a value is missing did not change the default options', async () => {
const mutationResolver = jest.fn().mockResolvedValue(expirationPolicyMutationPayload());
mountComponentWithApollo({
mutationResolver,
queryPayload: expirationPolicyPayload({ keepN: null, cadence: null, olderThan: null }),
});
await waitForPromises();
findForm().trigger('submit');
expect(mutationResolver).toHaveBeenCalledWith({
input: {
cadence: 'EVERY_DAY',
enabled: true,
keepN: 'TEN_TAGS',
nameRegex: 'asdasdssssdfdf',
nameRegexKeep: 'sss',
olderThan: 'NINETY_DAYS',
projectPath: 'path',
},
});
}); });
it('tracks the submit event', () => { it('tracks the submit event', () => {
mountComponentWithApollo({ mountComponentWithApollo({
resolver: jest.fn().mockResolvedValue(expirationPolicyMutationPayload()), mutationResolver: jest.fn().mockResolvedValue(expirationPolicyMutationPayload()),
}); });
findForm().trigger('submit'); findForm().trigger('submit');
...@@ -274,12 +313,12 @@ describe('Settings Form', () => { ...@@ -274,12 +313,12 @@ describe('Settings Form', () => {
}); });
it('show a success toast when submit succeed', async () => { it('show a success toast when submit succeed', async () => {
const handlers = mountComponentWithApollo({ mountComponentWithApollo({
resolver: jest.fn().mockResolvedValue(expirationPolicyMutationPayload()), mutationResolver: jest.fn().mockResolvedValue(expirationPolicyMutationPayload()),
}); });
findForm().trigger('submit'); findForm().trigger('submit');
await Promise.all(handlers); await waitForPromises();
await wrapper.vm.$nextTick(); await wrapper.vm.$nextTick();
expect(wrapper.vm.$toast.show).toHaveBeenCalledWith(UPDATE_SETTINGS_SUCCESS_MESSAGE, { expect(wrapper.vm.$toast.show).toHaveBeenCalledWith(UPDATE_SETTINGS_SUCCESS_MESSAGE, {
...@@ -290,14 +329,14 @@ describe('Settings Form', () => { ...@@ -290,14 +329,14 @@ describe('Settings Form', () => {
describe('when submit fails', () => { describe('when submit fails', () => {
describe('user recoverable errors', () => { describe('user recoverable errors', () => {
it('when there is an error is shown in a toast', async () => { it('when there is an error is shown in a toast', async () => {
const handlers = mountComponentWithApollo({ mountComponentWithApollo({
resolver: jest mutationResolver: jest
.fn() .fn()
.mockResolvedValue(expirationPolicyMutationPayload({ errors: ['foo'] })), .mockResolvedValue(expirationPolicyMutationPayload({ errors: ['foo'] })),
}); });
findForm().trigger('submit'); findForm().trigger('submit');
await Promise.all(handlers); await waitForPromises();
await wrapper.vm.$nextTick(); await wrapper.vm.$nextTick();
expect(wrapper.vm.$toast.show).toHaveBeenCalledWith('foo', { expect(wrapper.vm.$toast.show).toHaveBeenCalledWith('foo', {
...@@ -308,13 +347,12 @@ describe('Settings Form', () => { ...@@ -308,13 +347,12 @@ describe('Settings Form', () => {
describe('global errors', () => { describe('global errors', () => {
it('shows an error', async () => { it('shows an error', async () => {
const handlers = mountComponentWithApollo({ mountComponentWithApollo({
resolver: jest.fn().mockRejectedValue(expirationPolicyMutationPayload()), mutationResolver: jest.fn().mockRejectedValue(expirationPolicyMutationPayload()),
}); });
findForm().trigger('submit'); findForm().trigger('submit');
await Promise.all(handlers); await waitForPromises();
await wrapper.vm.$nextTick();
await wrapper.vm.$nextTick(); await wrapper.vm.$nextTick();
expect(wrapper.vm.$toast.show).toHaveBeenCalledWith(UPDATE_SETTINGS_ERROR_MESSAGE, { expect(wrapper.vm.$toast.show).toHaveBeenCalledWith(UPDATE_SETTINGS_ERROR_MESSAGE, {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment