Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add prototype for enable/disable removal of spms #3577

Merged
merged 7 commits into from
May 15, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1012,12 +1012,13 @@ class CustomerSheetUITest: XCTestCase {
XCTAssertFalse(app.buttons["Remove card"].exists)
}
// MARK: - PaymentMethodRemove w/ CBC
func testPaymentMethodRemove() throws {
func testCSPaymentMethodRemoveTwoCards() throws {
var settings = CustomerSheetTestPlaygroundSettings.defaultValues()
settings.merchantCountryCode = .FR
settings.customerMode = .new
settings.applePay = .on
settings.paymentMethodRemove = .disabled
settings.allowsRemovalOfLastSavedPaymentMethod = .on
loadPlayground(
app,
settings
Expand Down Expand Up @@ -1054,6 +1055,40 @@ class CustomerSheetUITest: XCTestCase {
app.buttons["Close"].waitForExistenceAndTap(timeout: timeout)
}

func testCSPaymentMethodRemoveTwoCards_keeplastSavedPaymentMethod_CBC() throws {
var settings = CustomerSheetTestPlaygroundSettings.defaultValues()
settings.merchantCountryCode = .FR
settings.customerMode = .new
settings.applePay = .on
settings.paymentMethodRemove = .disabled
settings.allowsRemovalOfLastSavedPaymentMethod = .off
loadPlayground(
app,
settings
)

// Save a card
app.staticTexts["None"].waitForExistenceAndTap()
app.buttons["+ Add"].waitForExistenceAndTap()
try! fillCardData(app, cardNumber: "4000002500001001", postalEnabled: true)
app.buttons["Save"].tap()
XCTAssertTrue(app.buttons["Confirm"].waitForExistence(timeout: timeout))

// Should be able to edit because of CBC saved PMs
XCTAssertTrue(app.staticTexts["Edit"].waitForExistenceAndTap())
XCTAssertTrue(app.staticTexts["Done"].waitForExistence(timeout: 1)) // Sanity check "Done" button is there

// Assert there are no remove buttons on each tile and the update screen
XCTAssertNil(scroll(collectionView: app.collectionViews.firstMatch, toFindButtonWithId: "CircularButton.Remove"))
XCTAssertTrue(app.buttons["CircularButton.Edit"].waitForExistenceAndTap(timeout: timeout))
XCTAssertFalse(app.buttons["Remove card"].exists)

// Dismiss Sheet
app.buttons["Back"].waitForExistenceAndTap(timeout: timeout)
app.buttons["Done"].waitForExistenceAndTap(timeout: timeout)
app.buttons["Close"].waitForExistenceAndTap(timeout: timeout)
}

// MARK: - Helpers

func presentCSAndAddCardFrom(buttonLabel: String, cardNumber: String? = nil, tapAdd: Bool = true) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2461,7 +2461,7 @@ class PaymentSheetDeferredServerSideUITests: PaymentSheetUITestCase {
}

// MARK: - PaymentMethodRemoval w/ CBC
func testPaymentMethodRemove() {
func testPSPaymentMethodRemoveTwoCards() {

var settings = PaymentSheetTestPlaygroundSettings.defaultValues()
settings.mode = .paymentWithSetup
Expand All @@ -2473,6 +2473,7 @@ class PaymentSheetDeferredServerSideUITests: PaymentSheetUITestCase {
settings.applePayEnabled = .on
settings.apmsEnabled = .off
settings.paymentMethodRemove = .disabled
settings.allowsRemovalOfLastSavedPaymentMethod = .on

loadPlayground(
app,
Expand Down Expand Up @@ -2510,7 +2511,49 @@ class PaymentSheetDeferredServerSideUITests: PaymentSheetUITestCase {
app.buttons["Done"].waitForExistenceAndTap(timeout: 5)
app.buttons["Close"].waitForExistenceAndTap(timeout: 5)
}
func testPSPaymentMethodRemoveDisabled_keeplastSavedPaymentMethod_CBC() {

var settings = PaymentSheetTestPlaygroundSettings.defaultValues()
settings.mode = .paymentWithSetup
settings.uiStyle = .paymentSheet
settings.customerKeyType = .customerSession
settings.customerMode = .new
settings.merchantCountryCode = .FR
settings.currency = .eur
settings.applePayEnabled = .on
settings.apmsEnabled = .off
settings.paymentMethodRemove = .disabled
settings.allowsRemovalOfLastSavedPaymentMethod = .off

loadPlayground(
app,
settings
)

app.buttons["Present PaymentSheet"].waitForExistenceAndTap()

try! fillCardData(app, cardNumber: "4000002500001001", postalEnabled: true)

// Complete payment
app.buttons["Pay €50.99"].tap()
XCTAssertTrue(app.staticTexts["Success!"].waitForExistence(timeout: 10.0))

// Reload w/ same customer
reload(app, settings: settings)

app.buttons["Present PaymentSheet"].waitForExistenceAndTap()
XCTAssertTrue(app.staticTexts["Edit"].waitForExistenceAndTap())
XCTAssertTrue(app.staticTexts["Done"].waitForExistence(timeout: 1)) // Sanity check "Done" button is there

// Detect there are no remove buttons on each tile and the update screen
XCTAssertNil(scroll(collectionView: app.collectionViews.firstMatch, toFindButtonWithId: "CircularButton.Remove")?.tap())
XCTAssertTrue(app.buttons["CircularButton.Edit"].waitForExistenceAndTap(timeout: 5))
XCTAssertFalse(app.buttons["Remove card"].exists)

app.buttons["Back"].waitForExistenceAndTap(timeout: 5)
app.buttons["Done"].waitForExistenceAndTap(timeout: 5)
app.buttons["Close"].waitForExistenceAndTap(timeout: 5)
}
func testPreservesSelectionAfterDismissPaymentSheetFlowController() throws {
var settings = PaymentSheetTestPlaygroundSettings.defaultValues()
settings.uiStyle = .flowController
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,9 @@ class CustomerSavedPaymentMethodsCollectionViewController: UIViewController {
return false
case 1:
// If there's exactly one PM, customer can only edit if configuration allows removal or if that single PM is editable
return savedPaymentMethodsConfiguration.paymentMethodRemove && (configuration.allowsRemovalOfLastSavedPaymentMethod || viewModels.contains(where: {
return (savedPaymentMethodsConfiguration.paymentMethodRemove && configuration.allowsRemovalOfLastSavedPaymentMethod) || viewModels.contains(where: {
$0.isCoBrandedCard && cbcEligible
}))
})
default:
return savedPaymentMethodsConfiguration.paymentMethodRemove || viewModels.contains(where: {
$0.isCoBrandedCard && cbcEligible
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,9 @@ class SavedPaymentOptionsViewController: UIViewController {
return false
case 1:
// If there's exactly one PM, customer can only edit if configuration allows removal or if that single PM allows for the card brand choice to be updated.
return paymentSheetConfiguration.paymentMethodRemove && (configuration.allowsRemovalOfLastSavedPaymentMethod || viewModels.contains(where: {
return (paymentSheetConfiguration.paymentMethodRemove && configuration.allowsRemovalOfLastSavedPaymentMethod) || viewModels.contains(where: {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like ideally we unit test canEditPaymentMethods instead of testing via UI test. That way we can test that various combos of paymentMethodRemove, allowsRemovalOfLastSavedPaymentMethod, and PMs produce the right value. Feel free to ticket.

Copy link
Collaborator Author

@wooj-stripe wooj-stripe May 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding a ticket. will be done as part of the CustomerSessions work stream.

$0.isCoBrandedCard && cbcEligible
}))
})
default:
return paymentSheetConfiguration.paymentMethodRemove || viewModels.contains(where: {
$0.isCoBrandedCard && cbcEligible
Expand Down
Loading