Files
honeyDueKMP/iosApp/CaseraUITests/SimpleLoginTest.swift

63 lines
2.4 KiB
Swift

import XCTest
/// Simple test to verify basic app launch and login screen
/// This is the foundation test - if this works, we can build more complex tests
final class SimpleLoginTest: BaseUITestCase {
override var includeResetStateLaunchArgument: Bool { false }
override func setUpWithError() throws {
try super.setUpWithError()
// CRITICAL: Ensure we're logged out before each test
ensureLoggedOut()
}
override func tearDownWithError() throws {
try super.tearDownWithError()
}
// MARK: - Helper Methods
/// Ensures the user is logged out and on the login screen
private func ensureLoggedOut() {
UITestHelpers.ensureLoggedOut(app: app)
}
// MARK: - Tests
/// Test 1: App launches and shows login screen (or logs out if needed)
func testAppLaunchesAndShowsLoginScreen() {
// After ensureLoggedOut(), we should be on login screen
let welcomeText = app.textFields[AccessibilityIdentifiers.Authentication.usernameField]
XCTAssertTrue(welcomeText.exists, "Login screen with 'Welcome Back' text should appear after logout")
// Also check that we have a username field
let usernameField = app.textFields.containing(NSPredicate(format: "placeholderValue CONTAINS[c] 'email'")).firstMatch
XCTAssertTrue(usernameField.exists, "Username/email field should exist")
}
/// Test 2: Can type in username and password fields
func testCanTypeInLoginFields() {
// Already logged out from setUp
// Find and tap username field
let usernameField = app.textFields.containing(NSPredicate(format: "placeholderValue CONTAINS[c] 'email'")).firstMatch
XCTAssertTrue(usernameField.waitForExistence(timeout: 10), "Username field should exist")
usernameField.tap()
usernameField.typeText("testuser")
// Find password field (could be TextField or SecureField)
let passwordField = app.secureTextFields.containing(NSPredicate(format: "placeholderValue CONTAINS[c] 'password'")).firstMatch
XCTAssertTrue(passwordField.exists, "Password field should exist")
passwordField.tap()
passwordField.typeText("testpass123")
// Verify we can see a Sign In button
let signInButton = app.buttons.containing(NSPredicate(format: "label CONTAINS[c] 'Sign In'")).firstMatch
XCTAssertTrue(signInButton.exists, "Sign In button should exist")
}
}