mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-08 10:34:15 +00:00
[835] Auto-save in new Item Submission form breaks the form
Section Metadata field tested. Form Touched filter tested.
This commit is contained in:
@@ -60,6 +60,21 @@ export const mockSectionsErrors = [
|
||||
}
|
||||
];
|
||||
|
||||
export const mockSectionsErrorsTwo = [
|
||||
{
|
||||
message: 'error.validation.required',
|
||||
paths: [
|
||||
'/sections/traditionalpageone/dc.title',
|
||||
]
|
||||
},
|
||||
{
|
||||
message: 'error.validation.license.notgranted',
|
||||
paths: [
|
||||
'/sections/license'
|
||||
]
|
||||
}
|
||||
];
|
||||
|
||||
export const mockUploadResponse1Errors = {
|
||||
errors: [
|
||||
{
|
||||
@@ -1033,6 +1048,7 @@ export const mockSubmissionState: SubmissionObjectState = Object.assign({}, {
|
||||
enabled: true,
|
||||
data: {},
|
||||
errors: [],
|
||||
formId: '2_traditionalpageone',
|
||||
isLoading: false,
|
||||
isValid: false
|
||||
} as any,
|
||||
|
@@ -32,7 +32,7 @@ import {
|
||||
mockSubmissionId,
|
||||
mockSubmissionSelfUrl,
|
||||
mockSubmissionState,
|
||||
mockSubmissionRestResponse
|
||||
mockSubmissionRestResponse, mockSectionsErrorsTwo
|
||||
} from '../../shared/mocks/submission.mock';
|
||||
import { SubmissionSectionModel } from '../../core/config/models/config-submission-section.model';
|
||||
import { NotificationsServiceStub } from '../../shared/testing/notifications-service.stub';
|
||||
@@ -51,6 +51,7 @@ import { Item } from '../../core/shared/item.model';
|
||||
import { WorkspaceitemDataService } from '../../core/submission/workspaceitem-data.service';
|
||||
import { WorkflowItemDataService } from '../../core/submission/workflowitem-data.service';
|
||||
import { HALEndpointService } from '../../core/shared/hal-endpoint.service';
|
||||
import {formStateSelector} from '../../shared/form/selectors';
|
||||
|
||||
describe('SubmissionObjectEffects test suite', () => {
|
||||
let submissionObjectEffects: SubmissionObjectEffects;
|
||||
@@ -343,7 +344,8 @@ describe('SubmissionObjectEffects test suite', () => {
|
||||
type: SubmissionObjectActionTypes.SAVE_SUBMISSION_FORM_SUCCESS,
|
||||
payload: {
|
||||
submissionId: submissionId,
|
||||
submissionObject: response
|
||||
submissionObject: response,
|
||||
notify: true
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -375,6 +377,63 @@ describe('SubmissionObjectEffects test suite', () => {
|
||||
|
||||
});
|
||||
|
||||
it('should not display errors when notification are disabled and field are not touched', () => {
|
||||
store.nextState({
|
||||
submission: {
|
||||
objects: submissionState
|
||||
},
|
||||
forms: {
|
||||
'2_traditionalpageone': {
|
||||
additional: {
|
||||
touched: {
|
||||
'dc.title': true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} as any);
|
||||
|
||||
const response = [Object.assign({}, mockSubmissionRestResponse[0], {
|
||||
sections: mockSectionsData,
|
||||
errors: mockSectionsErrors
|
||||
})];
|
||||
actions = hot('--a-', {
|
||||
a: {
|
||||
type: SubmissionObjectActionTypes.SAVE_SUBMISSION_SECTION_FORM_SUCCESS,
|
||||
payload: {
|
||||
submissionId: submissionId,
|
||||
submissionObject: response,
|
||||
notify: false
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
const errorsList = parseSectionErrors(mockSectionsErrorsTwo);
|
||||
const expected = cold('--(bcd)-', {
|
||||
b: new UpdateSectionDataAction(
|
||||
submissionId,
|
||||
'traditionalpageone',
|
||||
mockSectionsData.traditionalpageone as any,
|
||||
errorsList.traditionalpageone
|
||||
),
|
||||
c: new UpdateSectionDataAction(
|
||||
submissionId,
|
||||
'license',
|
||||
mockSectionsData.license as any,
|
||||
errorsList.license || []
|
||||
),
|
||||
d: new UpdateSectionDataAction(
|
||||
submissionId,
|
||||
'upload',
|
||||
mockSectionsData.upload as any,
|
||||
errorsList.upload || []
|
||||
),
|
||||
});
|
||||
|
||||
expect(submissionObjectEffects.saveSubmissionSectionSuccess$).toBeObservable(expected);
|
||||
expect(notificationsServiceStub.warning).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should display a success notification', () => {
|
||||
store.nextState({
|
||||
submission: {
|
||||
|
@@ -335,6 +335,17 @@ describe('submissionReducer test suite', () => {
|
||||
expect(newState[826].sections.traditionalpageone.data).toEqual(data);
|
||||
});
|
||||
|
||||
it('should update submission section metadata properly', () => {
|
||||
const data = {
|
||||
} as any;
|
||||
const metadata = ['dc.title', 'dc.contributor.author'];
|
||||
|
||||
const action = new UpdateSectionDataAction(submissionId, 'traditionalpageone', data, [], metadata);
|
||||
const newState = submissionObjectReducer(initState, action);
|
||||
|
||||
expect(newState[826].sections.traditionalpageone.metadata).toEqual(metadata);
|
||||
});
|
||||
|
||||
it('should add submission section errors properly', () => {
|
||||
const errors = [
|
||||
{
|
||||
|
Reference in New Issue
Block a user