[batch-f] Extend CardSelectionSheet test into PaymentCardView

testConfirmarEPagarWithCreditCardOpensCardSelectionWithoutSubmitting now
also taps CardSelectionSheet's "Adicionar novo cartão", which opens
PaymentCardView (CheckoutView.swift's own card-entry form - a distinct
struct from AddCardFormView.swift, which is a separate screen reached
from Profile -> Meus Cartões and already covered). Doesn't fill or
submit anything, just reaches the form and dismisses back through both
sheets.

Extracted the shared "x" close-button dismiss logic (used by both
CardSelectionSheet and PaymentCardView) into a private
dismissViaCloseButton helper.

Verified stable across 2 consecutive class-level runs.
This commit is contained in:
Daniel Arantes Loverde
2026-08-12 10:43:47 -03:00
parent fff087c402
commit b68cd92307

View File

@@ -96,22 +96,37 @@ final class CartCheckoutFlowTests: XCTestCase {
app.buttons["Confirmar e Pagar"].tap() app.buttons["Confirmar e Pagar"].tap()
XCTAssertTrue(app.staticTexts["Selecionar Cartão"].waitForExistence(timeout: 10), "Never reached the card selection sheet") XCTAssertTrue(app.staticTexts["Selecionar Cartão"].waitForExistence(timeout: 10), "Never reached the card selection sheet")
// Dismiss via the sheet's own "x" close button - never selects a // "Adicionar novo cartão" opens PaymentCardView (CheckoutView.swift's
// card, never submits anything. // own card-entry form - a different struct from AddCardFormView.swift,
// reached from Profile -> Meus Cartões, needs its own coverage) as a
// sheet on top. Only fills nothing and dismisses - no card saved, no
// order created.
app.buttons["Adicionar novo cartão"].tap()
XCTAssertTrue(
app.staticTexts["Novo Cartão"].waitForExistence(timeout: 10),
"Adicionar novo cartão never opened PaymentCardView"
)
dismissViaCloseButton(app)
XCTAssertTrue(app.staticTexts["Selecionar Cartão"].waitForExistence(timeout: 10), "Never returned to card selection")
dismissViaCloseButton(app)
XCTAssertTrue(app.staticTexts["Finalizar Pedido"].waitForExistence(timeout: 10), "Never returned to Checkout")
}
/// Dismisses via the topmost sheet's "x" close button
/// (`identifier: "xmark"`) - shared by `CardSelectionSheet` and
/// `PaymentCardView`. `.firstMatch` tolerates a lower sheet's own
/// close button still existing underneath in the accessibility tree.
private func dismissViaCloseButton(_ app: XCUIApplication) {
let closeButton = app.buttons.matching(identifier: "xmark").firstMatch let closeButton = app.buttons.matching(identifier: "xmark").firstMatch
var dismissed = false
for _ in 0..<10 { for _ in 0..<10 {
if closeButton.exists, closeButton.isHittable { if closeButton.exists, closeButton.isHittable {
closeButton.tap() closeButton.tap()
dismissed = true return
break
} }
usleep(200_000) usleep(200_000)
} }
if dismissed == false { app.swipeDown()
app.swipeDown()
}
XCTAssertTrue(app.staticTexts["Finalizar Pedido"].waitForExistence(timeout: 10), "Never returned to Checkout")
} }
private func reachCheckoutWithOneItem(_ app: XCUIApplication) throws { private func reachCheckoutWithOneItem(_ app: XCUIApplication) throws {