Skip to content

Commit 362cc53

Browse files
authored
more tests (#993)
1 parent 1ba0bf4 commit 362cc53

File tree

3 files changed

+86
-0
lines changed

3 files changed

+86
-0
lines changed

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -903,5 +903,27 @@ describe('ActivitiesComponent', () => {
903903
});
904904
});
905905

906+
describe('onSaveActivity early exit cases', () => {
907+
it('should exit early if activity is already being saved', () => {
908+
component.activities = [{ activityGuid: 'test-guid' }];
909+
component.activityForms = [component.createActivityForm({ activityGuid: 'test-guid' })];
910+
component.isActivitySaving[0] = true;
911+
component.onSaveActivity(0);
912+
913+
expect(mockProjectService.updateFiscalActivities).not.toHaveBeenCalled();
914+
expect(component.isActivitySaving[0]).toBeTrue();
915+
});
916+
917+
it('should reset isActivitySaving to false and return if form does not exist', () => {
918+
component.activities = [{}];
919+
component.activityForms = [];
920+
component.isActivitySaving[0] = false;
921+
922+
component.onSaveActivity(0);
923+
924+
expect(component.isActivitySaving[0]).toBeFalse();
925+
});
926+
});
927+
906928

907929
});

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

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1366,4 +1366,54 @@ describe('ProjectDetailsComponent', () => {
13661366
);
13671367
});
13681368

1369+
describe('isSaving flag behavior', () => {
1370+
beforeEach(() => {
1371+
component.projectGuid = 'test-guid';
1372+
component.projectDetail = {
1373+
projectTypeCode: { projectTypeCode: 'TEST' },
1374+
primaryObjectiveTypeCode: {}
1375+
};
1376+
1377+
component.detailsForm = new FormGroup({
1378+
projectTypeCode: new FormControl('FUEL_MGMT'),
1379+
programAreaGuid: new FormControl('area-guid'),
1380+
closestCommunityName: new FormControl('Test City'),
1381+
primaryObjectiveTypeCode: new FormControl('WRR'),
1382+
wildfireOrgUnitId: new FormControl(123)
1383+
});
1384+
spyOnProperty(component.detailsForm, 'valid', 'get').and.returnValue(true);
1385+
});
1386+
1387+
it('should set isSaving to true while saving and reset on success', () => {
1388+
mockProjectService.updateProject.and.returnValue(of({}));
1389+
mockProjectService.getProjectByProjectGuid.and.returnValue(of({}));
1390+
1391+
component.onSave();
1392+
1393+
expect(component.isSaving).toBeFalse();
1394+
});
1395+
1396+
it('should set isSaving to false when updateProject errors', () => {
1397+
mockProjectService.updateProject.and.returnValue(throwError(() => new Error('fail')));
1398+
1399+
component.onSave();
1400+
1401+
expect(component.isSaving).toBeFalse();
1402+
});
1403+
1404+
it('should not proceed with save if isSaving is already true', () => {
1405+
component.isSaving = true;
1406+
1407+
component.onSave();
1408+
1409+
expect(mockProjectService.updateProject).not.toHaveBeenCalled();
1410+
});
1411+
1412+
it('should block onSaveLatLong if isSaving is already true', () => {
1413+
component.isSaving = true;
1414+
component.onSaveLatLong();
1415+
expect(mockProjectService.updateProject).not.toHaveBeenCalled();
1416+
});
1417+
});
1418+
13691419
});

client/wfprev-war/src/main/angular/src/app/components/evaluation-criteria-dialog/evaluation-criteria-dialog.component.spec.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ describe('EvaluationCriteriaDialogComponent', () => {
111111
mockProjectService.createEvaluationCriteriaSummary.and.returnValue(of({}));
112112
component.onSave();
113113
expect(mockProjectService.createEvaluationCriteriaSummary).toHaveBeenCalled();
114+
expect(component.isSaving).toBeFalse();
114115
});
115116

116117
it('should call onSave and update evaluation criteria summary', () => {
@@ -120,13 +121,26 @@ describe('EvaluationCriteriaDialogComponent', () => {
120121
mockProjectService.updateEvaluationCriteriaSummary.and.returnValue(of({}));
121122
component.onSave();
122123
expect(mockProjectService.updateEvaluationCriteriaSummary).toHaveBeenCalled();
124+
expect(component.isSaving).toBeFalse();
123125
});
124126

125127
it('should handle invalid form onSave', () => {
126128
component.criteriaForm = { valid: false } as any;
127129
spyOn(console, 'warn');
128130
component.onSave();
129131
expect(console.warn).toHaveBeenCalledWith('Form is invalid, not saving.');
132+
expect(component.isSaving).toBeFalse();
133+
});
134+
135+
it('should block onSave if already saving', () => {
136+
component.initializeForm();
137+
component.criteriaForm.patchValue({ wuiRiskClassCode: 1 });
138+
component.isSaving = true;
139+
140+
component.onSave();
141+
142+
expect(mockProjectService.createEvaluationCriteriaSummary).not.toHaveBeenCalled();
143+
expect(mockProjectService.updateEvaluationCriteriaSummary).not.toHaveBeenCalled();
130144
});
131145

132146
it('should call onCancel and close dialog if confirmed', () => {

0 commit comments

Comments
 (0)