diff --git a/libs/vault/src/cipher-form/components/card-details-section/card-details-section.component.html b/libs/vault/src/cipher-form/components/card-details-section/card-details-section.component.html index c2c60f2a023..eacdae7f287 100644 --- a/libs/vault/src/cipher-form/components/card-details-section/card-details-section.component.html +++ b/libs/vault/src/cipher-form/components/card-details-section/card-details-section.component.html @@ -1,12 +1,7 @@

- - {{ "cardBrandDetails" | i18n: cardDetailsForm.value.brand }} - - - {{ "cardDetails" | i18n }} - + {{ getSectionHeading() }}

diff --git a/libs/vault/src/cipher-form/components/card-details-section/card-details-section.component.spec.ts b/libs/vault/src/cipher-form/components/card-details-section/card-details-section.component.spec.ts index 3ad13e1dbee..bcc86a3d2e0 100644 --- a/libs/vault/src/cipher-form/components/card-details-section/card-details-section.component.spec.ts +++ b/libs/vault/src/cipher-form/components/card-details-section/card-details-section.component.spec.ts @@ -28,7 +28,7 @@ describe("CardDetailsSectionComponent", () => { imports: [CardDetailsSectionComponent, CommonModule, ReactiveFormsModule], providers: [ { provide: CipherFormContainer, useValue: cipherFormProvider }, - { provide: I18nService, useValue: mock() }, + { provide: I18nService, useValue: { t: (key: string) => key } }, ], }).compileComponents(); }); @@ -122,4 +122,24 @@ describe("CardDetailsSectionComponent", () => { expect(component.cardDetailsForm.controls.brand.value).toBe("Visa"); }); + + it('displays brand heading text when "brand" is not "Other"', () => { + component.cardDetailsForm.patchValue({ + brand: "Visa", + }); + + fixture.detectChanges(); + + const heading = fixture.debugElement.query(By.css("h2")); + + expect(heading.nativeElement.textContent.trim()).toBe("cardBrandDetails"); + + component.cardDetailsForm.patchValue({ + brand: "Other", + }); + + fixture.detectChanges(); + + expect(heading.nativeElement.textContent.trim()).toBe("cardDetails"); + }); }); diff --git a/libs/vault/src/cipher-form/components/card-details-section/card-details-section.component.ts b/libs/vault/src/cipher-form/components/card-details-section/card-details-section.component.ts index b8bc4f35c4d..ecbddc3655f 100644 --- a/libs/vault/src/cipher-form/components/card-details-section/card-details-section.component.ts +++ b/libs/vault/src/cipher-form/components/card-details-section/card-details-section.component.ts @@ -145,6 +145,17 @@ export class CardDetailsSectionComponent implements OnInit { } } + /** Get the section heading based on the card brand */ + getSectionHeading(): string { + const { brand } = this.cardDetailsForm.value; + + if (brand && brand !== "Other") { + return this.i18nService.t("cardBrandDetails", brand); + } + + return this.i18nService.t("cardDetails"); + } + /** Set form initial form values from the current cipher */ private setInitialValues() { const { cardholderName, number, brand, expMonth, expYear, code } = this.originalCipherView.card;