Commit d1ba509e authored by Vitaly Slobodin's avatar Vitaly Slobodin

Merge branch '324688-form-clear' into 'master'

Fix: Do not clear rotation form on validation error

See merge request gitlab-org/gitlab!56901
parents fbc56222 1f1d3a38
......@@ -306,13 +306,17 @@ export default {
},
beforeShowModal() {
if (this.isEditMode) {
this.parseRotation();
return this.parseRotation();
}
return this.resetModal();
},
resetModal() {
this.form = cloneDeep(formEmptyState);
this.validationState = cloneDeep(validiationInitialState);
this.error = '';
if (!this.isLoading) {
this.form = cloneDeep(formEmptyState);
this.validationState = cloneDeep(validiationInitialState);
this.error = '';
}
},
parseRotation() {
const scheduleTimezone = this.schedule.timezone;
......
---
title: Do not clear the oncall schedule rotation form if there are validation errors
merge_request: 56901
author:
type: fixed
......@@ -131,7 +131,6 @@ describe('AddEditRotationModal', () => {
afterEach(() => {
wrapper.destroy();
wrapper = null;
});
const findModal = () => wrapper.findComponent(GlModal);
......@@ -143,16 +142,22 @@ describe('AddEditRotationModal', () => {
});
describe('Rotation create', () => {
it('makes a request with `oncallRotationCreate` to create a schedule rotation', () => {
beforeEach(() => {
createComponent({ data: { form: { name: mockRotation.name } } });
});
it('makes a request with `oncallRotationCreate` to create a schedule rotation and clears the form', async () => {
mutate.mockResolvedValueOnce({});
findModal().vm.$emit('primary', { preventDefault: jest.fn() });
expect(mutate).toHaveBeenCalledWith({
mutation: expect.any(Object),
variables: { input: expect.objectContaining({ projectPath }) },
});
await wrapper.vm.$nextTick();
expect(findForm().props('form').name).toBe(undefined);
});
it('does not hide the rotation modal and shows error alert on fail', async () => {
it('does not hide the rotation modal and shows error alert on fail and does not clear the form', async () => {
const error = 'some error';
mutate.mockResolvedValueOnce({ data: { oncallRotationCreate: { errors: [error] } } });
findModal().vm.$emit('primary', { preventDefault: jest.fn() });
......@@ -160,6 +165,7 @@ describe('AddEditRotationModal', () => {
expect(mockHideModal).not.toHaveBeenCalled();
expect(findAlert().exists()).toBe(true);
expect(findAlert().text()).toContain(error);
expect(findForm().props('form').name).toBe(mockRotation.name);
});
describe('Validation', () => {
......
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