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