mirror of
https://github.com/bitwarden/browser
synced 2025-12-18 17:23:37 +00:00
[PM-9190] Use updateFn for patchCipher so that the current CipherView is available for context (#10258)
This commit is contained in:
@@ -62,9 +62,11 @@ describe("CardDetailsSectionComponent", () => {
|
||||
cardView.number = "4242 4242 4242 4242";
|
||||
cardView.brand = "Visa";
|
||||
|
||||
expect(patchCipherSpy).toHaveBeenCalledWith({
|
||||
card: cardView,
|
||||
});
|
||||
expect(patchCipherSpy).toHaveBeenCalled();
|
||||
const patchFn = patchCipherSpy.mock.lastCall[0];
|
||||
|
||||
const updateCipher = patchFn(new CipherView());
|
||||
expect(updateCipher.card).toEqual(cardView);
|
||||
});
|
||||
|
||||
it("it converts the year integer to a string", () => {
|
||||
@@ -75,9 +77,11 @@ describe("CardDetailsSectionComponent", () => {
|
||||
const cardView = new CardView();
|
||||
cardView.expYear = "2022";
|
||||
|
||||
expect(patchCipherSpy).toHaveBeenCalledWith({
|
||||
card: cardView,
|
||||
});
|
||||
expect(patchCipherSpy).toHaveBeenCalled();
|
||||
const patchFn = patchCipherSpy.mock.lastCall[0];
|
||||
|
||||
const updatedCipher = patchFn(new CipherView());
|
||||
expect(updatedCipher.card).toEqual(cardView);
|
||||
});
|
||||
|
||||
it('disables `cardDetailsForm` when "disabled" is true', () => {
|
||||
|
||||
@@ -90,9 +90,6 @@ export class CardDetailsSectionComponent implements OnInit {
|
||||
{ name: "12 - " + this.i18nService.t("december"), value: "12" },
|
||||
];
|
||||
|
||||
/** Local CardView, either created empty or set to the existing card instance */
|
||||
private cardView: CardView;
|
||||
|
||||
constructor(
|
||||
private cipherFormContainer: CipherFormContainer,
|
||||
private formBuilder: FormBuilder,
|
||||
@@ -103,21 +100,21 @@ export class CardDetailsSectionComponent implements OnInit {
|
||||
this.cardDetailsForm.valueChanges
|
||||
.pipe(takeUntilDestroyed())
|
||||
.subscribe(({ cardholderName, number, brand, expMonth, expYear, code }) => {
|
||||
// The input[type="number"] is returning a number, convert it to a string
|
||||
// An empty field returns null, avoid casting `"null"` to a string
|
||||
const expirationYear = expYear !== null ? `${expYear}` : null;
|
||||
this.cipherFormContainer.patchCipher((cipher) => {
|
||||
// The input[type="number"] is returning a number, convert it to a string
|
||||
// An empty field returns null, avoid casting `"null"` to a string
|
||||
const expirationYear = expYear !== null ? `${expYear}` : null;
|
||||
|
||||
const patchedCard = Object.assign(this.cardView, {
|
||||
cardholderName,
|
||||
number,
|
||||
brand,
|
||||
expMonth,
|
||||
expYear: expirationYear,
|
||||
code,
|
||||
});
|
||||
Object.assign(cipher.card, {
|
||||
cardholderName,
|
||||
number,
|
||||
brand,
|
||||
expMonth,
|
||||
expYear: expirationYear,
|
||||
code,
|
||||
});
|
||||
|
||||
this.cipherFormContainer.patchCipher({
|
||||
card: patchedCard,
|
||||
return cipher;
|
||||
});
|
||||
});
|
||||
|
||||
@@ -133,9 +130,6 @@ export class CardDetailsSectionComponent implements OnInit {
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
// If the original cipher has a card, use it. Otherwise, create a new card instance
|
||||
this.cardView = this.originalCipherView?.card ?? new CardView();
|
||||
|
||||
if (this.originalCipherView?.card) {
|
||||
this.setInitialValues();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user