Skip to content

Commit 3eb4e95

Browse files
authored
wfprev-656 (#978)
1 parent 292c92b commit 3eb4e95

File tree

4 files changed

+72
-2
lines changed

4 files changed

+72
-2
lines changed

client/wfprev-war/src/main/angular/src/app/components/edit-project/fiscal-map/fiscal-map.component.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ export class FiscalMapComponent implements AfterViewInit, OnDestroy, OnInit {
164164
private handleBoundariesResponse(results: any[]): void {
165165
// Filter out nulls or empty boundary arrays
166166
const validResults = results.filter(r => r?.boundary && r.boundary.length > 0);
167-
167+
this.activityBoundaryGroup.clearLayers(); // clears old activity polygons at first place
168168
// For each activity, keep only the latest boundary
169169
const dedupedResults: any[] = [];
170170
const seenActivityGuids = new Set<string>();
@@ -203,7 +203,6 @@ export class FiscalMapComponent implements AfterViewInit, OnDestroy, OnInit {
203203
}
204204

205205
plotActivityBoundariesOnMap(boundaries: any[]): void {
206-
this.activityBoundaryGroup.clearLayers(); // clears old activity polygons
207206
const allFiscalPolygons: L.Layer[] = [];
208207

209208
boundaries.forEach(boundaryEntry => {

client/wfprev-war/src/main/angular/src/app/components/edit-project/project-fiscals/project-fiscals.component.spec.ts

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -933,4 +933,59 @@ describe('ProjectFiscalsComponent', () => {
933933
expect(component.selectedTabIndex).toBe(0);
934934
}));
935935

936+
it('should block deletion and show snackbar if activities exist', () => {
937+
mockSnackBar.open.calls.reset();
938+
mockProjectService.deleteProjectFiscalByProjectPlanFiscalGuid.calls.reset();
939+
940+
// ✅ Mock dialog.open to auto-confirm
941+
spyOn(component.dialog, 'open').and.returnValue({
942+
afterClosed: () => of(true) // Simulates user clicking "Confirm"
943+
} as any);
944+
945+
// ✅ Provide activities that match the fiscalGuid
946+
(component as any).activitiesComponent = {
947+
activities: [{ projectPlanFiscalGuid: 'test-guid' }]
948+
};
949+
950+
component.projectFiscals = [{ projectPlanFiscalGuid: 'test-guid' }];
951+
component.selectedTabIndex = 0;
952+
953+
fixture.detectChanges();
954+
955+
component.deleteFiscalYear({ value: component.projectFiscals[0] }, 0);
956+
957+
expect(mockSnackBar.open).toHaveBeenCalledOnceWith(
958+
component.messages.fiscalActivityDeletedFailure,
959+
'OK',
960+
{ duration: 5000, panelClass: 'snackbar-error' }
961+
);
962+
963+
expect(mockProjectService.deleteProjectFiscalByProjectPlanFiscalGuid)
964+
.not.toHaveBeenCalled();
965+
});
966+
967+
968+
it('should proceed with deletion if there are no activities', () => {
969+
spyOn(component.dialog, 'open').and.returnValue({
970+
afterClosed: () => of(true)
971+
} as any);
972+
spyOn(component, 'loadProjectFiscals');
973+
974+
component.activitiesComponent = {
975+
activities: []
976+
} as any;
977+
978+
mockProjectService.deleteProjectFiscalByProjectPlanFiscalGuid = jasmine.createSpy().and.returnValue(of({}));
979+
980+
component.projectFiscals = [{ projectPlanFiscalGuid: 'test-guid' }];
981+
component.deleteFiscalYear({ value: component.projectFiscals[0] }, 0);
982+
983+
expect(mockProjectService.deleteProjectFiscalByProjectPlanFiscalGuid).toHaveBeenCalledWith('test-guid', 'test-guid');
984+
expect(mockSnackBar.open).toHaveBeenCalledWith(
985+
component.messages.projectFiscalDeletedSuccess,
986+
'OK',
987+
{ duration: 5000, panelClass: 'snackbar-success' }
988+
);
989+
});
990+
936991
});

client/wfprev-war/src/main/angular/src/app/components/edit-project/project-fiscals/project-fiscals.component.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,7 @@ export class ProjectFiscalsComponent implements OnInit, CanComponentDeactivate {
491491
const fiscalYear = this.projectFiscals[this.selectedTabIndex]?.fiscalYear;
492492
const formattedYear = fiscalYear ? `${fiscalYear}/${(fiscalYear + 1).toString().slice(-2)}` : null;
493493
const yearName = (fiscalName && fiscalYear) ? `${fiscalName}:${formattedYear}` : 'this fiscal activity'
494+
const fiscalGuid = formData.projectPlanFiscalGuid ?? '';
494495

495496
const dialogRef = this.dialog.open(ConfirmationDialogComponent, {
496497
data: {
@@ -503,6 +504,18 @@ export class ProjectFiscalsComponent implements OnInit, CanComponentDeactivate {
503504

504505
dialogRef.afterClosed().subscribe((confirmed: boolean) => {
505506
if (confirmed) {
507+
508+
const hasActivities = this.activitiesComponent?.activities?.some(a => a.projectPlanFiscalGuid === fiscalGuid) ?? false;
509+
510+
if (hasActivities) {
511+
this.snackbarService.open(
512+
this.messages.fiscalActivityDeletedFailure,
513+
'OK',
514+
{ duration: 5000, panelClass: 'snackbar-error' }
515+
);
516+
return;
517+
}
518+
506519
if (formData.projectPlanFiscalGuid) {
507520
// Delete from the service call if it's a saved fiscal activity
508521
this.projectService.deleteProjectFiscalByProjectPlanFiscalGuid(this.projectGuid, formData.projectPlanFiscalGuid)
@@ -545,6 +558,7 @@ export class ProjectFiscalsComponent implements OnInit, CanComponentDeactivate {
545558
}
546559

547560
onBoundariesChanged(): void {
561+
548562
if (this.fiscalMapComponent) {
549563
this.fiscalMapComponent.getAllActivitiesBoundaries(); // refresh boundaries on map
550564
}
@@ -653,6 +667,7 @@ export class ProjectFiscalsComponent implements OnInit, CanComponentDeactivate {
653667
this.updateFiscalStatus(index, action);
654668
}
655669
}
670+
656671

657672
onSaveEndorsement(updatedFiscal: ProjectFiscal): void {
658673
const index = this.selectedTabIndex;

client/wfprev-war/src/main/angular/src/app/utils/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export const Messages = {
3030
fileDownloadFailure: 'Error: File download unsuccessful',
3131
fileDownloadSuccess: 'File downloaded successfully.',
3232
fileDownloadInProgress: 'File download in progress. Please wait',
33+
fiscalActivityDeletedFailure: 'Delete Failed. Remove Activities to Delete Fiscal Activity'
3334
};
3435

3536
export const CodeTableKeys = {

0 commit comments

Comments
 (0)