Skip to content

Commit

Permalink
Clear securityCode viewValue on switchPayment.
Browse files Browse the repository at this point in the history
  • Loading branch information
wjames111 committed Nov 19, 2024
1 parent 75d2d3b commit 67b31b4
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
}
}
})
}))

Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -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()
})
})
})
})
Expand Down

0 comments on commit 67b31b4

Please sign in to comment.