Complete re-validation remediation: KMP architecture, iOS platform, XCUITest rewrite
Phases 1-6 of fixes.md — closes all 13 issues from codex_issues_2.md re-validation: KMP Architecture: - Fix subscription purchase/restore response contract (VerificationResponse aligned) - Add feature benefits auth token + APILayer init flow - Remove ResidenceFormScreen direct API bypass (use APILayer) - Wire paywall purchase/restore to real SubscriptionApi calls iOS Platform: - Add iOS Keychain token storage via Swift KeychainHelper - Implement Google Sign-In via ASWebAuthenticationSession (GoogleSignInManager) - DocumentViewModelWrapper observes DataManager for auto-updates - Add missing accessibility identifiers (document, task columns, Google Sign-In) XCUITest Rewrite: - Rewrite test infrastructure: zero sleep() calls, accessibility ID lookups - Create AuthCriticalPathTests and NavigationCriticalPathTests - Delete 14 legacy brittle test files (Suite0-10, templates) - Fix CaseraTests module import (@testable import Casera) All platforms build clean. TEST BUILD SUCCEEDED. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,49 +1,43 @@
|
||||
import XCTest
|
||||
|
||||
/// Reusable helper functions for UI tests
|
||||
/// Reusable helper functions for UI tests.
|
||||
/// All waits use explicit conditions — zero sleep() calls.
|
||||
struct UITestHelpers {
|
||||
|
||||
// MARK: - Authentication Helpers
|
||||
|
||||
/// Logs out the user if they are currently logged in
|
||||
/// - Parameter app: The XCUIApplication instance
|
||||
/// Logs out the user if they are currently logged in.
|
||||
static func logout(app: XCUIApplication) {
|
||||
sleep(2)
|
||||
|
||||
// Check if already logged out (login screen visible)
|
||||
let welcomeText = app.staticTexts["Welcome Back"]
|
||||
if welcomeText.exists {
|
||||
// Already logged out
|
||||
if welcomeText.waitForExistence(timeout: 3) {
|
||||
return
|
||||
}
|
||||
|
||||
// Check if we have a tab bar (logged in state)
|
||||
let tabBar = app.tabBars.firstMatch
|
||||
guard tabBar.exists else { return }
|
||||
guard tabBar.waitForExistence(timeout: 3) else { return }
|
||||
|
||||
// Navigate to Residences tab first
|
||||
let residencesTab = app.tabBars.buttons.containing(NSPredicate(format: "label CONTAINS[c] 'Residences'")).firstMatch
|
||||
let residencesTab = app.tabBars.buttons[AccessibilityIdentifiers.Navigation.residencesTab]
|
||||
if residencesTab.exists {
|
||||
residencesTab.tap()
|
||||
sleep(1)
|
||||
}
|
||||
|
||||
// Tap settings button
|
||||
let settingsButton = app.buttons[AccessibilityIdentifiers.Navigation.settingsButton]
|
||||
if settingsButton.waitForExistence(timeout: 3) && settingsButton.isHittable {
|
||||
if settingsButton.waitForExistence(timeout: 5) {
|
||||
settingsButton.tap()
|
||||
sleep(1)
|
||||
}
|
||||
|
||||
// Find and tap logout button
|
||||
let logoutButton = app.buttons[AccessibilityIdentifiers.Profile.logoutButton]
|
||||
if logoutButton.waitForExistence(timeout: 3) {
|
||||
if logoutButton.waitForExistence(timeout: 5) {
|
||||
logoutButton.tap()
|
||||
sleep(1)
|
||||
|
||||
// Confirm logout in alert if present - specifically target the alert's button
|
||||
// Confirm logout in alert if present
|
||||
let alert = app.alerts.firstMatch
|
||||
if alert.waitForExistence(timeout: 2) {
|
||||
if alert.waitForExistence(timeout: 3) {
|
||||
let confirmLogout = alert.buttons["Log Out"]
|
||||
if confirmLogout.exists {
|
||||
confirmLogout.tap()
|
||||
@@ -51,25 +45,21 @@ struct UITestHelpers {
|
||||
}
|
||||
}
|
||||
|
||||
sleep(2)
|
||||
|
||||
// Verify we're back on login screen
|
||||
XCTAssertTrue(welcomeText.waitForExistence(timeout: 5), "Failed to log out - Welcome Back screen should appear after logout")
|
||||
XCTAssertTrue(
|
||||
welcomeText.waitForExistence(timeout: 10),
|
||||
"Failed to log out - Welcome Back screen should appear after logout"
|
||||
)
|
||||
}
|
||||
|
||||
/// Logs in a user with the provided credentials
|
||||
/// - Parameters:
|
||||
/// - app: The XCUIApplication instance
|
||||
/// - username: The username/email to use for login
|
||||
/// - password: The password to use for login
|
||||
/// Logs in a user with the provided credentials.
|
||||
static func login(app: XCUIApplication, username: String, password: String) {
|
||||
// Find username field by accessibility identifier
|
||||
let usernameField = app.textFields[AccessibilityIdentifiers.Authentication.usernameField]
|
||||
XCTAssertTrue(usernameField.waitForExistence(timeout: 5), "Username field should exist")
|
||||
usernameField.tap()
|
||||
usernameField.typeText(username)
|
||||
|
||||
// Find password field - it could be TextField (if visible) or SecureField
|
||||
// Password field may be SecureTextField or regular TextField
|
||||
var passwordField = app.secureTextFields[AccessibilityIdentifiers.Authentication.passwordField]
|
||||
if !passwordField.exists {
|
||||
passwordField = app.textFields[AccessibilityIdentifiers.Authentication.passwordField]
|
||||
@@ -78,42 +68,37 @@ struct UITestHelpers {
|
||||
passwordField.tap()
|
||||
passwordField.typeText(password)
|
||||
|
||||
// Find and tap login button
|
||||
let loginButton = app.buttons[AccessibilityIdentifiers.Authentication.loginButton]
|
||||
XCTAssertTrue(loginButton.waitForExistence(timeout: 3), "Login button should exist")
|
||||
loginButton.tap()
|
||||
|
||||
// Wait for login to complete
|
||||
sleep(3)
|
||||
// Wait for login to complete by checking for tab bar appearance
|
||||
let tabBar = app.tabBars.firstMatch
|
||||
_ = tabBar.waitForExistence(timeout: 15)
|
||||
}
|
||||
|
||||
/// Ensures the user is logged out before running a test
|
||||
/// - Parameter app: The XCUIApplication instance
|
||||
/// Ensures the user is logged out before running a test.
|
||||
static func ensureLoggedOut(app: XCUIApplication) {
|
||||
sleep(2)
|
||||
logout(app: app)
|
||||
}
|
||||
|
||||
/// Ensures the user is logged in with test credentials before running a test
|
||||
/// - Parameter app: The XCUIApplication instance
|
||||
/// - Parameter username: Optional username (defaults to "testuser")
|
||||
/// - Parameter password: Optional password (defaults to "TestPass123!")
|
||||
static func ensureLoggedIn(app: XCUIApplication, username: String = "testuser", password: String = "TestPass123!") {
|
||||
sleep(2)
|
||||
|
||||
/// Ensures the user is logged in with test credentials before running a test.
|
||||
static func ensureLoggedIn(
|
||||
app: XCUIApplication,
|
||||
username: String = "testuser",
|
||||
password: String = "TestPass123!"
|
||||
) {
|
||||
// Check if already logged in (tab bar visible)
|
||||
let tabBar = app.tabBars.firstMatch
|
||||
if tabBar.exists {
|
||||
return // Already logged in
|
||||
if tabBar.waitForExistence(timeout: 5) {
|
||||
return
|
||||
}
|
||||
|
||||
// Check if on login screen
|
||||
let usernameField = app.textFields[AccessibilityIdentifiers.Authentication.usernameField]
|
||||
if usernameField.waitForExistence(timeout: 5) {
|
||||
login(app: app, username: username, password: password)
|
||||
|
||||
// Wait for main screen to appear
|
||||
_ = tabBar.waitForExistence(timeout: 10)
|
||||
_ = tabBar.waitForExistence(timeout: 15)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user