Only auto-advance from cvc field when it is max possible length (#141)

This commit is contained in:
Cameron 2021-03-03 11:33:31 -08:00 committed by GitHub
parent fbd12ae891
commit fd9d0ed9f3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 89 additions and 0 deletions

View File

@ -68,6 +68,89 @@ class PaymentSheetUITest: XCTestCase {
okButton.tap()
}
func testCardFieldAutoAdvance() throws {
let app = XCUIApplication()
app.launch()
app.staticTexts[
"PaymentSheet"
].tap()
let buyButton = app.staticTexts["Buy"]
XCTAssertTrue(buyButton.waitForExistence(timeout: 60.0))
buyButton.tap()
let numberField = app.textFields["Card number"]
numberField.tap()
numberField.typeText("4242424242424242")
let expField = app.textFields["expiration date"]
XCTAssertTrue((expField.value as? String)?.isEmpty ?? true)
XCTAssertNoThrow(expField.typeText("1228"))
let cvcField = app.textFields["CVC"]
XCTAssertTrue((cvcField.value as? String)?.isEmpty ?? true)
XCTAssertNoThrow(cvcField.typeText("123"))
let postalField = app.textFields["ZIP"]
XCTAssertTrue((postalField.value as? String)?.isEmpty ?? true)
XCTAssertNoThrow(postalField.typeText("12345"))
}
func testCardFieldAutoAdvanceAutoTypeToPostalCode() throws {
let app = XCUIApplication()
app.launch()
app.staticTexts[
"PaymentSheet"
].tap()
let buyButton = app.staticTexts["Buy"]
XCTAssertTrue(buyButton.waitForExistence(timeout: 60.0))
buyButton.tap()
let numberField = app.textFields["Card number"]
numberField.tap()
numberField.typeText("4242424242424242")
let expField = app.textFields["expiration date"]
XCTAssertTrue((expField.value as? String)?.isEmpty ?? true)
XCTAssertNoThrow(expField.typeText("1228"))
let cvcField = app.textFields["CVC"]
XCTAssertTrue((cvcField.value as? String)?.isEmpty ?? true)
XCTAssertNoThrow(cvcField.typeText("1234"))
let postalField = app.textFields["ZIP"]
XCTAssertTrue((postalField.value as? String) ?? "" == "4")
}
func testCardFieldAutoAdvanceAmexCVV() throws {
let app = XCUIApplication()
app.launch()
app.staticTexts[
"PaymentSheet"
].tap()
let buyButton = app.staticTexts["Buy"]
XCTAssertTrue(buyButton.waitForExistence(timeout: 60.0))
buyButton.tap()
let numberField = app.textFields["Card number"]
numberField.tap()
numberField.typeText("378282246310005")
let expField = app.textFields["expiration date"]
XCTAssertTrue((expField.value as? String)?.isEmpty ?? true)
XCTAssertNoThrow(expField.typeText("1228"))
let cvvField = app.textFields["CVV"]
XCTAssertTrue((cvvField.value as? String)?.isEmpty ?? true)
XCTAssertNoThrow(cvvField.typeText("1234"))
let postalField = app.textFields["ZIP"]
XCTAssertTrue((postalField.value as? String)?.isEmpty ?? true)
XCTAssertNoThrow(postalField.typeText("12345"))
}
func testPaymentSheetCustom() throws {
let app = XCUIApplication()
app.launch()

View File

@ -169,6 +169,12 @@ class STPCardFormView: STPFormView {
} else {
return false
}
} else if input == cvcField{
if case .valid = validationState {
return (input.validator.inputValue?.count ?? 0) >= STPCardValidator.maxCVCLength(for: cvcField.cardBrand)
} else {
return false
}
} else if billingAddressSubForm.formSection.contains(input) {
return false
}