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 @@ -903,5 +903,27 @@ describe('ActivitiesComponent', () => {
});
});

describe('onSaveActivity early exit cases', () => {
it('should exit early if activity is already being saved', () => {
component.activities = [{ activityGuid: 'test-guid' }];
component.activityForms = [component.createActivityForm({ activityGuid: 'test-guid' })];
component.isActivitySaving[0] = true;
component.onSaveActivity(0);

expect(mockProjectService.updateFiscalActivities).not.toHaveBeenCalled();
expect(component.isActivitySaving[0]).toBeTrue();
});

it('should reset isActivitySaving to false and return if form does not exist', () => {
component.activities = [{}];
component.activityForms = [];
component.isActivitySaving[0] = false;

component.onSaveActivity(0);

expect(component.isActivitySaving[0]).toBeFalse();
});
});


});
Original file line number Diff line number Diff line change
Expand Up @@ -1366,4 +1366,54 @@ describe('ProjectDetailsComponent', () => {
);
});

describe('isSaving flag behavior', () => {
beforeEach(() => {
component.projectGuid = 'test-guid';
component.projectDetail = {
projectTypeCode: { projectTypeCode: 'TEST' },
primaryObjectiveTypeCode: {}
};

component.detailsForm = new FormGroup({
projectTypeCode: new FormControl('FUEL_MGMT'),
programAreaGuid: new FormControl('area-guid'),
closestCommunityName: new FormControl('Test City'),
primaryObjectiveTypeCode: new FormControl('WRR'),
wildfireOrgUnitId: new FormControl(123)
});
spyOnProperty(component.detailsForm, 'valid', 'get').and.returnValue(true);
});

it('should set isSaving to true while saving and reset on success', () => {
mockProjectService.updateProject.and.returnValue(of({}));
mockProjectService.getProjectByProjectGuid.and.returnValue(of({}));

component.onSave();

expect(component.isSaving).toBeFalse();
});

it('should set isSaving to false when updateProject errors', () => {
mockProjectService.updateProject.and.returnValue(throwError(() => new Error('fail')));

component.onSave();

expect(component.isSaving).toBeFalse();
});

it('should not proceed with save if isSaving is already true', () => {
component.isSaving = true;

component.onSave();

expect(mockProjectService.updateProject).not.toHaveBeenCalled();
});

it('should block onSaveLatLong if isSaving is already true', () => {
component.isSaving = true;
component.onSaveLatLong();
expect(mockProjectService.updateProject).not.toHaveBeenCalled();
});
});

});
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ describe('EvaluationCriteriaDialogComponent', () => {
mockProjectService.createEvaluationCriteriaSummary.and.returnValue(of({}));
component.onSave();
expect(mockProjectService.createEvaluationCriteriaSummary).toHaveBeenCalled();
expect(component.isSaving).toBeFalse();
});

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

it('should handle invalid form onSave', () => {
component.criteriaForm = { valid: false } as any;
spyOn(console, 'warn');
component.onSave();
expect(console.warn).toHaveBeenCalledWith('Form is invalid, not saving.');
expect(component.isSaving).toBeFalse();
});

it('should block onSave if already saving', () => {
component.initializeForm();
component.criteriaForm.patchValue({ wuiRiskClassCode: 1 });
component.isSaving = true;

component.onSave();

expect(mockProjectService.createEvaluationCriteriaSummary).not.toHaveBeenCalled();
expect(mockProjectService.updateEvaluationCriteriaSummary).not.toHaveBeenCalled();
});

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