diff --git a/PediFoodsUITests/CartCheckoutFlowTests.swift b/PediFoodsUITests/CartCheckoutFlowTests.swift index 170d579..0a1fae2 100644 --- a/PediFoodsUITests/CartCheckoutFlowTests.swift +++ b/PediFoodsUITests/CartCheckoutFlowTests.swift @@ -96,22 +96,37 @@ final class CartCheckoutFlowTests: XCTestCase { app.buttons["Confirmar e Pagar"].tap() 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 - // card, never submits anything. + // "Adicionar novo cartão" opens PaymentCardView (CheckoutView.swift's + // 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 - var dismissed = false for _ in 0..<10 { if closeButton.exists, closeButton.isHittable { closeButton.tap() - dismissed = true - break + return } usleep(200_000) } - if dismissed == false { - app.swipeDown() - } - XCTAssertTrue(app.staticTexts["Finalizar Pedido"].waitForExistence(timeout: 10), "Never returned to Checkout") + app.swipeDown() } private func reachCheckoutWithOneItem(_ app: XCUIApplication) throws {