mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-10 03:23:07 +00:00
[835] Auto-save in new Item Submission form breaks the form
Tests fixed.
This commit is contained in:
@@ -119,7 +119,8 @@ function init() {
|
||||
dc_identifier_issn: null
|
||||
},
|
||||
valid: false,
|
||||
errors: []
|
||||
errors: [],
|
||||
additional: {}
|
||||
}
|
||||
};
|
||||
|
||||
|
@@ -21,7 +21,8 @@ describe('formReducer', () => {
|
||||
description: null
|
||||
},
|
||||
valid: false,
|
||||
errors: []
|
||||
errors: [],
|
||||
additional: {}
|
||||
}
|
||||
};
|
||||
const formId = 'testForm';
|
||||
@@ -48,7 +49,8 @@ describe('formReducer', () => {
|
||||
description: null
|
||||
},
|
||||
valid: false,
|
||||
errors: []
|
||||
errors: [],
|
||||
additional: {}
|
||||
}
|
||||
};
|
||||
const formId = 'testForm';
|
||||
@@ -67,7 +69,8 @@ describe('formReducer', () => {
|
||||
description: null
|
||||
},
|
||||
valid: false,
|
||||
errors: []
|
||||
errors: [],
|
||||
additional: {}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -88,7 +91,8 @@ describe('formReducer', () => {
|
||||
description: null
|
||||
},
|
||||
valid: false,
|
||||
errors: []
|
||||
errors: [],
|
||||
additional: {}
|
||||
}
|
||||
};
|
||||
const state = {
|
||||
@@ -100,7 +104,8 @@ describe('formReducer', () => {
|
||||
description: null
|
||||
},
|
||||
valid: false,
|
||||
errors: []
|
||||
errors: [],
|
||||
additional: {}
|
||||
}
|
||||
};
|
||||
const formId = 'testForm';
|
||||
@@ -127,7 +132,8 @@ describe('formReducer', () => {
|
||||
description: null
|
||||
},
|
||||
valid: false,
|
||||
errors: []
|
||||
errors: [],
|
||||
additional: {}
|
||||
}
|
||||
};
|
||||
const state = {
|
||||
@@ -139,7 +145,8 @@ describe('formReducer', () => {
|
||||
description: null
|
||||
},
|
||||
valid: true,
|
||||
errors: []
|
||||
errors: [],
|
||||
additional: {}
|
||||
}
|
||||
};
|
||||
const formId = 'testForm';
|
||||
@@ -160,7 +167,8 @@ describe('formReducer', () => {
|
||||
description: null
|
||||
},
|
||||
valid: true,
|
||||
errors: []
|
||||
errors: [],
|
||||
additional: {}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -204,7 +212,8 @@ describe('formReducer', () => {
|
||||
fieldIndex: 0,
|
||||
message: 'error.validation.required'
|
||||
}
|
||||
]
|
||||
],
|
||||
additional: {}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -236,7 +245,8 @@ describe('formReducer', () => {
|
||||
description: null
|
||||
},
|
||||
valid: true,
|
||||
errors: []
|
||||
errors: [],
|
||||
additional: {}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -264,7 +274,8 @@ describe('formReducer', () => {
|
||||
fieldIndex: 0,
|
||||
message: 'error.validation.required'
|
||||
}
|
||||
]
|
||||
],
|
||||
additional: {}
|
||||
}
|
||||
};
|
||||
|
||||
|
@@ -84,7 +84,8 @@ describe('FormService test suite', () => {
|
||||
testForm: {
|
||||
data: formData,
|
||||
valid: false,
|
||||
errors: []
|
||||
errors: [],
|
||||
additional: {}
|
||||
}
|
||||
};
|
||||
|
||||
|
@@ -2,6 +2,7 @@ export class SectionsServiceStub {
|
||||
|
||||
checkSectionErrors = jasmine.createSpy('checkSectionErrors');
|
||||
dispatchRemoveSectionErrors = jasmine.createSpy('dispatchRemoveSectionErrors');
|
||||
dispatchSetSectionFormId = jasmine.createSpy('dispatchSetSectionFormId');
|
||||
getSectionData = jasmine.createSpy('getSectionData');
|
||||
getSectionErrors = jasmine.createSpy('getSectionErrors');
|
||||
getSectionState = jasmine.createSpy('getSectionState');
|
||||
@@ -14,5 +15,5 @@ export class SectionsServiceStub {
|
||||
updateSectionData = jasmine.createSpy('updateSectionData');
|
||||
setSectionError = jasmine.createSpy('setSectionError');
|
||||
setSectionStatus = jasmine.createSpy('setSectionStatus');
|
||||
|
||||
computeSectionConfiguredMetadata = jasmine.createSpy('computeSectionConfiguredMetadata');
|
||||
}
|
||||
|
@@ -551,7 +551,7 @@ describe('SubmissionObjectEffects test suite', () => {
|
||||
submissionId,
|
||||
'traditionalpageone',
|
||||
mockSectionsData.traditionalpageone as any,
|
||||
errorsList.traditionalpageone || []
|
||||
[]
|
||||
),
|
||||
c: new UpdateSectionDataAction(
|
||||
submissionId,
|
||||
@@ -638,12 +638,13 @@ describe('SubmissionObjectEffects test suite', () => {
|
||||
});
|
||||
|
||||
const errorsList = parseSectionErrors(mockSectionsErrors);
|
||||
console.log(errorsList);
|
||||
const expected = cold('--(bcd)-', {
|
||||
b: new UpdateSectionDataAction(
|
||||
submissionId,
|
||||
'traditionalpageone',
|
||||
mockSectionsData.traditionalpageone as any,
|
||||
errorsList.traditionalpageone || []
|
||||
[]
|
||||
),
|
||||
c: new UpdateSectionDataAction(
|
||||
submissionId,
|
||||
@@ -679,7 +680,7 @@ describe('SubmissionObjectEffects test suite', () => {
|
||||
type: SubmissionObjectActionTypes.SAVE_SUBMISSION_SECTION_FORM_SUCCESS,
|
||||
payload: {
|
||||
submissionId: submissionId,
|
||||
submissionObject: response
|
||||
submissionObject: response,
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -690,7 +691,7 @@ describe('SubmissionObjectEffects test suite', () => {
|
||||
submissionId,
|
||||
'traditionalpageone',
|
||||
mockSectionsDataTwo.traditionalpageone as any,
|
||||
errorsList.traditionalpageone || []
|
||||
[]
|
||||
),
|
||||
c: new UpdateSectionDataAction(
|
||||
submissionId,
|
||||
|
@@ -410,9 +410,8 @@ export class SubmissionObjectEffects {
|
||||
this.submissionService.notifyNewSection(submissionId, sectionId, currentState.sections[sectionId].sectionType);
|
||||
}
|
||||
|
||||
const sectionForm = forms[currentState.sections[sectionId].formId];
|
||||
const sectionForm = getForm(forms, currentState, sectionId);
|
||||
const filteredErrors = filterErrors(sectionForm, sectionErrors, currentState.sections[sectionId].sectionType, notify);
|
||||
|
||||
mappedActions.push(new UpdateSectionDataAction(submissionId, sectionId, sectionData, filteredErrors));
|
||||
}
|
||||
});
|
||||
@@ -421,6 +420,15 @@ export class SubmissionObjectEffects {
|
||||
}
|
||||
}
|
||||
|
||||
function getForm(forms, currentState, sectionId) {
|
||||
if (!forms) {
|
||||
return null;
|
||||
}
|
||||
const formId = currentState.sections[sectionId].formId;
|
||||
return forms[formId];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Filter sectionErrors accordingly to this rules:
|
||||
* 1. if notifications are enabled return all errors
|
||||
|
@@ -287,6 +287,7 @@ describe('SubmissionSectionformComponent test suite', () => {
|
||||
'dc.title': [new FormFieldMetadataValueObject('test')]
|
||||
};
|
||||
compAsAny.formData = {};
|
||||
compAsAny.sectionMetadata = ['dc.title'];
|
||||
|
||||
expect(comp.hasMetadataEnrichment(newSectionData)).toBeTruthy();
|
||||
});
|
||||
@@ -296,7 +297,7 @@ describe('SubmissionSectionformComponent test suite', () => {
|
||||
'dc.title': [new FormFieldMetadataValueObject('test')]
|
||||
};
|
||||
compAsAny.formData = newSectionData;
|
||||
|
||||
compAsAny.sectionMetadata = ['dc.title'];
|
||||
expect(comp.hasMetadataEnrichment(newSectionData)).toBeFalsy();
|
||||
});
|
||||
|
||||
@@ -310,6 +311,7 @@ describe('SubmissionSectionformComponent test suite', () => {
|
||||
comp.sectionData.data = {};
|
||||
comp.sectionData.errors = [];
|
||||
compAsAny.formData = {};
|
||||
compAsAny.sectionMetadata = ['dc.title'];
|
||||
|
||||
comp.updateForm(sectionData, sectionError);
|
||||
|
||||
@@ -329,10 +331,11 @@ describe('SubmissionSectionformComponent test suite', () => {
|
||||
comp.sectionData.data = {};
|
||||
comp.sectionData.errors = [];
|
||||
compAsAny.formData = sectionData;
|
||||
compAsAny.sectionMetadata = ['dc.title'];
|
||||
|
||||
comp.updateForm(sectionData, parsedSectionErrors);
|
||||
|
||||
expect(comp.initForm).toHaveBeenCalled();
|
||||
expect(comp.initForm).not.toHaveBeenCalled();
|
||||
expect(comp.checksForErrors).toHaveBeenCalled();
|
||||
expect(comp.sectionData.data).toEqual(sectionData);
|
||||
});
|
||||
|
Reference in New Issue
Block a user