Skip to content

Commit d22589e

Browse files
authored
Wfprev 381 (#778)
1 parent 364c84e commit d22589e

File tree

4 files changed

+101
-31
lines changed

4 files changed

+101
-31
lines changed

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -640,4 +640,31 @@ describe('ProjectFiscalsComponent', () => {
640640
const control = component.getFiscalControl(0, 'testField');
641641
expect(control).toBeTruthy();
642642
});
643+
644+
it('should return default fiscal data with expected values', () => {
645+
component.projectGuid = 'test-guid';
646+
647+
const result = component.getDefaultFiscalData();
648+
649+
expect(result).toEqual({
650+
fiscalYear: 0,
651+
projectFiscalName: '',
652+
projectGuid: 'test-guid',
653+
planFiscalStatusCode: 'DRAFT',
654+
proposalTypeCode: 'NEW',
655+
projectPlanStatusCode: 'ACTIVE',
656+
activityCategoryCode: '',
657+
fiscalPlannedProjectSizeHa: 0,
658+
fiscalPlannedCostPerHaAmt: 0,
659+
fiscalReportedSpendAmount: 0,
660+
fiscalActualAmount: 0,
661+
fiscalActualCostPerHaAmt: 0,
662+
firstNationsEngagementInd: false,
663+
firstNationsDelivPartInd: false,
664+
isApprovedInd: false,
665+
isDelayedInd: false,
666+
totalCostEstimateAmount: 0
667+
});
668+
});
669+
643670
});

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

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ export class ProjectFiscalsComponent implements OnInit, CanComponentDeactivate
249249
// And to prevent adding another unsaved fiscal
250250
return;
251251
}
252-
const newFiscalData = { fiscalYear: '', projectFiscalName: '', projectGuid: this.projectGuid, planFiscalStatusCode: 'DRAFT', proposalTypeCode: 'NEW'};
252+
const newFiscalData = this.getDefaultFiscalData();
253253
this.projectFiscals.push(newFiscalData);
254254
this.fiscalForms.push(this.createFiscalForm(newFiscalData));
255255
this.selectedTabIndex = this.projectFiscals.length - 1; // Navigate to the newly added tab
@@ -262,8 +262,9 @@ export class ProjectFiscalsComponent implements OnInit, CanComponentDeactivate
262262

263263
if (isNewEntry) {
264264
// Case 1: New entry → Clear all fields
265-
this.fiscalForms[index].reset();
266-
} else {
265+
this.fiscalForms[index].reset(this.getDefaultFiscalData());
266+
}
267+
else {
267268
// Case 2: Existing entry → Revert to original API values
268269
const originalData = this.originalFiscalValues[index];
269270
this.fiscalForms[index].patchValue(originalData);
@@ -296,7 +297,7 @@ export class ProjectFiscalsComponent implements OnInit, CanComponentDeactivate
296297
projectGuid: updatedData.projectGuid,
297298
projectPlanFiscalGuid: updatedData.projectPlanFiscalGuid,
298299
activityCategoryCode: updatedData.activityCategoryCode,
299-
fiscalYear: updatedData.fiscalYear ? parseInt(updatedData.fiscalYear, 10) : undefined,
300+
fiscalYear: updatedData.fiscalYear ? parseInt(updatedData.fiscalYear, 10) : 0,
300301
projectPlanStatusCode: isUpdate ? updatedData.projectPlanStatusCode : "ACTIVE",
301302
planFiscalStatusCode: updatedData.planFiscalStatusCode,
302303
projectFiscalName: updatedData.projectFiscalName,
@@ -459,5 +460,27 @@ export class ProjectFiscalsComponent implements OnInit, CanComponentDeactivate
459460
return this.fiscalForms[i].get(controlName) as FormControl;
460461
}
461462

