@@ -99,6 +99,16 @@ describe('ProjectFilesComponent', () => {
99
99
component . ngOnInit ( ) ;
100
100
expect ( component . loadProjectAttachments ) . toHaveBeenCalled ( ) ;
101
101
} ) ;
102
+ it ( 'should call loadActivityAttachments when activityGuid and fiscalGuid are present' , ( ) => {
103
+ component . activityGuid = 'activity-guid' ;
104
+ component . fiscalGuid = 'fiscal-guid' ;
105
+
106
+ spyOn ( component , 'loadActivityAttachments' ) ;
107
+
108
+ component . ngOnInit ( ) ;
109
+
110
+ expect ( component . loadActivityAttachments ) . toHaveBeenCalled ( ) ;
111
+ } ) ;
102
112
} ) ;
103
113
104
114
describe ( 'loadProjectAttachments' , ( ) => {
@@ -198,7 +208,7 @@ describe('ProjectFilesComponent', () => {
198
208
it ( 'should open file upload modal and call uploadFile if a file is selected' , ( ) => {
199
209
const mockFile = new File ( [ 'content' ] , 'test-file.txt' , { type : 'text/plain' } ) ;
200
210
mockDialog . open . and . returnValue ( {
201
- afterClosed : ( ) => of ( { file : mockFile } ) ,
211
+ afterClosed : ( ) => of ( { file : mockFile , type : 'Activity Polygon' } ) ,
202
212
} as any ) ;
203
213
204
214
spyOn ( component , 'uploadFile' ) . and . stub ( ) ;
@@ -208,7 +218,7 @@ describe('ProjectFilesComponent', () => {
208
218
width : '1000px' ,
209
219
data : { indicator : 'project-files' } ,
210
220
} ) ;
211
- expect ( component . uploadFile ) . toHaveBeenCalledWith ( mockFile ) ;
221
+ expect ( component . uploadFile ) . toHaveBeenCalledWith ( mockFile , 'Activity Polygon' ) ;
212
222
} ) ;
213
223
214
224
it ( 'should not call uploadFile if modal is closed without a file' , ( ) => {
@@ -245,17 +255,17 @@ describe('ProjectFilesComponent', () => {
245
255
246
256
spyOn ( component , 'uploadAttachment' ) . and . stub ( ) ;
247
257
248
- component . uploadFile ( mockFile ) ;
258
+ component . uploadFile ( mockFile , 'Activity Polygon' ) ;
249
259
250
260
expect ( mockProjectService . uploadDocument ) . toHaveBeenCalledWith ( { file : mockFile } ) ;
251
- expect ( component . uploadAttachment ) . toHaveBeenCalledWith ( mockFile , response ) ;
261
+ expect ( component . uploadAttachment ) . toHaveBeenCalledWith ( mockFile , response , 'Activity Polygon' ) ;
252
262
} ) ;
253
263
254
264
it ( 'should handle file upload error' , ( ) => {
255
265
const mockFile = new File ( [ 'content' ] , 'test-file.txt' , { type : 'text/plain' } ) ;
256
266
mockProjectService . uploadDocument . and . returnValue ( throwError ( ( ) => new Error ( 'Upload failed' ) ) ) ;
257
267
258
- component . uploadFile ( mockFile ) ;
268
+ component . uploadFile ( mockFile , 'Activity Polygon' ) ;
259
269
260
270
expect ( mockProjectService . uploadDocument ) . toHaveBeenCalledWith ( { file : mockFile } ) ;
261
271
expect ( mockSnackbar . open ) . toHaveBeenCalledWith (
@@ -285,7 +295,7 @@ describe('ProjectFilesComponent', () => {
285
295
spyOn ( component , 'updateProjectBoundary' ) . and . stub ( ) ;
286
296
spyOn ( component , 'loadProjectAttachments' ) . and . stub ( ) ;
287
297
288
- component . uploadAttachment ( mockFile , response ) ;
298
+ component . uploadAttachment ( mockFile , response , 'Activity Polygon' ) ;
289
299
290
300
expect ( mockAttachmentService . createProjectAttachment ) . toHaveBeenCalledWith (
291
301
mockProjectGuid ,
@@ -314,12 +324,30 @@ describe('ProjectFilesComponent', () => {
314
324
throwError ( ( ) => new Error ( 'Failed to create attachment' ) )
315
325
) ;
316
326
317
- component . uploadAttachment ( mockFile , response ) ;
327
+ component . uploadAttachment ( mockFile , response , 'Activity Polygon' ) ;
318
328
319
329
expect ( mockAttachmentService . createProjectAttachment ) . toHaveBeenCalled ( ) ;
320
330
expect ( console . log ) . toHaveBeenCalledWith ( 'Failed to upload attachment: ' , jasmine . any ( Error ) ) ;
321
331
} ) ;
322
332
333
+ it ( 'should call finishWithoutGeometry if type is "Other"' , async ( ) => {
334
+ const mockFile = new File ( [ 'test' ] , 'test-file.txt' , { type : 'text/plain' } ) ;
335
+ const response = { fileId : 'test-file-id' } ;
336
+ const uploadResponse = { uploadedByUserId : 'tester' } ;
337
+
338
+ component . projectGuid = 'project-guid' ;
339
+ component . fiscalGuid = 'fiscal-guid' ;
340
+ component . activityGuid = 'activity-guid' ;
341
+
342
+ spyOn ( component as any , 'finishWithoutGeometry' ) ;
343
+ mockAttachmentService . createActivityAttachment . and . returnValue ( of ( uploadResponse ) ) ;
344
+
345
+ await component . uploadAttachment ( mockFile , response , 'Other' ) ;
346
+
347
+ expect ( mockAttachmentService . createActivityAttachment ) . toHaveBeenCalled ( ) ;
348
+ expect ( component . uploadedBy ) . toBe ( 'tester' ) ;
349
+ expect ( component . finishWithoutGeometry ) . toHaveBeenCalled ( ) ;
350
+ } ) ;
323
351
} ) ;
324
352
325
353
describe ( 'updateProjectBoundary' , ( ) => {
@@ -543,7 +571,7 @@ describe('ProjectFilesComponent', () => {
543
571
it ( 'should show error if uploaded file has no extension' , ( ) => {
544
572
const mockFile = new File ( [ 'content' ] , 'file.' , { type : 'text/plain' } ) ;
545
573
546
- component . uploadAttachment ( mockFile , { fileId : 'some-id' } ) ;
574
+ component . uploadAttachment ( mockFile , { fileId : 'some-id' } , 'Activity Polygon' ) ;
547
575
548
576
expect ( mockSnackbar . open ) . toHaveBeenCalledWith (
549
577
'The spatial file was not uploaded because the file format is not accepted.' ,
@@ -620,15 +648,15 @@ describe('ProjectFilesComponent', () => {
620
648
const description = 'my description' ;
621
649
622
650
mockDialog . open . and . returnValue ( {
623
- afterClosed : ( ) => of ( { file : mockFile , description } ) ,
651
+ afterClosed : ( ) => of ( { file : mockFile , description, type : 'Activity Polygon' } ) ,
624
652
} as any ) ;
625
653
626
654
spyOn ( component , 'uploadFile' ) . and . stub ( ) ;
627
655
628
656
component . openFileUploadModal ( ) ;
629
657
630
658
expect ( component . attachmentDescription ) . toBe ( description ) ;
631
- expect ( component . uploadFile ) . toHaveBeenCalledWith ( mockFile ) ;
659
+ expect ( component . uploadFile ) . toHaveBeenCalledWith ( mockFile , 'Activity Polygon' ) ;
632
660
} ) ;
633
661
} ) ;
634
662
@@ -796,7 +824,7 @@ describe('ProjectFilesComponent', () => {
796
824
mockAttachmentService . createActivityAttachment . and . returnValue ( of ( mockResponse ) ) ;
797
825
mockSpatialService . extractCoordinates . and . returnValue ( Promise . resolve ( mockCoordinates ) ) ;
798
826
799
- await component . uploadAttachment ( mockFile , { fileId : 'file-xyz' } ) ;
827
+ await component . uploadAttachment ( mockFile , { fileId : 'file-xyz' } , 'Activity Polygon' ) ;
800
828
801
829
expect ( mockAttachmentService . createActivityAttachment ) . toHaveBeenCalledWith (
802
830
'project-guid' ,
@@ -815,5 +843,44 @@ describe('ProjectFilesComponent', () => {
815
843
expect ( component . updateActivityBoundary ) . toHaveBeenCalledWith ( mockFile , mockCoordinates ) ;
816
844
} ) ;
817
845
846
+ describe ( 'finishWithoutGeometry' , ( ) => {
847
+ beforeEach ( ( ) => {
848
+ spyOn ( component . filesUpdated , 'emit' ) ;
849
+ spyOn ( component , 'loadActivityAttachments' ) ;
850
+ spyOn ( component , 'loadProjectAttachments' ) ;
851
+ } ) ;
852
+
853
+ it ( 'should show snackbar, call loadActivityAttachments and emit event when isActivityContext is true' , ( ) => {
854
+ component . fiscalGuid = 'fiscal-guid' ;
855
+ component . activityGuid = 'activity-guid' ;
856
+
857
+ ( component as any ) . finishWithoutGeometry ( ) ;
858
+
859
+ expect ( mockSnackbar . open ) . toHaveBeenCalledWith (
860
+ 'File uploaded successfully.' ,
861
+ 'Close' ,
862
+ jasmine . objectContaining ( { duration : 5000 , panelClass : 'snackbar-success' } )
863
+ ) ;
864
+ expect ( component . loadActivityAttachments ) . toHaveBeenCalled ( ) ;
865
+ expect ( component . loadProjectAttachments ) . not . toHaveBeenCalled ( ) ;
866
+ expect ( component . filesUpdated . emit ) . toHaveBeenCalled ( ) ;
867
+ } ) ;
868
+
869
+ it ( 'should show snackbar, call loadProjectAttachments and emit event when isActivityContext is false' , ( ) => {
870
+ component . fiscalGuid = '' ;
871
+ component . activityGuid = '' ;
872
+
873
+ ( component as any ) . finishWithoutGeometry ( ) ;
874
+
875
+ expect ( mockSnackbar . open ) . toHaveBeenCalledWith (
876
+ 'File uploaded successfully.' ,
877
+ 'Close' ,
878
+ jasmine . objectContaining ( { duration : 5000 , panelClass : 'snackbar-success' } )
879
+ ) ;
880
+ expect ( component . loadProjectAttachments ) . toHaveBeenCalled ( ) ;
881
+ expect ( component . loadActivityAttachments ) . not . toHaveBeenCalled ( ) ;
882
+ expect ( component . filesUpdated . emit ) . toHaveBeenCalled ( ) ;
883
+ } ) ;
884
+ } ) ;
818
885
819
886
} ) ;
0 commit comments