@@ -86,10 +86,18 @@ describe('BatchImportPageComponent', () => {
8686 let fileMock : File ;
8787
8888 beforeEach ( ( ) => {
89+ component . isUpload = true ;
8990 fileMock = new File ( [ '' ] , 'filename.zip' , { type : 'application/zip' } ) ;
9091 component . setFile ( fileMock ) ;
9192 } ) ;
9293
94+ it ( 'should show the file dropzone' , ( ) => {
95+ const fileDropzone = fixture . debugElement . query ( By . css ( '[data-test="file-dropzone"]' ) ) ;
96+ const fileUrlInput = fixture . debugElement . query ( By . css ( '[data-test="file-url-input"]' ) ) ;
97+ expect ( fileDropzone ) . toBeTruthy ( ) ;
98+ expect ( fileUrlInput ) . toBeFalsy ( ) ;
99+ } ) ;
100+
93101 describe ( 'if proceed button is pressed without validate only' , ( ) => {
94102 beforeEach ( fakeAsync ( ( ) => {
95103 component . validateOnly = false ;
@@ -99,9 +107,9 @@ describe('BatchImportPageComponent', () => {
99107 } ) ) ;
100108 it ( 'metadata-import script is invoked with --zip fileName and the mockFile' , ( ) => {
101109 const parameterValues : ProcessParameter [ ] = [
102- Object . assign ( new ProcessParameter ( ) , { name : '--zip' , value : 'filename.zip' } ) ,
110+ Object . assign ( new ProcessParameter ( ) , { name : '--add' } ) ,
111+ Object . assign ( new ProcessParameter ( ) , { name : '--zip' , value : 'filename.zip' } )
103112 ] ;
104- parameterValues . push ( Object . assign ( new ProcessParameter ( ) , { name : '--add' } ) ) ;
105113 expect ( scriptService . invoke ) . toHaveBeenCalledWith ( BATCH_IMPORT_SCRIPT_NAME , parameterValues , [ fileMock ] ) ;
106114 } ) ;
107115 it ( 'success notification is shown' , ( ) => {
@@ -121,8 +129,8 @@ describe('BatchImportPageComponent', () => {
121129 } ) ) ;
122130 it ( 'metadata-import script is invoked with --zip fileName and the mockFile and -v validate-only' , ( ) => {
123131 const parameterValues : ProcessParameter [ ] = [
124- Object . assign ( new ProcessParameter ( ) , { name : '--zip' , value : 'filename.zip' } ) ,
125132 Object . assign ( new ProcessParameter ( ) , { name : '--add' } ) ,
133+ Object . assign ( new ProcessParameter ( ) , { name : '--zip' , value : 'filename.zip' } ) ,
126134 Object . assign ( new ProcessParameter ( ) , { name : '-v' , value : true } ) ,
127135 ] ;
128136 expect ( scriptService . invoke ) . toHaveBeenCalledWith ( BATCH_IMPORT_SCRIPT_NAME , parameterValues , [ fileMock ] ) ;
@@ -148,4 +156,77 @@ describe('BatchImportPageComponent', () => {
148156 } ) ;
149157 } ) ;
150158 } ) ;
159+
160+ describe ( 'if url is set' , ( ) => {
161+ beforeEach ( fakeAsync ( ( ) => {
162+ component . isUpload = false ;
163+ component . fileURL = 'example.fileURL.com' ;
164+ fixture . detectChanges ( ) ;
165+ } ) ) ;
166+
167+ it ( 'should show the file url input' , ( ) => {
168+ const fileDropzone = fixture . debugElement . query ( By . css ( '[data-test="file-dropzone"]' ) ) ;
169+ const fileUrlInput = fixture . debugElement . query ( By . css ( '[data-test="file-url-input"]' ) ) ;
170+ expect ( fileDropzone ) . toBeFalsy ( ) ;
171+ expect ( fileUrlInput ) . toBeTruthy ( ) ;
172+ } ) ;
173+
174+ describe ( 'if proceed button is pressed without validate only' , ( ) => {
175+ beforeEach ( fakeAsync ( ( ) => {
176+ component . validateOnly = false ;
177+ const proceed = fixture . debugElement . query ( By . css ( '#proceedButton' ) ) . nativeElement ;
178+ proceed . click ( ) ;
179+ fixture . detectChanges ( ) ;
180+ } ) ) ;
181+ it ( 'metadata-import script is invoked with --url and the file url' , ( ) => {
182+ const parameterValues : ProcessParameter [ ] = [
183+ Object . assign ( new ProcessParameter ( ) , { name : '--add' } ) ,
184+ Object . assign ( new ProcessParameter ( ) , { name : '--url' , value : 'example.fileURL.com' } )
185+ ] ;
186+ expect ( scriptService . invoke ) . toHaveBeenCalledWith ( BATCH_IMPORT_SCRIPT_NAME , parameterValues , [ null ] ) ;
187+ } ) ;
188+ it ( 'success notification is shown' , ( ) => {
189+ expect ( notificationService . success ) . toHaveBeenCalled ( ) ;
190+ } ) ;
191+ it ( 'redirected to process page' , ( ) => {
192+ expect ( router . navigateByUrl ) . toHaveBeenCalledWith ( '/processes/46' ) ;
193+ } ) ;
194+ } ) ;
195+
196+ describe ( 'if proceed button is pressed with validate only' , ( ) => {
197+ beforeEach ( fakeAsync ( ( ) => {
198+ component . validateOnly = true ;
199+ const proceed = fixture . debugElement . query ( By . css ( '#proceedButton' ) ) . nativeElement ;
200+ proceed . click ( ) ;
201+ fixture . detectChanges ( ) ;
202+ } ) ) ;
203+ it ( 'metadata-import script is invoked with --url and the file url and -v validate-only' , ( ) => {
204+ const parameterValues : ProcessParameter [ ] = [
205+ Object . assign ( new ProcessParameter ( ) , { name : '--add' } ) ,
206+ Object . assign ( new ProcessParameter ( ) , { name : '--url' , value : 'example.fileURL.com' } ) ,
207+ Object . assign ( new ProcessParameter ( ) , { name : '-v' , value : true } ) ,
208+ ] ;
209+ expect ( scriptService . invoke ) . toHaveBeenCalledWith ( BATCH_IMPORT_SCRIPT_NAME , parameterValues , [ null ] ) ;
210+ } ) ;
211+ it ( 'success notification is shown' , ( ) => {
212+ expect ( notificationService . success ) . toHaveBeenCalled ( ) ;
213+ } ) ;
214+ it ( 'redirected to process page' , ( ) => {
215+ expect ( router . navigateByUrl ) . toHaveBeenCalledWith ( '/processes/46' ) ;
216+ } ) ;
217+ } ) ;
218+
219+ describe ( 'if proceed is pressed; but script invoke fails' , ( ) => {
220+ beforeEach ( fakeAsync ( ( ) => {
221+ jasmine . getEnv ( ) . allowRespy ( true ) ;
222+ spyOn ( scriptService , 'invoke' ) . and . returnValue ( createFailedRemoteDataObject$ ( 'Error' , 500 ) ) ;
223+ const proceed = fixture . debugElement . query ( By . css ( '#proceedButton' ) ) . nativeElement ;
224+ proceed . click ( ) ;
225+ fixture . detectChanges ( ) ;
226+ } ) ) ;
227+ it ( 'error notification is shown' , ( ) => {
228+ expect ( notificationService . error ) . toHaveBeenCalled ( ) ;
229+ } ) ;
230+ } ) ;
231+ } ) ;
151232} ) ;
0 commit comments