import XCTest /// Covers the guest (unauthenticated) Home screen - confirmed reachable /// and stable, see decisions/2026-08-06-ui-test-account-and-app-attest-bypass.md. /// Authenticated-only flows (real store data, cart checkout, orders) are /// blocked by a separate login-navigation issue documented there and are /// not covered here. final class HomeGuestFlowTests: XCTestCase { override func setUpWithError() throws { continueAfterFailure = false } /// Authenticated-flow tests no longer log out after themselves (see /// decisions/2026-09-11-ui-test-shared-login-session.md), so guest /// tests must force a clean logged-out state themselves right after /// launch, rather than assume one. private func launchGuestApp() -> XCUIApplication { let app = XCUIApplication() app.launch() app.logoutIfAuthenticated() return app } func testHomeRendersSearchAndGreeting() throws { let app = launchGuestApp() XCTAssertTrue(app.reachGuestHome(), "Never reached Home's search field") XCTAssertTrue(app.staticTexts["ENTREGAR EM:"].exists) XCTAssertTrue(app.textFields["Search menu, restaurant or craving"].exists) XCTAssertTrue(app.images["bell"].exists, "Notifications bell missing") } func testHomeShowsDefaultCategoryChip() throws { let app = launchGuestApp() XCTAssertTrue(app.reachGuestHome()) XCTAssertTrue(app.staticTexts["Categories"].exists) XCTAssertTrue(app.staticTexts["Todas"].exists, "Default 'Todas' category chip missing") } func testHomeShowsGuestLocationPromptWhenNoLocationChosen() throws { let app = launchGuestApp() XCTAssertTrue(app.reachGuestHome()) // No guest state/city selected -> Home's own inline message, not // the blocking sheet (which we just dismissed to get here). XCTAssertTrue(app.staticTexts["Escolha um estado e cidade para visualizar os estabelecimentos."].waitForExistence(timeout: 3)) } func testTappingAddressChipReopensLocationPicker() throws { let app = launchGuestApp() XCTAssertTrue(app.reachGuestHome()) // The "ENTREGAR EM:" address button re-opens the same address // picker sheet we dismissed to reach Home - confirms the chip is // wired to the real activeModal state, not just decorative. let addressChip = app.buttons.matching(NSPredicate(format: "identifier == 'chevron.down'")).firstMatch if addressChip.exists { addressChip.tap() } else { // Fall back to tapping near the "ENTREGAR EM:" label's row. app.staticTexts["ENTREGAR EM:"].tap() } XCTAssertTrue( app.staticTexts["Escolha seu estado"].waitForExistence(timeout: 3) || app.staticTexts["Escolha sua cidade"].waitForExistence(timeout: 3), "Tapping the address chip did not reopen the location picker" ) } // No testSearchFieldAcceptsTextInput here: the guest address-picker // sheet re-presents on an independent timer (see // decisions/2026-08-06-ui-test-account-and-app-attest-bypass.md) and // can land back on top between a tap and the following `typeText`, // which XCTest treats as a fatal, non-catchable event-synthesis // failure - unlike `.exists` checks, there is no reliable way to guard // against it. Confirmed via accessibility-hierarchy dump that the sheet // was back on top at the moment of failure. Dropped rather than // papered over with more retries. }