Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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({}));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) =>
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,10 @@ export interface ProjectFile {
polygonHectares?: string,
description?: string,
fileIdentifier?: string,
documentPath?: string
documentPath?: string,
attachmentContentTypeCode?: {
attachmentContentTypeCode?: string;
}
}

export interface FeaturesResponse {
Expand Down
Loading