diff --git a/client/wfprev-war/src/main/angular/src/app/components/edit-project/project-details/project-files/project-files.component.spec.ts b/client/wfprev-war/src/main/angular/src/app/components/edit-project/project-details/project-files/project-files.component.spec.ts index 4dda073c5..c43380b9d 100644 --- a/client/wfprev-war/src/main/angular/src/app/components/edit-project/project-details/project-files/project-files.component.spec.ts +++ b/client/wfprev-war/src/main/angular/src/app/components/edit-project/project-details/project-files/project-files.component.spec.ts @@ -850,13 +850,42 @@ describe('ProjectFilesComponent', () => { }); }); + it('should skip boundary deletion when file is not MAP type', () => { + component.activityGuid = 'activity-guid'; + component.fiscalGuid = 'fiscal-guid'; + component.projectGuid = 'project-guid'; + + const mockFile = { + fileAttachmentGuid: 'test-guid', + attachmentContentTypeCode: { attachmentContentTypeCode: 'DOCUMENT' } + } as ProjectFile; + + mockDialog.open.and.returnValue({ afterClosed: () => of(true) } as any); + mockAttachmentService.deleteActivityAttachments.and.returnValue(of({})); + + spyOn(component.filesUpdated, 'emit'); + spyOn(component, 'loadActivityAttachments'); + + mockProjectService.getActivityBoundaries.calls.reset(); + + component.projectFiles = [mockFile]; + component.dataSource.data = [mockFile]; + + component.deleteFile(mockFile); + + expect(mockAttachmentService.deleteActivityAttachments).toHaveBeenCalled(); + expect(mockProjectService.getActivityBoundaries).not.toHaveBeenCalled(); // ✅ safe + expect(component.filesUpdated.emit).toHaveBeenCalled(); + expect(component.loadActivityAttachments).toHaveBeenCalled(); + }); + it('should delete activity attachment and latest boundary successfully when confirmed', (done) => { component.activityGuid = 'activity-guid'; component.fiscalGuid = 'fiscal-guid'; component.projectGuid = 'project-guid'; - const mockFile = { fileAttachmentGuid: 'test-guid' } as ProjectFile; + const mockFile = { fileAttachmentGuid: 'test-guid', attachmentContentTypeCode: { attachmentContentTypeCode: 'MAP' } } as ProjectFile; const mockBoundary = { activityBoundaryGuid: 'boundary-guid', systemStartTimestamp: new Date().toISOString() @@ -923,8 +952,10 @@ describe('ProjectFilesComponent', () => { component.activityGuid = 'activity-guid'; component.fiscalGuid = 'fiscal-guid'; component.projectGuid = 'project-guid'; - - const mockFile = { fileAttachmentGuid: 'test-guid' } as ProjectFile; + const mockFile = { + fileAttachmentGuid: 'test-guid', + attachmentContentTypeCode: { attachmentContentTypeCode: 'MAP' } + } as ProjectFile; mockDialog.open.and.returnValue({ afterClosed: () => of(true) } as any); mockAttachmentService.deleteActivityAttachments = jasmine.createSpy().and.returnValue(of({})); diff --git a/client/wfprev-war/src/main/angular/src/app/components/edit-project/project-details/project-files/project-files.component.ts b/client/wfprev-war/src/main/angular/src/app/components/edit-project/project-details/project-files/project-files.component.ts index c4c61680e..4a10b6104 100644 --- a/client/wfprev-war/src/main/angular/src/app/components/edit-project/project-details/project-files/project-files.component.ts +++ b/client/wfprev-war/src/main/angular/src/app/components/edit-project/project-details/project-files/project-files.component.ts @@ -472,7 +472,10 @@ export class ProjectFilesComponent implements OnInit { this.projectFiles = this.projectFiles.filter(file => file !== fileToDelete); this.dataSource.data = [...this.projectFiles]; - this.projectService.getActivityBoundaries(this.projectGuid, this.fiscalGuid, this.activityGuid).subscribe(response => { + const typeCode = fileToDelete.attachmentContentTypeCode?.attachmentContentTypeCode; + if (typeCode === 'MAP') { + // only run boundary deletion logic for MAP files + this.projectService.getActivityBoundaries(this.projectGuid, this.fiscalGuid, this.activityGuid).subscribe(response => { const boundaries = response?._embedded?.activityBoundary; if (boundaries && boundaries.length > 0) { const latest = boundaries.sort((a: ActivityBoundary, b: ActivityBoundary) => @@ -492,11 +495,18 @@ export class ProjectFilesComponent implements OnInit { } }) - } else { - console.log('No boundaries found'); - } - - }) + } else { + console.log('No boundaries found'); + } + }) + } else{ + this.filesUpdated.emit(); + this.snackbarService.open('File has been deleted successfully.', 'Close', { + duration: 5000, + panelClass: 'snackbar-success', + }); + this.loadActivityAttachments(); + } }, error: (error) => { // Handle any error during the deletion process diff --git a/client/wfprev-war/src/main/angular/src/app/components/models.ts b/client/wfprev-war/src/main/angular/src/app/components/models.ts index b4279fb81..6c1f1b93a 100644 --- a/client/wfprev-war/src/main/angular/src/app/components/models.ts +++ b/client/wfprev-war/src/main/angular/src/app/components/models.ts @@ -195,7 +195,10 @@ export interface ProjectFile { polygonHectares?: string, description?: string, fileIdentifier?: string, - documentPath?: string + documentPath?: string, + attachmentContentTypeCode?: { + attachmentContentTypeCode?: string; + } } export interface FeaturesResponse {