mirror of
https://github.com/bitwarden/browser
synced 2026-02-07 04:03:29 +00:00
[PM-30845] fix(vault): preserve card brand when editing existing card (#18381)
* fix(vault): preserve card brand when editing existing card Fixes #16978 The brand field was not being restored when editing an existing card cipher, causing it to show '--Select--' and potentially lose the brand data when saving. Added the brand field to initFromExistingCipher() to properly restore the card brand when opening a card for editing. Also updated the test to verify all card fields including brand, expMonth, and expYear are properly initialized from existing cipher data. * fix: add brand to OptionalInitialValues interface Addresses review feedback from @jengstrom-bw in PR #18381. The brand field was being used in card-details-section.component.ts but wasn't defined in the OptionalInitialValues type, causing a TypeScript compilation error. Adds brand?: string; to the Credit Card Information section of OptionalInitialValues in cipher-form-config.service.ts. * test: add coverage for initFromExistingCipher brand logic
This commit is contained in:
@@ -28,6 +28,7 @@ export type OptionalInitialValues = {
|
||||
// Credit Card Information
|
||||
cardholderName?: string;
|
||||
number?: string;
|
||||
brand?: string;
|
||||
expMonth?: string;
|
||||
expYear?: string;
|
||||
code?: string;
|
||||
|
||||
@@ -108,12 +108,17 @@ describe("CardDetailsSectionComponent", () => {
|
||||
const cardholderName = "Ron Burgundy";
|
||||
const number = "4242 4242 4242 4242";
|
||||
const code = "619";
|
||||
const brand = "Maestro";
|
||||
const expMonth = "5";
|
||||
const expYear = "2028";
|
||||
|
||||
const cardView = new CardView();
|
||||
cardView.cardholderName = cardholderName;
|
||||
cardView.number = number;
|
||||
cardView.code = code;
|
||||
cardView.brand = "Visa";
|
||||
cardView.brand = brand;
|
||||
cardView.expMonth = expMonth;
|
||||
cardView.expYear = expYear;
|
||||
|
||||
getInitialCipherView.mockReturnValueOnce({ card: cardView });
|
||||
|
||||
@@ -123,7 +128,9 @@ describe("CardDetailsSectionComponent", () => {
|
||||
cardholderName,
|
||||
number,
|
||||
code,
|
||||
brand: cardView.brand,
|
||||
brand,
|
||||
expMonth,
|
||||
expYear,
|
||||
});
|
||||
});
|
||||
|
||||
@@ -154,4 +161,27 @@ describe("CardDetailsSectionComponent", () => {
|
||||
|
||||
expect(heading.nativeElement.textContent.trim()).toBe("cardDetails");
|
||||
});
|
||||
|
||||
it("initializes `cardDetailsForm` from `initialValues` when provided and editing existing cipher", () => {
|
||||
const initialCardholderName = "New Name";
|
||||
const initialBrand = "Amex";
|
||||
|
||||
(cipherFormProvider as any).config = {
|
||||
initialValues: {
|
||||
cardholderName: initialCardholderName,
|
||||
brand: initialBrand,
|
||||
},
|
||||
};
|
||||
|
||||
const existingCard = new CardView();
|
||||
existingCard.cardholderName = "Old Name";
|
||||
existingCard.brand = "Visa";
|
||||
|
||||
getInitialCipherView.mockReturnValueOnce({ card: existingCard });
|
||||
|
||||
component.ngOnInit();
|
||||
|
||||
expect(component.cardDetailsForm.value.cardholderName).toBe(initialCardholderName);
|
||||
expect(component.cardDetailsForm.value.brand).toBe(initialBrand);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -158,6 +158,7 @@ export class CardDetailsSectionComponent implements OnInit {
|
||||
this.cardDetailsForm.patchValue({
|
||||
cardholderName: this.initialValues?.cardholderName ?? existingCard.cardholderName,
|
||||
number: this.initialValues?.number ?? existingCard.number,
|
||||
brand: this.initialValues?.brand ?? existingCard.brand,
|
||||
expMonth: this.initialValues?.expMonth ?? existingCard.expMonth,
|
||||
expYear: this.initialValues?.expYear ?? existingCard.expYear,
|
||||
code: this.initialValues?.code ?? existingCard.code,
|
||||
|
||||
Reference in New Issue
Block a user