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 { ...@@ -306,13 +306,17 @@ export default {
}, },
beforeShowModal() { beforeShowModal() {
if (this.isEditMode) { if (this.isEditMode) {
this.parseRotation(); return this.parseRotation();
} }
return this.resetModal();
}, },
resetModal() { resetModal() {
this.form = cloneDeep(formEmptyState); if (!this.isLoading) {
this.validationState = cloneDeep(validiationInitialState); this.form = cloneDeep(formEmptyState);
this.error = ''; this.validationState = cloneDeep(validiationInitialState);
this.error = '';
}
}, },
parseRotation() { parseRotation() {
const scheduleTimezone = this.schedule.timezone; 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', () => { ...@@ -131,7 +131,6 @@ describe('AddEditRotationModal', () => {
afterEach(() => { afterEach(() => {
wrapper.destroy(); wrapper.destroy();
wrapper = null;
}); });
const findModal = () => wrapper.findComponent(GlModal); const findModal = () => wrapper.findComponent(GlModal);
...@@ -143,16 +142,22 @@ describe('AddEditRotationModal', () => { ...@@ -143,16 +142,22 @@ describe('AddEditRotationModal', () => {
}); });
describe('Rotation create', () => { 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({}); mutate.mockResolvedValueOnce({});
findModal().vm.$emit('primary', { preventDefault: jest.fn() }); findModal().vm.$emit('primary', { preventDefault: jest.fn() });
expect(mutate).toHaveBeenCalledWith({ expect(mutate).toHaveBeenCalledWith({
mutation: expect.any(Object), mutation: expect.any(Object),
variables: { input: expect.objectContaining({ projectPath }) }, 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'; const error = 'some error';
mutate.mockResolvedValueOnce({ data: { oncallRotationCreate: { errors: [error] } } }); mutate.mockResolvedValueOnce({ data: { oncallRotationCreate: { errors: [error] } } });
findModal().vm.$emit('primary', { preventDefault: jest.fn() }); findModal().vm.$emit('primary', { preventDefault: jest.fn() });
...@@ -160,6 +165,7 @@ describe('AddEditRotationModal', () => { ...@@ -160,6 +165,7 @@ describe('AddEditRotationModal', () => {
expect(mockHideModal).not.toHaveBeenCalled(); expect(mockHideModal).not.toHaveBeenCalled();
expect(findAlert().exists()).toBe(true); expect(findAlert().exists()).toBe(true);
expect(findAlert().text()).toContain(error); expect(findAlert().text()).toContain(error);
expect(findForm().props('form').name).toBe(mockRotation.name);
}); });
describe('Validation', () => { 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