diff --git a/libs/vault/src/cipher-form/components/item-details/item-details-section.component.spec.ts b/libs/vault/src/cipher-form/components/item-details/item-details-section.component.spec.ts index 4da299ed039..67b5509c8ac 100644 --- a/libs/vault/src/cipher-form/components/item-details/item-details-section.component.spec.ts +++ b/libs/vault/src/cipher-form/components/item-details/item-details-section.component.spec.ts @@ -135,7 +135,7 @@ describe("ItemDetailsSectionComponent", () => { tick(); expect(cipherFormProvider.patchCipher).toHaveBeenCalled(); - const patchFn = cipherFormProvider.patchCipher.mock.lastCall[0]; + const patchFn = cipherFormProvider.patchCipher.mock.lastCall![0]; const updatedCipher = patchFn(new CipherView()); @@ -165,7 +165,7 @@ describe("ItemDetailsSectionComponent", () => { tick(); expect(cipherFormProvider.patchCipher).toHaveBeenCalled(); - const patchFn = cipherFormProvider.patchCipher.mock.lastCall[0]; + const patchFn = cipherFormProvider.patchCipher.mock.lastCall![0]; const updatedCipher = patchFn(new CipherView()); @@ -440,7 +440,7 @@ describe("ItemDetailsSectionComponent", () => { await fixture.whenStable(); expect(cipherFormProvider.patchCipher).toHaveBeenCalled(); - const patchFn = cipherFormProvider.patchCipher.mock.lastCall[0]; + const patchFn = cipherFormProvider.patchCipher.mock.lastCall![0]; const updatedCipher = patchFn(new CipherView()); @@ -691,6 +691,35 @@ describe("ItemDetailsSectionComponent", () => { expect(enableFormFields).toHaveBeenCalled(); }); }); + + describe("setFormState behavior with null/undefined", () => { + it("calls disableFormFields when organizationId value is null", async () => { + component.originalCipherView.organizationId = null as any; + getInitialCipherView.mockReturnValue(component.originalCipherView); + + await component.ngOnInit(); + + expect(disableFormFields).toHaveBeenCalled(); + }); + + it("calls disableFormFields when organizationId value is undefined", async () => { + component.originalCipherView.organizationId = undefined; + getInitialCipherView.mockReturnValue(component.originalCipherView); + + await component.ngOnInit(); + + expect(disableFormFields).toHaveBeenCalled(); + }); + + it("calls enableFormFields when organizationId has a string value", async () => { + component.originalCipherView.organizationId = "org-id" as any; + getInitialCipherView.mockReturnValue(component.originalCipherView); + + await component.ngOnInit(); + + expect(enableFormFields).toHaveBeenCalled(); + }); + }); }); describe("when an ownership change is not allowed", () => { diff --git a/libs/vault/src/cipher-form/components/item-details/item-details-section.component.ts b/libs/vault/src/cipher-form/components/item-details/item-details-section.component.ts index 8877b4cbcea..ce0244bc759 100644 --- a/libs/vault/src/cipher-form/components/item-details/item-details-section.component.ts +++ b/libs/vault/src/cipher-form/components/item-details/item-details-section.component.ts @@ -125,7 +125,7 @@ export class ItemDetailsSectionComponent implements OnInit { this.itemDetailsForm.controls.organizationId.disabled || (!this.allowPersonalOwnership && this.config.originalCipher && - this.itemDetailsForm.controls.organizationId.value === null) + this.itemDetailsForm.controls.organizationId.value == null) ); } @@ -252,7 +252,7 @@ export class ItemDetailsSectionComponent implements OnInit { // When editing a cipher and the user cannot have personal ownership // and the cipher is is not within the organization - force the user to // move the cipher within the organization first before editing any other field - if (this.itemDetailsForm.controls.organizationId.value === null) { + if (this.itemDetailsForm.controls.organizationId.value == null) { this.cipherFormContainer.disableFormFields(); this.itemDetailsForm.controls.organizationId.enable(); this.favoriteButtonDisabled = true;