Skip to content

Commit

Permalink
Merge pull request #1973 from bcgov/bugfix/ALCS-2372
Browse files Browse the repository at this point in the history
Fix NOI structure questions disappearing
  • Loading branch information
trslater authored Nov 13, 2024
2 parents e9b5148 + beb1314 commit 8df61a1
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,6 @@ describe('AdditionalInformationComponent', () => {
const mockFilledSubmission: NoticeOfIntentSubmissionDetailedDto = {
...emptySubmission,
soilIsRemovingSoilForNewStructure: true,
soilStructureFarmUseReason: 'soilStructureFarmUseReason',
soilStructureResidentialUseReason: 'soilStructureResidentialUseReason',
soilProposedStructures: [
{
Expand All @@ -166,9 +165,12 @@ describe('AdditionalInformationComponent', () => {

expect(component.form.controls.isRemovingSoilForNewStructure.value).toEqual('true');
expect(component.form.controls.soilStructureFarmUseReason.value).toEqual(null);
expect(component.form.controls.soilAgriParcelActivity.value).toEqual(null);
expect(component.form.controls.soilStructureResidentialUseReason.value).toEqual(
'soilStructureResidentialUseReason',
);
expect(component.form.controls.soilStructureResidentialAccessoryUseReason.value).toEqual(null);
expect(component.form.controls.soilStructureOtherUseReason.value).toEqual(null);
expect(Object.values(component.structuresForm.controls).length).toEqual(2);
expect(component.isSoilStructureResidentialUseReasonVisible).toBeTruthy();
expect(component.isSoilAgriParcelActivityVisible).toBeFalsy();
Expand All @@ -181,7 +183,7 @@ describe('AdditionalInformationComponent', () => {
...emptySubmission,
soilIsRemovingSoilForNewStructure: true,
soilStructureFarmUseReason: 'soilStructureFarmUseReason',
soilStructureResidentialUseReason: 'soilStructureResidentialUseReason',
soilAgriParcelActivity: 'soilAgriParcelActivity',
soilProposedStructures: [
{
type: STRUCTURE_TYPES.FARM_STRUCTURE,
Expand All @@ -197,7 +199,10 @@ describe('AdditionalInformationComponent', () => {

expect(component.form.controls.isRemovingSoilForNewStructure.value).toEqual('true');
expect(component.form.controls.soilStructureFarmUseReason.value).toEqual('soilStructureFarmUseReason');
expect(component.form.controls.soilAgriParcelActivity.value).toEqual('soilAgriParcelActivity');
expect(component.form.controls.soilStructureResidentialUseReason.value).toEqual(null);
expect(component.form.controls.soilStructureResidentialAccessoryUseReason.value).toEqual(null);
expect(component.form.controls.soilStructureOtherUseReason.value).toEqual(null);
expect(component.isSoilStructureResidentialUseReasonVisible).toBeFalsy();
expect(component.isSoilAgriParcelActivityVisible).toBeTruthy();
expect(component.isSoilOtherUseReasonVisible).toBeFalsy();
Expand All @@ -208,8 +213,7 @@ describe('AdditionalInformationComponent', () => {
const mockFilledSubmission: NoticeOfIntentSubmissionDetailedDto = {
...emptySubmission,
soilIsRemovingSoilForNewStructure: true,
soilStructureFarmUseReason: 'soilStructureFarmUseReason',
soilStructureResidentialUseReason: 'soilStructureResidentialUseReason',
soilStructureOtherUseReason: 'soilStructureOtherUseReason',
soilProposedStructures: [
{
type: STRUCTURE_TYPES.OTHER_STRUCTURE,
Expand All @@ -225,7 +229,9 @@ describe('AdditionalInformationComponent', () => {

expect(component.form.controls.isRemovingSoilForNewStructure.value).toEqual('true');
expect(component.form.controls.soilStructureFarmUseReason.value).toEqual(null);
expect(component.form.controls.soilAgriParcelActivity.value).toEqual(null);
expect(component.form.controls.soilStructureResidentialUseReason.value).toEqual(null);
expect(component.form.controls.soilStructureOtherUseReason.value).toEqual('soilStructureOtherUseReason');
expect(component.isSoilStructureResidentialUseReasonVisible).toBeFalsy();
expect(component.isSoilAgriParcelActivityVisible).toBeFalsy();
expect(component.isSoilOtherUseReasonVisible).toBeTruthy();
Expand All @@ -236,7 +242,7 @@ describe('AdditionalInformationComponent', () => {
const mockFilledSubmission: NoticeOfIntentSubmissionDetailedDto = {
...emptySubmission,
soilIsRemovingSoilForNewStructure: true,
soilStructureFarmUseReason: 'soilStructureFarmUseReason',
soilStructureResidentialAccessoryUseReason: 'soilStructureResidentialAccessoryUseReason',
soilStructureResidentialUseReason: 'soilStructureResidentialUseReason',
soilProposedStructures: [
{
Expand All @@ -253,9 +259,14 @@ describe('AdditionalInformationComponent', () => {

expect(component.form.controls.isRemovingSoilForNewStructure.value).toEqual('true');
expect(component.form.controls.soilStructureFarmUseReason.value).toEqual(null);
expect(component.form.controls.soilAgriParcelActivity.value).toEqual(null);
expect(component.form.controls.soilStructureResidentialUseReason.value).toEqual(
'soilStructureResidentialUseReason',
);
expect(component.form.controls.soilStructureResidentialAccessoryUseReason.value).toEqual(
'soilStructureResidentialAccessoryUseReason',
);
expect(component.form.controls.soilStructureOtherUseReason.value).toEqual(null);
expect(component.isSoilStructureResidentialUseReasonVisible).toBeTruthy();
expect(component.isSoilAgriParcelActivityVisible).toBeFalsy();
expect(component.isSoilOtherUseReasonVisible).toBeFalsy();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,15 +162,6 @@ export class AdditionalInformationComponent extends FilesStepComponent implement
this.confirmRemovalOfSoil = true;
}

this.form.patchValue({
isRemovingSoilForNewStructure: formatBooleanToString(noiSubmission.soilIsRemovingSoilForNewStructure),
soilStructureFarmUseReason: noiSubmission.soilStructureFarmUseReason,
soilStructureResidentialUseReason: noiSubmission.soilStructureResidentialUseReason,
soilAgriParcelActivity: noiSubmission.soilAgriParcelActivity,
soilStructureResidentialAccessoryUseReason: noiSubmission.soilStructureResidentialAccessoryUseReason,
soilStructureOtherUseReason: noiSubmission.soilStructureOtherUseReason,
});

this.structuresForm = new FormGroup({});
this.proposedStructures = [];
for (const structure of noiSubmission.soilProposedStructures) {
Expand All @@ -182,6 +173,15 @@ export class AdditionalInformationComponent extends FilesStepComponent implement
this.structuresSource = new MatTableDataSource(this.proposedStructures);
this.prepareStructureSpecificTextInputs();

this.form.patchValue({
isRemovingSoilForNewStructure: formatBooleanToString(noiSubmission.soilIsRemovingSoilForNewStructure),
soilStructureFarmUseReason: noiSubmission.soilStructureFarmUseReason,
soilStructureResidentialUseReason: noiSubmission.soilStructureResidentialUseReason,
soilAgriParcelActivity: noiSubmission.soilAgriParcelActivity,
soilStructureResidentialAccessoryUseReason: noiSubmission.soilStructureResidentialAccessoryUseReason,
soilStructureOtherUseReason: noiSubmission.soilStructureOtherUseReason,
});

if (this.showErrors) {
this.structuresForm.markAllAsTouched();
this.form.markAllAsTouched();
Expand Down Expand Up @@ -349,9 +349,10 @@ export class AdditionalInformationComponent extends FilesStepComponent implement
}
}

private setStructureTypeInput(structure: FormProposedStructure, value: STRUCTURE_TYPES) {
structure.type = value;
private setStructureTypeInput(structure: FormProposedStructure, newType: STRUCTURE_TYPES) {
structure.type = newType;
this.prepareStructureSpecificTextInputs();
this.structuresForm.get(`${structure.id}-type`)?.setValue(newType);
this.form.markAsDirty();
}

Expand Down Expand Up @@ -505,7 +506,7 @@ export class AdditionalInformationComponent extends FilesStepComponent implement
return item.type === STRUCTURE_TYPES.PRINCIPAL_RESIDENCE || item.type === STRUCTURE_TYPES.ADDITIONAL_RESIDENCE;
}

private addControl(area: number | null = null) {
private addControl(area: number | null = null): FormProposedStructure {
const areaStr = area ? area.toString(10) : null;
const newStructure: FormProposedStructure = { type: null, area: areaStr, id: v4() };
this.proposedStructures.push(newStructure);
Expand Down

0 comments on commit 8df61a1

Please sign in to comment.