463+
getDefaultFiscalData(): ProjectFiscal {
464+
return {
465+
fiscalYear: 0,
466+
projectFiscalName: '',
467+
projectGuid: this.projectGuid,
468+
planFiscalStatusCode: 'DRAFT',
469+
proposalTypeCode: 'NEW',
470+
projectPlanStatusCode: 'ACTIVE',
471+
activityCategoryCode: '',
472+
fiscalPlannedProjectSizeHa: 0,
473+
fiscalPlannedCostPerHaAmt: 0,
474+
fiscalReportedSpendAmount: 0,
475+
fiscalActualAmount: 0,
476+
fiscalActualCostPerHaAmt: 0,
477+
firstNationsEngagementInd: false,
478+
firstNationsDelivPartInd: false,
479+
isApprovedInd: false,
480+
isDelayedInd: false,
481+
totalCostEstimateAmount: 0
482+
};
483+
}
484+
462485
}
463486

client/wfprev-war/src/main/angular/src/app/components/models.ts

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -49,25 +49,29 @@ export interface Project {
4949
}
5050

5151
export interface ProjectFiscal {
52-
projectGuid?: string;
52+
projectGuid: string;
53+
activityCategoryCode: string;
54+
fiscalYear: number;
55+
projectPlanStatusCode: string;
56+
planFiscalStatusCode: string;
57+
projectFiscalName: string;
58+
isApprovedInd: boolean;
59+
isDelayedInd: boolean;
60+
totalCostEstimateAmount: number;
61+
fiscalPlannedProjectSizeHa: number;
62+
fiscalPlannedCostPerHaAmt: number;
63+
fiscalReportedSpendAmount: number;
64+
fiscalActualAmount: number;
65+
fiscalActualCostPerHaAmt: number;
66+
firstNationsDelivPartInd: boolean;
67+
firstNationsEngagementInd: boolean;
68+
5369
projectPlanFiscalGuid?: string;
54-
activityCategoryCode?: string;
55-
fiscalYear?: number;
56-
projectPlanStatusCode?: string;
57-
planFiscalStatusCode?: string;
58-
projectFiscalName?: string;
5970
projectFiscalDescription?: string;
6071
businessAreaComment?: string;
6172
estimatedClwrrAllocAmount?: number;
6273
fiscalAncillaryFundAmount?: number;
63-
fiscalPlannedProjectSizeHa?: number;
64-
fiscalPlannedCostPerHaAmt?: number;
65-
fiscalReportedSpendAmount?: number;
66-
fiscalActualAmount?: number;
6774
fiscalCompletedSizeHa?: number;
68-
fiscalActualCostPerHaAmt?: number;
69-
firstNationsDelivPartInd?: boolean;
70-
firstNationsEngagementInd?: boolean;
7175
firstNationsPartner?: string;
7276
resultsNumber?: string;
7377
resultsOpeningId?: string;
@@ -76,16 +80,14 @@ export interface ProjectFiscal {
7680
submittedByUserGuid?: string;
7781
submittedByUserUserid?: string;
7882
submissionTimestamp?: string;
79-
isApprovedInd?: boolean;
80-
isDelayedInd?: boolean;
8183
fiscalForecastAmount?: number;
82-
totalCostEstimateAmount?: number;
8384
cfsProjectCode?: string;
8485
otherPartner?: string;
8586
proposalTypeCode?: string;
8687
ancillaryFundingProvider?: string;
8788
}
8889

90+
8991
export interface ActivityModel {
9092
activityGuid?: string;
9193
projectPlanFiscalGuid?: string;

client/wfprev-war/src/main/angular/src/app/services/project-services.spec.ts

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { TestBed } from '@angular/core/testing';
22
import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing';
33
import { AppConfigService } from 'src/app/services/app-config.service';
44
import { TokenService } from 'src/app/services/token.service';
5-
import { FeaturesResponse, Project, ProjectBoundary } from 'src/app/components/models';
5+
import { FeaturesResponse, Project, ProjectBoundary, ProjectFiscal } from 'src/app/components/models';
66
import { ProjectService } from 'src/app/services/project-services';
77
import { HttpEventType } from '@angular/common/http';
88
import { of } from 'rxjs';
@@ -60,7 +60,29 @@ describe('ProjectService', () => {
6060
},
6161
locationGeometry: [-124, 49],
6262
};
63+
const projectGuid = '12345';
64+
const projectPlanFiscalGuid = 'fiscal-6789';
6365

66+
const updatedFiscal: ProjectFiscal = {
67+
projectGuid,
68+
projectPlanFiscalGuid,
69+
fiscalYear: 2024,
70+
projectFiscalName: 'Updated Fiscal',
71+
activityCategoryCode: 'RX_DEV',
72+
planFiscalStatusCode: 'COMPLETE',
73+
projectPlanStatusCode: 'ACTIVE',
74+
proposalTypeCode: 'NEW',
75+
isApprovedInd: false,
76+
isDelayedInd: false,
77+
totalCostEstimateAmount: 0,
78+
fiscalPlannedProjectSizeHa: 0,
79+
fiscalPlannedCostPerHaAmt: 0,
80+
fiscalReportedSpendAmount: 0,
81+
fiscalActualAmount: 0,
82+
fiscalActualCostPerHaAmt: 0,
83+
firstNationsDelivPartInd: false,
84+
firstNationsEngagementInd: false
85+
};
6486

6587

6688
beforeEach(() => {
@@ -253,27 +275,25 @@ describe('ProjectService', () => {
253275

254276
it('should create a project fiscal', () => {
255277
const projectGuid = '12345';
256-
const mockFiscal = { fiscalYear: 2023, projectFiscalName: 'New Fiscal' };
257278

258-
service.createProjectFiscal(projectGuid, mockFiscal).subscribe((response) => {
259-
expect(response).toEqual(mockFiscal);
279+
service.createProjectFiscal(projectGuid, updatedFiscal).subscribe((response) => {
280+
expect(response).toEqual(updatedFiscal);
260281
});
261282

262283
const req = httpMock.expectOne(`http://mock-api.com/wfprev-api/projects/${projectGuid}/projectFiscals`);
263284
expect(req.request.method).toBe('POST');
264285
expect(req.request.headers.get('Authorization')).toBe('Bearer mock-token');
265-
expect(req.request.body).toEqual(mockFiscal);
266-
req.flush(mockFiscal);
286+
expect(req.request.body).toEqual(updatedFiscal);
287+
req.flush(updatedFiscal);
267288
});
268289

269290
it('should handle errors when creating a project fiscal', () => {
270291
const projectGuid = '12345';
271-
const mockFiscal = { fiscalYear: 2023, projectFiscalName: 'New Fiscal' };
272292

273-
service.createProjectFiscal(projectGuid, mockFiscal).subscribe({
293+
service.createProjectFiscal(projectGuid, updatedFiscal).subscribe({
274294
next: () => fail('Should have failed with an error'),
275295
error: (error) => {
276-
expect(error.message).toBe('Failed to create project fiscal'); // ✅ Now correctly matches the service error
296+
expect(error.message).toBe('Failed to create project fiscal');
277297
}
278298
});
279299

@@ -284,7 +304,6 @@ describe('ProjectService', () => {
284304
it('should update a project fiscal', () => {
285305
const projectGuid = '12345';
286306
const projectPlanFiscalGuid = 'fiscal-6789';
287-
const updatedFiscal = { fiscalYear: 2024, projectFiscalName: 'Updated Fiscal' };
288307

289308
service.updateProjectFiscal(projectGuid, projectPlanFiscalGuid, updatedFiscal).subscribe((response) => {
290309
expect(response).toEqual(updatedFiscal);
@@ -300,7 +319,6 @@ describe('ProjectService', () => {
300319
it('should handle errors when updating a project fiscal', () => {
301320
const projectGuid = '12345';
302321
const projectPlanFiscalGuid = 'fiscal-6789';
303-
const updatedFiscal = { fiscalYear: 2024, projectFiscalName: 'Updated Fiscal' };
304322

305323
service.updateProjectFiscal(projectGuid, projectPlanFiscalGuid, updatedFiscal).subscribe({
306324
next: () => fail('Should have failed with an error'),

0 commit comments

Comments
 (0)