@@ -27,6 +27,7 @@ import { Collection } from '../../../core/shared/collection.model';
2727import { SectionExternalUploadComponent } from './section-external-upload.component' ;
2828import { ExternalUploadService } from './external-upload.service' ;
2929import { ExternalServiceStub } from './external-upload-service.mock' ;
30+ import { PathableObjectError } from '../../../core/data/response-state.model' ;
3031
3132function getMockCollectionDataService ( ) : CollectionDataService {
3233 return jasmine . createSpyObj ( 'CollectionDataService' , {
@@ -148,6 +149,7 @@ describe('SectionExternalUploadComponent test suite', () => {
148149 collectionDataService = TestBed . inject ( CollectionDataService ) ;
149150 externalUploadService = TestBed . inject ( ExternalUploadService ) ;
150151 compAsAny . pathCombiner = new JsonPatchOperationPathCombiner ( 'sections' , sectionObject . id ) ;
152+ compAsAny . errors$ = observableOf ( [ ] ) ;
151153 } ) ;
152154
153155 afterEach ( ( ) => {
@@ -175,7 +177,7 @@ describe('SectionExternalUploadComponent test suite', () => {
175177 expect ( fixture . debugElement . query ( By . css ( 'button' ) ) . nativeElement . disabled ) . toBeTruthy ( ) ;
176178 } ) ;
177179
178- it ( 'Should execute upload is source is present' , ( ) => {
180+ it ( 'Should execute upload if source is present' , ( ) => {
179181 spyOn ( compAsAny , 'submitUpload' ) ;
180182 comp . loading$ = of ( false ) ;
181183
@@ -191,6 +193,23 @@ describe('SectionExternalUploadComponent test suite', () => {
191193 expect ( fixture . debugElement . query ( By . css ( 'button' ) ) . nativeElement . disabled ) . toBeFalsy ( ) ;
192194 expect ( compAsAny . submitUpload ) . toHaveBeenCalled ( ) ;
193195 } ) ;
196+
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+ } ) ;
194213 } ) ;
195214
196215} ) ;
0 commit comments