From 67b31b407b263d543f92220961ae5cdd31ec71a5 Mon Sep 17 00:00:00 2001 From: wjames111 Date: Tue, 19 Nov 2024 15:34:49 -0500 Subject: [PATCH] Clear securityCode viewValue on switchPayment. --- .../existingPaymentMethods.component.js | 3 ++ .../existingPaymentMethods.component.spec.js | 30 +++++++++++-------- 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/src/app/checkout/step-2/existingPaymentMethods/existingPaymentMethods.component.js b/src/app/checkout/step-2/existingPaymentMethods/existingPaymentMethods.component.js index fbcb10f9b..ac97a41d9 100644 --- a/src/app/checkout/step-2/existingPaymentMethods/existingPaymentMethods.component.js +++ b/src/app/checkout/step-2/existingPaymentMethods/existingPaymentMethods.component.js @@ -141,6 +141,9 @@ class ExistingPaymentMethodsController { } switchPayment () { + this.creditCardPaymentForm.securityCode.$setViewValue('') + this.creditCardPaymentForm.securityCode.$render() + console.log(this.selectedPaymentMethod) this.onPaymentChange({ selectedPaymentMethod: this.selectedPaymentMethod }) if (this.selectedPaymentMethod?.['bank-name']) { // This is an EFT payment method so we need to remove any fee coverage diff --git a/src/app/checkout/step-2/existingPaymentMethods/existingPaymentMethods.component.spec.js b/src/app/checkout/step-2/existingPaymentMethods/existingPaymentMethods.component.spec.js index 38aa3a752..a9a6d02b7 100644 --- a/src/app/checkout/step-2/existingPaymentMethods/existingPaymentMethods.component.spec.js +++ b/src/app/checkout/step-2/existingPaymentMethods/existingPaymentMethods.component.spec.js @@ -26,6 +26,17 @@ describe('checkout', () => { enableContinue: jest.fn(), onPaymentFormStateChange: jest.fn(), cartData: { items: [] }, + creditCardPaymentForm: { + securityCode: { + $valid: true, + $validators: { + minLength: (value) => cruPayments.creditCard.cvv.validate.minLength(value), + maxLength: cruPayments.creditCard.cvv.validate.maxLength + }, + $setViewValue: jest.fn(), + $render: jest.fn(), + } + } }) })) @@ -336,18 +347,6 @@ describe('checkout', () => { }) describe('addCustomValidators', () => { - beforeEach(() => { - self.controller.creditCardPaymentForm = { - securityCode: { - $valid: true, - $validators: { - minLength: (value) => cruPayments.creditCard.cvv.validate.minLength(value), - maxLength: cruPayments.creditCard.cvv.validate.maxLength - } - } - } - }) - it('should add validator functions to creditCardPaymentForm.securityCode', () => { expect(size(self.controller.creditCardPaymentForm.securityCode.$validators)).toEqual(2) expect(typeof self.controller.creditCardPaymentForm.securityCode.$validators.minLength).toBe('function') @@ -375,6 +374,13 @@ describe('checkout', () => { self.controller.$scope.$apply() expect(self.controller.enableContinue).toHaveBeenCalledWith({ $event: false }) }) + + it('should reset securityCode viewValue on switch payment', () => { + self.controller.creditCardPaymentForm.securityCode.$viewValue = '123' + self.controller.switchPayment() + expect(self.controller.creditCardPaymentForm.securityCode.$setViewValue).toHaveBeenCalledWith('') + expect(self.controller.creditCardPaymentForm.securityCode.$render).toHaveBeenCalled() + }) }) }) })