Skip to content

Commit 7c20e7d

Browse files
committed
[UXP-147] Add test for refactoring external upload
1 parent 4595f14 commit 7c20e7d

6 files changed

Lines changed: 69 additions & 33 deletions

File tree

src/app/shared/mocks/submission.mock.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3079,6 +3079,21 @@ export const mockSubmissionState: SubmissionObjectState = Object.assign({}, {
30793079
isValid: false,
30803080
removePending: false
30813081
} as any,
3082+
'external-upload': {
3083+
header: 'submit.progressbar.external-upload',
3084+
config: 'https://rest.api/dspace-spring-rest/api/config/submissionuploads/external-upload',
3085+
mandatory: true,
3086+
sectionType: 'external-upload',
3087+
collapsed: false,
3088+
enabled: true,
3089+
data: {
3090+
files: []
3091+
},
3092+
errorsToShow: [],
3093+
isLoading: false,
3094+
isValid: false,
3095+
removePending: false
3096+
} as any,
30823097
'upload': {
30833098
header: 'submit.progressbar.upload',
30843099
config: 'https://rest.api/dspace-spring-rest/api/config/submissionuploads/upload',
@@ -3117,7 +3132,6 @@ export const mockSubmissionState: SubmissionObjectState = Object.assign({}, {
31173132
savePending: false,
31183133
depositPending: false,
31193134
externalUploadPending: false,
3120-
externalUploadErrors: []
31213135
}
31223136
});
31233137

src/app/submission/objects/submission-objects.actions.ts

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
WorkspaceitemSectionDataType,
1010
WorkspaceitemSectionsObject
1111
} from '../../core/submission/models/workspaceitem-sections.model';
12-
import { SubmissionObject, SubmissionObjectError } from '../../core/submission/models/submission-object.model';
12+
import { SubmissionObject } from '../../core/submission/models/submission-object.model';
1313
import { SubmissionDefinitionsModel } from '../../core/config/models/config-submission-definitions.model';
1414
import { SectionsType } from '../sections/sections-type';
1515
import { Item } from '../../core/shared/item.model';
@@ -1067,7 +1067,6 @@ export class ExecuteExternalUploadSuccessAction implements Action {
10671067
payload: {
10681068
submissionId: string;
10691069
sectionId: string;
1070-
sectionsObject: WorkspaceitemSectionsObject;
10711070
};
10721071

10731072
/**
@@ -1076,11 +1075,9 @@ export class ExecuteExternalUploadSuccessAction implements Action {
10761075
* @param submissionId
10771076
* the submission's ID
10781077
* @param sectionId
1079-
* the section's ID
1080-
* @param sectionsObject
10811078
*/
1082-
constructor(submissionId: string, sectionId: string, sectionsObject: WorkspaceitemSectionsObject) {
1083-
this.payload = { submissionId, sectionId, sectionsObject };
1079+
constructor(submissionId: string, sectionId: string) {
1080+
this.payload = { submissionId, sectionId };
10841081
}
10851082
}
10861083

@@ -1089,7 +1086,7 @@ export class ExecuteExternalUploadErrorAction implements Action {
10891086
payload: {
10901087
submissionId: string;
10911088
sectionId: string;
1092-
errors: SubmissionObjectError[]
1089+
errors: SubmissionSectionError[]
10931090
};
10941091

10951092
/**
@@ -1102,7 +1099,7 @@ export class ExecuteExternalUploadErrorAction implements Action {
11021099
* @param errors
11031100
* the section's ID
11041101
*/
1105-
constructor(submissionId: string, sectionId: string, errors: SubmissionObjectError[]) {
1102+
constructor(submissionId: string, sectionId: string, errors: SubmissionSectionError[]) {
11061103
this.payload = { submissionId, sectionId, errors };
11071104
}
11081105
}

src/app/submission/objects/submission-objects.effects.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,6 @@ export class SubmissionObjectEffects {
413413
actions.push(new ExecuteExternalUploadSuccessAction(
414414
action.payload.submissionId,
415415
action.payload.sectionId,
416-
null
417416
));
418417
return actions;
419418
}

src/app/submission/objects/submission-objects.reducer.spec.ts

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ import {
1414
DiscardSubmissionSuccessAction,
1515
EditFileDataAction,
1616
EnableSectionAction,
17+
ExecuteExternalUploadAction,
18+
ExecuteExternalUploadErrorAction,
19+
ExecuteExternalUploadSuccessAction,
1720
InertSectionErrorsAction,
1821
InitSectionAction,
1922
InitSubmissionFormAction,
@@ -88,7 +91,6 @@ describe('submissionReducer test suite', () => {
8891
savePending: false,
8992
saveDecisionPending: false,
9093
externalUploadPending: false,
91-
externalUploadErrors: [],
9294
depositPending: false,
9395
metadataSecurityConfiguration: metadataSecurityConfiguration as any,
9496
}
@@ -125,7 +127,6 @@ describe('submissionReducer test suite', () => {
125127
savePending: false,
126128
depositPending: false,
127129
externalUploadPending: false,
128-
externalUploadErrors: []
129130
}
130131
};
131132

@@ -752,4 +753,48 @@ describe('submissionReducer test suite', () => {
752753
expect(newState[826].saveDecisionPending).toBeFalsy();
753754
});
754755

756+
it('should set the externalUploadPending to true', () => {
757+
const action: any = new ExecuteExternalUploadAction(submissionId, 'external-upload');
758+
let newState;
759+
760+
newState = submissionObjectReducer(initState, action);
761+
762+
expect(newState[826].externalUploadPending).toBeTrue();
763+
});
764+
765+
it('should set the errors fo the external Upload section', () => {
766+
const errors = [{
767+
path: '/sections/external-upload',
768+
message: 'error.validation.notfound'
769+
}];
770+
const action: any = new ExecuteExternalUploadErrorAction(submissionId, 'external-upload', errors);
771+
772+
const newState = submissionObjectReducer(initState, action);
773+
774+
expect(newState[826].externalUploadPending).toBeFalse();
775+
expect(newState[826].sections['external-upload'].errorsToShow).toEqual(errors);
776+
expect(newState[826].sections['external-upload'].serverValidationErrors).toEqual(errors);
777+
});
778+
779+
it('should clean the errors fo the external Upload section', () => {
780+
const errors = [{
781+
path: '/sections/external-upload',
782+
message: 'error.validation.notfound'
783+
}];
784+
let action: any = new ExecuteExternalUploadErrorAction(submissionId, 'external-upload', errors);
785+
let newState = submissionObjectReducer(initState, action);
786+
787+
expect(newState[826].externalUploadPending).toBeFalse();
788+
expect(newState[826].sections['external-upload'].errorsToShow).toEqual(errors);
789+
expect(newState[826].sections['external-upload'].serverValidationErrors).toEqual(errors);
790+
791+
action = new ExecuteExternalUploadSuccessAction(submissionId, 'external-upload');
792+
793+
newState = submissionObjectReducer(initState, action);
794+
795+
expect(newState[826].externalUploadPending).toBeFalse();
796+
expect(newState[826].sections['external-upload'].errorsToShow).toEqual([]);
797+
expect(newState[826].sections['external-upload'].serverValidationErrors).toEqual([]);
798+
});
799+
755800
});

src/app/submission/objects/submission-objects.reducer.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ import {
5454
} from '../../core/submission/models/workspaceitem-section-deduplication.model';
5555
import { SubmissionSectionObject } from './submission-section-object.model';
5656
import { MetadataSecurityConfiguration } from '../../core/submission/models/metadata-security-configuration';
57-
import { SubmissionObjectError } from '../../core/submission/models/submission-object.model';
57+
import { SubmissionSectionError } from './submission-section-error.model';
5858

5959
/**
6060
* An interface to represent SubmissionSectionObject entry
@@ -1131,7 +1131,7 @@ function startExternalUploadExecution(state: SubmissionObjectState, action: Exec
11311131
* @return SubmissionObjectState
11321132
* the new state, with the decision flag changed.
11331133
*/
1134-
function updateExternalUploadState(state: SubmissionObjectState, submissionId: string, sectionId: string, errors: SubmissionObjectError[]): SubmissionObjectState {
1134+
function updateExternalUploadState(state: SubmissionObjectState, submissionId: string, sectionId: string, errors: SubmissionSectionError[]): SubmissionObjectState {
11351135
if (isNotEmpty(state[ submissionId ])
11361136
&& isNotEmpty(state[ submissionId ].sections[ sectionId])) {
11371137
return Object.assign({}, state, {

src/app/submission/sections/external-upload/section-external-upload.component.spec.ts

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ import { Collection } from '../../../core/shared/collection.model';
2727
import { SectionExternalUploadComponent } from './section-external-upload.component';
2828
import { ExternalUploadService } from './external-upload.service';
2929
import { ExternalServiceStub } from './external-upload-service.mock';
30-
import { PathableObjectError } from '../../../core/data/response-state.model';
3130

3231
function getMockCollectionDataService(): CollectionDataService {
3332
return jasmine.createSpyObj('CollectionDataService', {
@@ -49,8 +48,6 @@ const sectionObject: SectionDataObject = {
4948
sectionVisibility: null
5049
};
5150

52-
53-
5451
describe('SectionExternalUploadComponent test suite', () => {
5552
let comp: SectionExternalUploadComponent;
5653
let compAsAny: any;
@@ -194,22 +191,6 @@ describe('SectionExternalUploadComponent test suite', () => {
194191
expect(compAsAny.submitUpload).toHaveBeenCalled();
195192
});
196193

197-
it('Should display errors if present', () => {
198-
const errorObj = [{message:'Test error message', paths: ['external-upload']} as PathableObjectError];
199-
spyOn(compAsAny, 'submitUpload');
200-
comp.loading$ = of(false);
201-
comp.errors$ = of(errorObj);
202-
203-
comp.onSectionInit();
204-
comp.source = '/path/to/file';
205-
comp.submissionId = 'subId';
206-
207-
fixture.detectChanges();
208-
209-
const errorElement = fixture.debugElement.query(By.css('.text-danger')).nativeElement;
210-
expect(errorElement.innerHTML).toEqual(' ' + errorObj[0].message + ' ');
211-
212-
});
213194
});
214195

215196
});

0 commit comments

Comments
 (0)