Rebrand from MyCrib to Casera
- Rename Kotlin package from com.example.mycrib to com.example.casera - Update Android app name, namespace, and application ID - Update iOS bundle identifiers and project settings - Rename iOS directories (MyCribTests -> CaseraTests, etc.) - Update deep link schemes from mycrib:// to casera:// - Update app group identifiers - Update subscription product IDs - Update all UI strings and branding 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
212
iosApp/CaseraUITests/AccessibilityIdentifiers.swift
Normal file
212
iosApp/CaseraUITests/AccessibilityIdentifiers.swift
Normal file
@@ -0,0 +1,212 @@
|
||||
import Foundation
|
||||
|
||||
/// Centralized accessibility identifiers for UI testing
|
||||
/// These identifiers are used by XCUITests to locate and interact with UI elements
|
||||
struct AccessibilityIdentifiers {
|
||||
|
||||
// MARK: - Authentication
|
||||
struct Authentication {
|
||||
static let usernameField = "Login.UsernameField"
|
||||
static let passwordField = "Login.PasswordField"
|
||||
static let loginButton = "Login.LoginButton"
|
||||
static let signUpButton = "Login.SignUpButton"
|
||||
static let forgotPasswordButton = "Login.ForgotPasswordButton"
|
||||
static let passwordVisibilityToggle = "Login.PasswordVisibilityToggle"
|
||||
|
||||
// Registration
|
||||
static let registerUsernameField = "Register.UsernameField"
|
||||
static let registerEmailField = "Register.EmailField"
|
||||
static let registerPasswordField = "Register.PasswordField"
|
||||
static let registerConfirmPasswordField = "Register.ConfirmPasswordField"
|
||||
static let registerButton = "Register.RegisterButton"
|
||||
static let registerCancelButton = "Register.CancelButton"
|
||||
|
||||
// Verification
|
||||
static let verificationCodeField = "Verification.CodeField"
|
||||
static let verifyButton = "Verification.VerifyButton"
|
||||
static let resendCodeButton = "Verification.ResendButton"
|
||||
}
|
||||
|
||||
// MARK: - Navigation
|
||||
struct Navigation {
|
||||
static let residencesTab = "TabBar.Residences"
|
||||
static let tasksTab = "TabBar.Tasks"
|
||||
static let contractorsTab = "TabBar.Contractors"
|
||||
static let documentsTab = "TabBar.Documents"
|
||||
static let profileTab = "TabBar.Profile"
|
||||
static let backButton = "Navigation.BackButton"
|
||||
}
|
||||
|
||||
// MARK: - Residence
|
||||
struct Residence {
|
||||
// List
|
||||
static let addButton = "Residence.AddButton"
|
||||
static let residencesList = "Residence.List"
|
||||
static let residenceCard = "Residence.Card"
|
||||
static let emptyStateView = "Residence.EmptyState"
|
||||
static let emptyStateButton = "Residence.EmptyState.AddButton"
|
||||
|
||||
// Form
|
||||
static let nameField = "ResidenceForm.NameField"
|
||||
static let propertyTypePicker = "ResidenceForm.PropertyTypePicker"
|
||||
static let streetAddressField = "ResidenceForm.StreetAddressField"
|
||||
static let apartmentUnitField = "ResidenceForm.ApartmentUnitField"
|
||||
static let cityField = "ResidenceForm.CityField"
|
||||
static let stateProvinceField = "ResidenceForm.StateProvinceField"
|
||||
static let postalCodeField = "ResidenceForm.PostalCodeField"
|
||||
static let countryField = "ResidenceForm.CountryField"
|
||||
static let bedroomsField = "ResidenceForm.BedroomsField"
|
||||
static let bathroomsField = "ResidenceForm.BathroomsField"
|
||||
static let squareFootageField = "ResidenceForm.SquareFootageField"
|
||||
static let lotSizeField = "ResidenceForm.LotSizeField"
|
||||
static let yearBuiltField = "ResidenceForm.YearBuiltField"
|
||||
static let descriptionField = "ResidenceForm.DescriptionField"
|
||||
static let isPrimaryToggle = "ResidenceForm.IsPrimaryToggle"
|
||||
static let saveButton = "ResidenceForm.SaveButton"
|
||||
static let formCancelButton = "ResidenceForm.CancelButton"
|
||||
|
||||
// Detail
|
||||
static let detailView = "ResidenceDetail.View"
|
||||
static let editButton = "ResidenceDetail.EditButton"
|
||||
static let deleteButton = "ResidenceDetail.DeleteButton"
|
||||
static let shareButton = "ResidenceDetail.ShareButton"
|
||||
static let manageUsersButton = "ResidenceDetail.ManageUsersButton"
|
||||
static let tasksSection = "ResidenceDetail.TasksSection"
|
||||
static let addTaskButton = "ResidenceDetail.AddTaskButton"
|
||||
}
|
||||
|
||||
// MARK: - Task
|
||||
struct Task {
|
||||
// List/Kanban
|
||||
static let addButton = "Task.AddButton"
|
||||
static let tasksList = "Task.List"
|
||||
static let taskCard = "Task.Card"
|
||||
static let emptyStateView = "Task.EmptyState"
|
||||
static let kanbanView = "Task.KanbanView"
|
||||
static let overdueColumn = "Task.Column.Overdue"
|
||||
static let upcomingColumn = "Task.Column.Upcoming"
|
||||
static let inProgressColumn = "Task.Column.InProgress"
|
||||
static let completedColumn = "Task.Column.Completed"
|
||||
|
||||
// Form
|
||||
static let titleField = "TaskForm.TitleField"
|
||||
static let descriptionField = "TaskForm.DescriptionField"
|
||||
static let categoryPicker = "TaskForm.CategoryPicker"
|
||||
static let frequencyPicker = "TaskForm.FrequencyPicker"
|
||||
static let priorityPicker = "TaskForm.PriorityPicker"
|
||||
static let statusPicker = "TaskForm.StatusPicker"
|
||||
static let dueDatePicker = "TaskForm.DueDatePicker"
|
||||
static let intervalDaysField = "TaskForm.IntervalDaysField"
|
||||
static let estimatedCostField = "TaskForm.EstimatedCostField"
|
||||
static let residencePicker = "TaskForm.ResidencePicker"
|
||||
static let saveButton = "TaskForm.SaveButton"
|
||||
static let formCancelButton = "TaskForm.CancelButton"
|
||||
|
||||
// Detail
|
||||
static let detailView = "TaskDetail.View"
|
||||
static let editButton = "TaskDetail.EditButton"
|
||||
static let deleteButton = "TaskDetail.DeleteButton"
|
||||
static let markInProgressButton = "TaskDetail.MarkInProgressButton"
|
||||
static let completeButton = "TaskDetail.CompleteButton"
|
||||
static let detailCancelButton = "TaskDetail.CancelButton"
|
||||
|
||||
// Completion
|
||||
static let completionDatePicker = "TaskCompletion.CompletionDatePicker"
|
||||
static let actualCostField = "TaskCompletion.ActualCostField"
|
||||
static let ratingView = "TaskCompletion.RatingView"
|
||||
static let notesField = "TaskCompletion.NotesField"
|
||||
static let photosPicker = "TaskCompletion.PhotosPicker"
|
||||
static let submitButton = "TaskCompletion.SubmitButton"
|
||||
}
|
||||
|
||||
// MARK: - Contractor
|
||||
struct Contractor {
|
||||
static let addButton = "Contractor.AddButton"
|
||||
static let contractorsList = "Contractor.List"
|
||||
static let contractorCard = "Contractor.Card"
|
||||
static let emptyStateView = "Contractor.EmptyState"
|
||||
|
||||
// Form
|
||||
static let nameField = "ContractorForm.NameField"
|
||||
static let companyField = "ContractorForm.CompanyField"
|
||||
static let emailField = "ContractorForm.EmailField"
|
||||
static let phoneField = "ContractorForm.PhoneField"
|
||||
static let specialtyPicker = "ContractorForm.SpecialtyPicker"
|
||||
static let ratingView = "ContractorForm.RatingView"
|
||||
static let notesField = "ContractorForm.NotesField"
|
||||
static let saveButton = "ContractorForm.SaveButton"
|
||||
static let formCancelButton = "ContractorForm.CancelButton"
|
||||
|
||||
// Detail
|
||||
static let detailView = "ContractorDetail.View"
|
||||
static let editButton = "ContractorDetail.EditButton"
|
||||
static let deleteButton = "ContractorDetail.DeleteButton"
|
||||
static let callButton = "ContractorDetail.CallButton"
|
||||
static let emailButton = "ContractorDetail.EmailButton"
|
||||
}
|
||||
|
||||
// MARK: - Document
|
||||
struct Document {
|
||||
static let addButton = "Document.AddButton"
|
||||
static let documentsList = "Document.List"
|
||||
static let documentCard = "Document.Card"
|
||||
static let emptyStateView = "Document.EmptyState"
|
||||
|
||||
// Form
|
||||
static let titleField = "DocumentForm.TitleField"
|
||||
static let typePicker = "DocumentForm.TypePicker"
|
||||
static let categoryPicker = "DocumentForm.CategoryPicker"
|
||||
static let residencePicker = "DocumentForm.ResidencePicker"
|
||||
static let filePicker = "DocumentForm.FilePicker"
|
||||
static let notesField = "DocumentForm.NotesField"
|
||||
static let expirationDatePicker = "DocumentForm.ExpirationDatePicker"
|
||||
static let saveButton = "DocumentForm.SaveButton"
|
||||
static let formCancelButton = "DocumentForm.CancelButton"
|
||||
|
||||
// Detail
|
||||
static let detailView = "DocumentDetail.View"
|
||||
static let editButton = "DocumentDetail.EditButton"
|
||||
static let deleteButton = "DocumentDetail.DeleteButton"
|
||||
static let shareButton = "DocumentDetail.ShareButton"
|
||||
static let downloadButton = "DocumentDetail.DownloadButton"
|
||||
}
|
||||
|
||||
// MARK: - Profile
|
||||
struct Profile {
|
||||
static let logoutButton = "Profile.LogoutButton"
|
||||
static let editProfileButton = "Profile.EditProfileButton"
|
||||
static let settingsButton = "Profile.SettingsButton"
|
||||
static let notificationsToggle = "Profile.NotificationsToggle"
|
||||
static let darkModeToggle = "Profile.DarkModeToggle"
|
||||
static let aboutButton = "Profile.AboutButton"
|
||||
static let helpButton = "Profile.HelpButton"
|
||||
}
|
||||
|
||||
// MARK: - Alerts & Modals
|
||||
struct Alert {
|
||||
static let confirmButton = "Alert.ConfirmButton"
|
||||
static let cancelButton = "Alert.CancelButton"
|
||||
static let deleteButton = "Alert.DeleteButton"
|
||||
static let okButton = "Alert.OKButton"
|
||||
}
|
||||
|
||||
// MARK: - Common
|
||||
struct Common {
|
||||
static let loadingIndicator = "Common.LoadingIndicator"
|
||||
static let errorView = "Common.ErrorView"
|
||||
static let retryButton = "Common.RetryButton"
|
||||
static let searchField = "Common.SearchField"
|
||||
static let filterButton = "Common.FilterButton"
|
||||
static let sortButton = "Common.SortButton"
|
||||
static let refreshControl = "Common.RefreshControl"
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Helper Extension
|
||||
extension String {
|
||||
/// Convenience method to generate dynamic identifiers
|
||||
/// Example: "Residence.Card.\(residenceId)"
|
||||
func withId(_ id: Any) -> String {
|
||||
return "\(self).\(id)"
|
||||
}
|
||||
}
|
||||
133
iosApp/CaseraUITests/AuthenticationTests.swift
Normal file
133
iosApp/CaseraUITests/AuthenticationTests.swift
Normal file
@@ -0,0 +1,133 @@
|
||||
import XCTest
|
||||
|
||||
/// Authentication flow tests
|
||||
/// Based on working SimpleLoginTest pattern
|
||||
final class AuthenticationTests: XCTestCase {
|
||||
var app: XCUIApplication!
|
||||
|
||||
override func setUpWithError() throws {
|
||||
continueAfterFailure = false
|
||||
app = XCUIApplication()
|
||||
app.launch()
|
||||
ensureLoggedOut()
|
||||
}
|
||||
|
||||
override func tearDownWithError() throws {
|
||||
app = nil
|
||||
}
|
||||
|
||||
// MARK: - Helper Methods
|
||||
|
||||
private func ensureLoggedOut() {
|
||||
UITestHelpers.ensureLoggedOut(app: app)
|
||||
}
|
||||
|
||||
private func login(username: String, password: String) {
|
||||
UITestHelpers.login(app: app, username: username, password: password)
|
||||
}
|
||||
|
||||
// MARK: - Tests
|
||||
|
||||
func testLoginWithValidCredentials() {
|
||||
// Given: User is on login screen
|
||||
let welcomeText = app.staticTexts["Welcome Back"]
|
||||
XCTAssertTrue(welcomeText.exists, "Should be on login screen")
|
||||
|
||||
// When: User logs in with valid credentials
|
||||
login(username: "testuser", password: "TestPass123!")
|
||||
|
||||
// Then: User should see main tab view
|
||||
let residencesTab = app.tabBars.buttons.containing(NSPredicate(format: "label CONTAINS[c] 'Residences'")).firstMatch
|
||||
let didNavigate = residencesTab.waitForExistence(timeout: 10)
|
||||
XCTAssertTrue(didNavigate, "Should navigate to main app after successful login")
|
||||
}
|
||||
|
||||
func testLoginWithInvalidCredentials() {
|
||||
// Given: User is on login screen
|
||||
let welcomeText = app.staticTexts["Welcome Back"]
|
||||
XCTAssertTrue(welcomeText.exists, "Should be on login screen")
|
||||
|
||||
// When: User logs in with invalid credentials
|
||||
login(username: "wronguser", password: "wrongpass")
|
||||
|
||||
// Then: User should see error message and stay on login screen
|
||||
sleep(3) // Wait for API response
|
||||
|
||||
// Should still be on login screen
|
||||
XCTAssertTrue(welcomeText.exists, "Should still be on login screen")
|
||||
|
||||
// Sign In button should still be visible (not logged in)
|
||||
let signInButton = app.buttons.containing(NSPredicate(format: "label CONTAINS[c] 'Sign In'")).firstMatch
|
||||
XCTAssertTrue(signInButton.exists, "Should still see Sign In button")
|
||||
}
|
||||
|
||||
func testPasswordVisibilityToggle() {
|
||||
// Given: User is on login screen
|
||||
let passwordField = app.secureTextFields.containing(NSPredicate(format: "placeholderValue CONTAINS[c] 'password'")).firstMatch
|
||||
XCTAssertTrue(passwordField.waitForExistence(timeout: 5), "Password field should exist")
|
||||
|
||||
// When: User types password
|
||||
passwordField.tap()
|
||||
passwordField.typeText("secret123")
|
||||
|
||||
// Then: Find and tap the eye icon (visibility toggle)
|
||||
let eyeButton = app.buttons[AccessibilityIdentifiers.Authentication.passwordVisibilityToggle].firstMatch
|
||||
XCTAssertTrue(eyeButton.waitForExistence(timeout: 5), "Password visibility toggle button must exist")
|
||||
|
||||
eyeButton.tap()
|
||||
sleep(1)
|
||||
|
||||
// Password should now be visible in a regular text field
|
||||
let visiblePasswordField = app.textFields.containing(NSPredicate(format: "placeholderValue CONTAINS[c] 'password'")).firstMatch
|
||||
XCTAssertTrue(visiblePasswordField.exists, "Password should be visible after toggle")
|
||||
}
|
||||
|
||||
func testNavigationToSignUp() {
|
||||
// Given: User is on login screen
|
||||
let welcomeText = app.staticTexts["Welcome Back"]
|
||||
XCTAssertTrue(welcomeText.exists, "Should be on login screen")
|
||||
|
||||
// When: User taps Sign Up button
|
||||
let signUpButton = app.buttons.containing(NSPredicate(format: "label CONTAINS[c] 'Sign Up'")).firstMatch
|
||||
XCTAssertTrue(signUpButton.exists, "Sign Up button should exist")
|
||||
signUpButton.tap()
|
||||
|
||||
// Then: Registration screen should appear
|
||||
sleep(2)
|
||||
let registerButton = app.buttons.containing(NSPredicate(format: "label CONTAINS[c] 'Register' OR label CONTAINS[c] 'Create Account'")).firstMatch
|
||||
XCTAssertTrue(registerButton.waitForExistence(timeout: 5), "Should navigate to registration screen")
|
||||
}
|
||||
|
||||
func testForgotPasswordNavigation() {
|
||||
// Given: User is on login screen
|
||||
let welcomeText = app.staticTexts["Welcome Back"]
|
||||
XCTAssertTrue(welcomeText.exists, "Should be on login screen")
|
||||
|
||||
// When: User taps Forgot Password button
|
||||
let forgotPasswordButton = app.buttons.containing(NSPredicate(format: "label CONTAINS[c] 'Forgot Password'")).firstMatch
|
||||
XCTAssertTrue(forgotPasswordButton.exists, "Forgot Password button should exist")
|
||||
forgotPasswordButton.tap()
|
||||
|
||||
// Then: Password reset screen should appear
|
||||
sleep(2)
|
||||
// Look for email field or reset button
|
||||
let emailField = app.textFields.containing(NSPredicate(format: "placeholderValue CONTAINS[c] 'email'")).firstMatch
|
||||
let resetButton = app.buttons.containing(NSPredicate(format: "label CONTAINS[c] 'Reset' OR label CONTAINS[c] 'Send'")).firstMatch
|
||||
|
||||
let passwordResetScreenAppeared = emailField.exists || resetButton.exists
|
||||
XCTAssertTrue(passwordResetScreenAppeared, "Should navigate to password reset screen")
|
||||
}
|
||||
|
||||
func testLogout() {
|
||||
// Given: User is logged in
|
||||
login(username: "testuser", password: "TestPass123!")
|
||||
|
||||
let residencesTab = app.tabBars.buttons.containing(NSPredicate(format: "label CONTAINS[c] 'Residences'")).firstMatch
|
||||
XCTAssertTrue(residencesTab.waitForExistence(timeout: 10), "Should be logged in")
|
||||
|
||||
// When: User logs out
|
||||
UITestHelpers.logout(app: app)
|
||||
|
||||
// Then: User should be back on login screen (verified by UITestHelpers.logout)
|
||||
}
|
||||
}
|
||||
747
iosApp/CaseraUITests/ComprehensiveContractorTests.swift
Normal file
747
iosApp/CaseraUITests/ComprehensiveContractorTests.swift
Normal file
@@ -0,0 +1,747 @@
|
||||
import XCTest
|
||||
|
||||
/// Comprehensive contractor testing suite covering all scenarios, edge cases, and variations
|
||||
/// This test suite is designed to be bulletproof and catch regressions early
|
||||
final class ComprehensiveContractorTests: XCTestCase {
|
||||
var app: XCUIApplication!
|
||||
|
||||
// Test data tracking
|
||||
var createdContractorNames: [String] = []
|
||||
|
||||
override func setUpWithError() throws {
|
||||
continueAfterFailure = false
|
||||
app = XCUIApplication()
|
||||
app.launch()
|
||||
|
||||
// Ensure user is logged in
|
||||
UITestHelpers.ensureLoggedIn(app: app)
|
||||
|
||||
// Navigate to Contractors tab
|
||||
navigateToContractorsTab()
|
||||
}
|
||||
|
||||
override func tearDownWithError() throws {
|
||||
createdContractorNames.removeAll()
|
||||
app = nil
|
||||
}
|
||||
|
||||
// MARK: - Helper Methods
|
||||
|
||||
private func navigateToContractorsTab() {
|
||||
let contractorsTab = app.tabBars.buttons.containing(NSPredicate(format: "label CONTAINS[c] 'Contractors'")).firstMatch
|
||||
if contractorsTab.waitForExistence(timeout: 5) {
|
||||
if !contractorsTab.isSelected {
|
||||
contractorsTab.tap()
|
||||
sleep(3)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func openContractorForm() -> Bool {
|
||||
let addButton = findAddContractorButton()
|
||||
guard addButton.exists && addButton.isEnabled else { return false }
|
||||
addButton.tap()
|
||||
sleep(3)
|
||||
|
||||
// Verify form opened
|
||||
let nameField = app.textFields.containing(NSPredicate(format: "placeholderValue CONTAINS[c] 'Name'")).firstMatch
|
||||
return nameField.waitForExistence(timeout: 5)
|
||||
}
|
||||
|
||||
private func findAddContractorButton() -> XCUIElement {
|
||||
sleep(2)
|
||||
|
||||
// Look for add button by various methods
|
||||
let navBarButtons = app.navigationBars.buttons
|
||||
for i in 0..<navBarButtons.count {
|
||||
let button = navBarButtons.element(boundBy: i)
|
||||
if button.label == "plus" || button.label.contains("Add") {
|
||||
if button.isEnabled {
|
||||
return button
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Fallback: look for any button with plus icon
|
||||
return app.buttons.containing(NSPredicate(format: "label CONTAINS 'plus'")).firstMatch
|
||||
}
|
||||
|
||||
private func fillTextField(placeholder: String, text: String) {
|
||||
let field = app.textFields.containing(NSPredicate(format: "placeholderValue CONTAINS[c] '\(placeholder)'")).firstMatch
|
||||
if field.exists {
|
||||
field.tap()
|
||||
field.typeText(text)
|
||||
}
|
||||
}
|
||||
|
||||
private func selectSpecialty(specialty: String) {
|
||||
let specialtyPicker = app.buttons.containing(NSPredicate(format: "label CONTAINS[c] 'Specialty'")).firstMatch
|
||||
if specialtyPicker.exists {
|
||||
specialtyPicker.tap()
|
||||
sleep(1)
|
||||
|
||||
// Try to find and tap the specialty option
|
||||
let specialtyButton = app.buttons[specialty]
|
||||
if specialtyButton.exists {
|
||||
specialtyButton.tap()
|
||||
sleep(1)
|
||||
} else {
|
||||
// Try cells if it's a navigation style picker
|
||||
let cells = app.cells
|
||||
for i in 0..<cells.count {
|
||||
let cell = cells.element(boundBy: i)
|
||||
if cell.staticTexts[specialty].exists {
|
||||
cell.tap()
|
||||
sleep(1)
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func createContractor(
|
||||
name: String,
|
||||
phone: String = "555-123-4567",
|
||||
email: String? = nil,
|
||||
company: String? = nil,
|
||||
specialty: String? = nil,
|
||||
scrollBeforeSave: Bool = true
|
||||
) -> Bool {
|
||||
guard openContractorForm() else { return false }
|
||||
|
||||
// Fill name
|
||||
let nameField = app.textFields.containing(NSPredicate(format: "placeholderValue CONTAINS[c] 'Name'")).firstMatch
|
||||
nameField.tap()
|
||||
nameField.typeText(name)
|
||||
|
||||
// Fill phone (required field)
|
||||
fillTextField(placeholder: "Phone", text: phone)
|
||||
|
||||
// Fill optional fields
|
||||
if let email = email {
|
||||
fillTextField(placeholder: "Email", text: email)
|
||||
}
|
||||
|
||||
if let company = company {
|
||||
fillTextField(placeholder: "Company", text: company)
|
||||
}
|
||||
|
||||
// Select specialty if provided
|
||||
if let specialty = specialty {
|
||||
selectSpecialty(specialty: specialty)
|
||||
}
|
||||
|
||||
// Scroll to save button if needed
|
||||
if scrollBeforeSave {
|
||||
app.swipeUp()
|
||||
sleep(1)
|
||||
}
|
||||
|
||||
// Add button (for creating new contractors)
|
||||
let addButton = app.buttons.containing(NSPredicate(format: "label CONTAINS[c] 'Add'")).firstMatch
|
||||
guard addButton.exists else { return false }
|
||||
addButton.tap()
|
||||
|
||||
sleep(4) // Wait for API call
|
||||
|
||||
// Track created contractor
|
||||
createdContractorNames.append(name)
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
private func findContractor(name: String, scrollIfNeeded: Bool = true) -> XCUIElement {
|
||||
let element = app.staticTexts.containing(NSPredicate(format: "label CONTAINS[c] %@", name)).firstMatch
|
||||
|
||||
// If element is visible, return it immediately
|
||||
if element.exists && element.isHittable {
|
||||
return element
|
||||
}
|
||||
|
||||
// If scrolling is not needed, return the element as-is
|
||||
guard scrollIfNeeded else {
|
||||
return element
|
||||
}
|
||||
|
||||
// Get the scroll view
|
||||
let scrollView = app.scrollViews.firstMatch
|
||||
guard scrollView.exists else {
|
||||
return element
|
||||
}
|
||||
|
||||
// First, scroll to the top of the list
|
||||
scrollView.swipeDown(velocity: .fast)
|
||||
usleep(30_000) // 0.03 second delay
|
||||
|
||||
// Now scroll down from top, checking after each swipe
|
||||
var lastVisibleRow = ""
|
||||
for _ in 0..<Int.max {
|
||||
// Check if element is now visible
|
||||
if element.exists && element.isHittable {
|
||||
return element
|
||||
}
|
||||
|
||||
// Get the last visible row before swiping
|
||||
let visibleTexts = app.staticTexts.allElementsBoundByIndex.filter { $0.isHittable }
|
||||
let currentLastRow = visibleTexts.last?.label ?? ""
|
||||
|
||||
// If last row hasn't changed, we've reached the end
|
||||
if !lastVisibleRow.isEmpty && currentLastRow == lastVisibleRow {
|
||||
break
|
||||
}
|
||||
|
||||
lastVisibleRow = currentLastRow
|
||||
|
||||
// Scroll down one swipe
|
||||
scrollView.swipeUp(velocity: .slow)
|
||||
usleep(50_000) // 0.05 second delay
|
||||
}
|
||||
|
||||
// Return element (test assertions will handle if not found)
|
||||
return element
|
||||
}
|
||||
|
||||
// MARK: - Basic Contractor Creation Tests
|
||||
|
||||
func testCreateContractorWithMinimalData() {
|
||||
let timestamp = Int(Date().timeIntervalSince1970)
|
||||
let contractorName = "John Doe \(timestamp)"
|
||||
|
||||
let success = createContractor(name: contractorName)
|
||||
XCTAssertTrue(success, "Should successfully create contractor with minimal data")
|
||||
|
||||
let contractorInList = findContractor(name: contractorName)
|
||||
XCTAssertTrue(contractorInList.waitForExistence(timeout: 10), "Contractor should appear in list")
|
||||
}
|
||||
|
||||
func testCreateContractorWithAllFields() {
|
||||
let timestamp = Int(Date().timeIntervalSince1970)
|
||||
let contractorName = "Jane Smith \(timestamp)"
|
||||
|
||||
let success = createContractor(
|
||||
name: contractorName,
|
||||
phone: "555-987-6543",
|
||||
email: "jane.smith@example.com",
|
||||
company: "Smith Plumbing Inc",
|
||||
specialty: "Plumbing"
|
||||
)
|
||||
XCTAssertTrue(success, "Should successfully create contractor with all fields")
|
||||
|
||||
let contractorInList = findContractor(name: contractorName)
|
||||
XCTAssertTrue(contractorInList.waitForExistence(timeout: 10), "Complete contractor should appear in list")
|
||||
}
|
||||
|
||||
func testCreateContractorWithDifferentSpecialties() {
|
||||
let timestamp = Int(Date().timeIntervalSince1970)
|
||||
let specialties = ["Plumbing", "Electrical", "HVAC"]
|
||||
|
||||
for (index, specialty) in specialties.enumerated() {
|
||||
let contractorName = "\(specialty) Expert \(timestamp)_\(index)"
|
||||
let success = createContractor(name: contractorName, specialty: specialty)
|
||||
XCTAssertTrue(success, "Should create \(specialty) contractor")
|
||||
|
||||
navigateToContractorsTab()
|
||||
sleep(2)
|
||||
}
|
||||
|
||||
// Verify all contractors exist
|
||||
for (index, specialty) in specialties.enumerated() {
|
||||
let contractorName = "\(specialty) Expert \(timestamp)_\(index)"
|
||||
let contractor = findContractor(name: contractorName)
|
||||
XCTAssertTrue(contractor.exists, "\(specialty) contractor should exist in list")
|
||||
}
|
||||
}
|
||||
|
||||
func testCreateMultipleContractorsInSequence() {
|
||||
let timestamp = Int(Date().timeIntervalSince1970)
|
||||
|
||||
for i in 1...3 {
|
||||
let contractorName = "Sequential Contractor \(i) - \(timestamp)"
|
||||
let success = createContractor(name: contractorName)
|
||||
XCTAssertTrue(success, "Should create contractor \(i)")
|
||||
|
||||
navigateToContractorsTab()
|
||||
sleep(2)
|
||||
}
|
||||
|
||||
// Verify all contractors exist
|
||||
for i in 1...3 {
|
||||
let contractorName = "Sequential Contractor \(i) - \(timestamp)"
|
||||
let contractor = findContractor(name: contractorName)
|
||||
XCTAssertTrue(contractor.exists, "Contractor \(i) should exist in list")
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Contractor Editing Tests
|
||||
|
||||
func testEditContractorName() {
|
||||
let timestamp = Int(Date().timeIntervalSince1970)
|
||||
let originalName = "Original Contractor \(timestamp)"
|
||||
let newName = "Edited Contractor \(timestamp)"
|
||||
|
||||
// Create contractor
|
||||
guard createContractor(name: originalName) else {
|
||||
XCTFail("Failed to create contractor")
|
||||
return
|
||||
}
|
||||
|
||||
navigateToContractorsTab()
|
||||
sleep(2)
|
||||
|
||||
// Find and tap contractor
|
||||
let contractor = findContractor(name: originalName)
|
||||
XCTAssertTrue(contractor.waitForExistence(timeout: 5), "Contractor should exist")
|
||||
contractor.tap()
|
||||
sleep(2)
|
||||
|
||||
// Tap edit button (may be in menu)
|
||||
app/*@START_MENU_TOKEN@*/.images["ellipsis.circle"]/*[[".buttons[\"More\"].images",".buttons",".images[\"More\"]",".images[\"ellipsis.circle\"]"],[[[-1,3],[-1,2],[-1,1,1],[-1,0]],[[-1,3],[-1,2]]],[0]]@END_MENU_TOKEN@*/.firstMatch.tap()
|
||||
app/*@START_MENU_TOKEN@*/.buttons["pencil"]/*[[".buttons.containing(.image, identifier: \"pencil\")",".cells",".buttons[\"Edit\"]",".buttons[\"pencil\"]"],[[[-1,3],[-1,2],[-1,1,1],[-1,0]],[[-1,3],[-1,2]]],[0]]@END_MENU_TOKEN@*/.firstMatch.tap()
|
||||
|
||||
// Edit name
|
||||
let nameField = app.textFields.containing(NSPredicate(format: "placeholderValue CONTAINS[c] 'Name'")).firstMatch
|
||||
if nameField.exists {
|
||||
nameField.tap()
|
||||
sleep(1)
|
||||
nameField.tap()
|
||||
sleep(1)
|
||||
app.menuItems["Select All"].tap()
|
||||
sleep(1)
|
||||
nameField.typeText(newName)
|
||||
|
||||
// Save (when editing, button should say "Save")
|
||||
let saveButton = app.buttons.containing(NSPredicate(format: "label CONTAINS[c] 'Save'")).firstMatch
|
||||
if saveButton.exists {
|
||||
saveButton.tap()
|
||||
sleep(3)
|
||||
|
||||
// Track new name
|
||||
createdContractorNames.append(newName)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func testUpdateAllContractorFields() {
|
||||
let timestamp = Int(Date().timeIntervalSince1970)
|
||||
let originalName = "Update All Fields \(timestamp)"
|
||||
let newName = "All Fields Updated \(timestamp)"
|
||||
let newPhone = "999-888-7777"
|
||||
let newEmail = "updated@contractor.com"
|
||||
let newCompany = "Updated Company LLC"
|
||||
|
||||
// Create contractor with initial values
|
||||
guard createContractor(
|
||||
name: originalName,
|
||||
phone: "555-123-4567",
|
||||
email: "original@contractor.com",
|
||||
company: "Original Company"
|
||||
) else {
|
||||
XCTFail("Failed to create contractor")
|
||||
return
|
||||
}
|
||||
|
||||
navigateToContractorsTab()
|
||||
sleep(2)
|
||||
|
||||
// Find and tap contractor
|
||||
let contractor = findContractor(name: originalName)
|
||||
XCTAssertTrue(contractor.waitForExistence(timeout: 5), "Contractor should exist")
|
||||
contractor.tap()
|
||||
sleep(2)
|
||||
|
||||
// Tap edit button (may be in menu)
|
||||
app/*@START_MENU_TOKEN@*/.images["ellipsis.circle"]/*[[".buttons[\"More\"].images",".buttons",".images[\"More\"]",".images[\"ellipsis.circle\"]"],[[[-1,3],[-1,2],[-1,1,1],[-1,0]],[[-1,3],[-1,2]]],[0]]@END_MENU_TOKEN@*/.firstMatch.tap()
|
||||
app/*@START_MENU_TOKEN@*/.buttons["pencil"]/*[[".buttons.containing(.image, identifier: \"pencil\")",".cells",".buttons[\"Edit\"]",".buttons[\"pencil\"]"],[[[-1,3],[-1,2],[-1,1,1],[-1,0]],[[-1,3],[-1,2]]],[0]]@END_MENU_TOKEN@*/.firstMatch.tap()
|
||||
|
||||
// Update name
|
||||
let nameField = app.textFields.containing(NSPredicate(format: "placeholderValue CONTAINS[c] 'Name'")).firstMatch
|
||||
XCTAssertTrue(nameField.exists, "Name field should exist")
|
||||
nameField.tap()
|
||||
sleep(1)
|
||||
nameField.tap()
|
||||
sleep(1)
|
||||
app.menuItems["Select All"].tap()
|
||||
sleep(1)
|
||||
nameField.typeText(newName)
|
||||
|
||||
// Update phone
|
||||
let phoneField = app.textFields.containing(NSPredicate(format: "placeholderValue CONTAINS[c] 'Phone'")).firstMatch
|
||||
if phoneField.exists {
|
||||
phoneField.tap()
|
||||
sleep(1)
|
||||
phoneField.tap()
|
||||
sleep(1)
|
||||
app.menuItems["Select All"].tap()
|
||||
phoneField.typeText(newPhone)
|
||||
}
|
||||
|
||||
// Scroll to more fields
|
||||
app.swipeUp()
|
||||
sleep(1)
|
||||
|
||||
// Update email
|
||||
let emailField = app.textFields.containing(NSPredicate(format: "placeholderValue CONTAINS[c] 'Email'")).firstMatch
|
||||
if emailField.exists {
|
||||
emailField.tap()
|
||||
sleep(1)
|
||||
emailField.tap()
|
||||
sleep(1)
|
||||
app.menuItems["Select All"].tap()
|
||||
emailField.typeText(newEmail)
|
||||
}
|
||||
|
||||
// Update company
|
||||
let companyField = app.textFields.containing(NSPredicate(format: "placeholderValue CONTAINS[c] 'Company'")).firstMatch
|
||||
if companyField.exists {
|
||||
companyField.tap()
|
||||
sleep(1)
|
||||
companyField.tap()
|
||||
sleep(1)
|
||||
app.menuItems["Select All"].tap()
|
||||
companyField.typeText(newCompany)
|
||||
}
|
||||
|
||||
// Update specialty (if picker exists)
|
||||
let specialtyPicker = app.buttons.containing(NSPredicate(format: "label CONTAINS[c] 'Specialty'")).firstMatch
|
||||
if specialtyPicker.exists {
|
||||
specialtyPicker.tap()
|
||||
sleep(1)
|
||||
// Select HVAC
|
||||
let hvacOption = app.buttons["HVAC"]
|
||||
if hvacOption.exists {
|
||||
hvacOption.tap()
|
||||
sleep(1)
|
||||
}
|
||||
}
|
||||
|
||||
// Scroll to save button
|
||||
app.swipeUp()
|
||||
sleep(1)
|
||||
|
||||
// Save (when editing, button should say "Save")
|
||||
let saveButton = app.buttons.containing(NSPredicate(format: "label CONTAINS[c] 'Save'")).firstMatch
|
||||
XCTAssertTrue(saveButton.exists, "Save button should exist when editing contractor")
|
||||
saveButton.tap()
|
||||
sleep(4)
|
||||
|
||||
// Track new name
|
||||
createdContractorNames.append(newName)
|
||||
|
||||
// Verify updated contractor appears in list with new name
|
||||
navigateToContractorsTab()
|
||||
sleep(2)
|
||||
let updatedContractor = findContractor(name: newName)
|
||||
XCTAssertTrue(updatedContractor.exists, "Contractor should show updated name in list")
|
||||
|
||||
// Tap on contractor to verify details were updated
|
||||
updatedContractor.tap()
|
||||
sleep(2)
|
||||
|
||||
// Verify updated phone appears in detail view
|
||||
let phoneText = app.staticTexts.containing(NSPredicate(format: "label CONTAINS '\(newPhone)' OR label CONTAINS '999-888-7777' OR label CONTAINS '9998887777'")).firstMatch
|
||||
XCTAssertTrue(phoneText.exists, "Updated phone should be visible in detail view")
|
||||
|
||||
// Verify updated email appears in detail view
|
||||
let emailText = app.staticTexts.containing(NSPredicate(format: "label CONTAINS '\(newEmail)'")).firstMatch
|
||||
XCTAssertTrue(emailText.exists, "Updated email should be visible in detail view")
|
||||
|
||||
// Verify updated company appears in detail view
|
||||
let companyText = app.staticTexts.containing(NSPredicate(format: "label CONTAINS '\(newCompany)'")).firstMatch
|
||||
XCTAssertTrue(companyText.exists, "Updated company should be visible in detail view")
|
||||
|
||||
// Verify updated specialty (HVAC) appears
|
||||
let hvacBadge = app.staticTexts.containing(NSPredicate(format: "label CONTAINS 'HVAC'")).firstMatch
|
||||
XCTAssertTrue(hvacBadge.exists || true, "Updated specialty should be visible (if shown in detail)")
|
||||
}
|
||||
|
||||
// MARK: - Validation & Error Handling Tests
|
||||
|
||||
func testCannotCreateContractorWithEmptyName() {
|
||||
guard openContractorForm() else {
|
||||
XCTFail("Failed to open contractor form")
|
||||
return
|
||||
}
|
||||
|
||||
// Leave name empty, fill only phone
|
||||
fillTextField(placeholder: "Phone", text: "555-123-4567")
|
||||
|
||||
// Scroll to Add button if needed
|
||||
app.swipeUp()
|
||||
sleep(1)
|
||||
|
||||
// When creating, button should say "Add"
|
||||
let addButton = app.buttons.containing(NSPredicate(format: "label CONTAINS[c] 'Add'")).firstMatch
|
||||
XCTAssertTrue(addButton.exists, "Add button should exist when creating contractor")
|
||||
XCTAssertFalse(addButton.isEnabled, "Add button should be disabled when name is empty")
|
||||
}
|
||||
|
||||
// func testCannotCreateContractorWithEmptyPhone() {
|
||||
// guard openContractorForm() else {
|
||||
// XCTFail("Failed to open contractor form")
|
||||
// return
|
||||
// }
|
||||
//
|
||||
// // Fill name but leave phone empty
|
||||
// let nameField = app.textFields.containing(NSPredicate(format: "placeholderValue CONTAINS[c] 'Name'")).firstMatch
|
||||
// nameField.tap()
|
||||
// nameField.typeText("Test Contractor")
|
||||
//
|
||||
// // Scroll to Add button if needed
|
||||
// app.swipeUp()
|
||||
// sleep(1)
|
||||
//
|
||||
// // When creating, button should say "Add"
|
||||
// let addButton = app.buttons.containing(NSPredicate(format: "label CONTAINS[c] 'Add'")).firstMatch
|
||||
// XCTAssertTrue(addButton.exists, "Add button should exist when creating contractor")
|
||||
// XCTAssertFalse(addButton.isEnabled, "Add button should be disabled when phone is empty")
|
||||
// }
|
||||
|
||||
func testCancelContractorCreation() {
|
||||
guard openContractorForm() else {
|
||||
XCTFail("Failed to open contractor form")
|
||||
return
|
||||
}
|
||||
|
||||
// Fill some data
|
||||
let nameField = app.textFields.containing(NSPredicate(format: "placeholderValue CONTAINS[c] 'Name'")).firstMatch
|
||||
nameField.tap()
|
||||
nameField.typeText("This will be canceled")
|
||||
|
||||
// Tap cancel
|
||||
let cancelButton = app.buttons.containing(NSPredicate(format: "label CONTAINS[c] 'Cancel'")).firstMatch
|
||||
XCTAssertTrue(cancelButton.exists, "Cancel button should exist")
|
||||
cancelButton.tap()
|
||||
sleep(2)
|
||||
|
||||
// Should be back on contractors list
|
||||
let contractorsTab = app.tabBars.buttons.containing(NSPredicate(format: "label CONTAINS[c] 'Contractors'")).firstMatch
|
||||
XCTAssertTrue(contractorsTab.exists, "Should be back on contractors list")
|
||||
|
||||
// Contractor should not exist
|
||||
let contractor = findContractor(name: "This will be canceled")
|
||||
XCTAssertFalse(contractor.exists, "Canceled contractor should not exist")
|
||||
}
|
||||
|
||||
// MARK: - Edge Case Tests - Phone Numbers
|
||||
|
||||
func testCreateContractorWithDifferentPhoneFormats() {
|
||||
let timestamp = Int(Date().timeIntervalSince1970)
|
||||
let phoneFormats = [
|
||||
("555-123-4567", "Dashed"),
|
||||
("(555) 123-4567", "Parentheses"),
|
||||
("5551234567", "NoFormat"),
|
||||
("555.123.4567", "Dotted")
|
||||
]
|
||||
|
||||
for (index, (phone, format)) in phoneFormats.enumerated() {
|
||||
let contractorName = "\(format) Phone \(timestamp)_\(index)"
|
||||
let success = createContractor(name: contractorName, phone: phone)
|
||||
XCTAssertTrue(success, "Should create contractor with \(format) phone format")
|
||||
|
||||
navigateToContractorsTab()
|
||||
sleep(2)
|
||||
}
|
||||
|
||||
// Verify all contractors exist
|
||||
for (index, (_, format)) in phoneFormats.enumerated() {
|
||||
let contractorName = "\(format) Phone \(timestamp)_\(index)"
|
||||
let contractor = findContractor(name: contractorName)
|
||||
XCTAssertTrue(contractor.exists, "Contractor with \(format) phone should exist")
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Edge Case Tests - Emails
|
||||
|
||||
func testCreateContractorWithValidEmails() {
|
||||
let timestamp = Int(Date().timeIntervalSince1970)
|
||||
let emails = [
|
||||
"simple@example.com",
|
||||
"firstname.lastname@example.com",
|
||||
"email+tag@example.co.uk",
|
||||
"email_with_underscore@example.com"
|
||||
]
|
||||
|
||||
for (index, email) in emails.enumerated() {
|
||||
let contractorName = "Email Test \(index) - \(timestamp)"
|
||||
let success = createContractor(name: contractorName, email: email)
|
||||
XCTAssertTrue(success, "Should create contractor with email: \(email)")
|
||||
|
||||
navigateToContractorsTab()
|
||||
sleep(2)
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Edge Case Tests - Names
|
||||
|
||||
func testCreateContractorWithVeryLongName() {
|
||||
let timestamp = Int(Date().timeIntervalSince1970)
|
||||
let longName = "John Christopher Alexander Montgomery Wellington III Esquire \(timestamp)"
|
||||
|
||||
let success = createContractor(name: longName)
|
||||
XCTAssertTrue(success, "Should handle very long names")
|
||||
|
||||
// Verify it appears (may be truncated in display)
|
||||
let contractor = findContractor(name: "John Christopher")
|
||||
XCTAssertTrue(contractor.waitForExistence(timeout: 10), "Long name contractor should exist")
|
||||
}
|
||||
|
||||
func testCreateContractorWithSpecialCharactersInName() {
|
||||
let timestamp = Int(Date().timeIntervalSince1970)
|
||||
let specialName = "O'Brien-Smith Jr. \(timestamp)"
|
||||
|
||||
let success = createContractor(name: specialName)
|
||||
XCTAssertTrue(success, "Should handle special characters in names")
|
||||
|
||||
let contractor = findContractor(name: "O'Brien")
|
||||
XCTAssertTrue(contractor.waitForExistence(timeout: 10), "Contractor with special chars should exist")
|
||||
}
|
||||
|
||||
func testCreateContractorWithInternationalCharacters() {
|
||||
let timestamp = Int(Date().timeIntervalSince1970)
|
||||
let internationalName = "José García \(timestamp)"
|
||||
|
||||
let success = createContractor(name: internationalName)
|
||||
XCTAssertTrue(success, "Should handle international characters")
|
||||
|
||||
let contractor = findContractor(name: "José")
|
||||
XCTAssertTrue(contractor.waitForExistence(timeout: 10), "Contractor with international chars should exist")
|
||||
}
|
||||
|
||||
func testCreateContractorWithEmojisInName() {
|
||||
let timestamp = Int(Date().timeIntervalSince1970)
|
||||
let emojiName = "Bob 🔧 Builder \(timestamp)"
|
||||
|
||||
let success = createContractor(name: emojiName)
|
||||
XCTAssertTrue(success, "Should handle emojis in names")
|
||||
|
||||
let contractor = findContractor(name: "Bob")
|
||||
XCTAssertTrue(contractor.waitForExistence(timeout: 10), "Contractor with emojis should exist")
|
||||
}
|
||||
|
||||
// MARK: - Navigation & List Tests
|
||||
|
||||
func testNavigateFromContractorsToOtherTabs() {
|
||||
// From Contractors tab
|
||||
navigateToContractorsTab()
|
||||
|
||||
// Navigate to Residences
|
||||
let residencesTab = app.tabBars.buttons.containing(NSPredicate(format: "label CONTAINS[c] 'Residences'")).firstMatch
|
||||
XCTAssertTrue(residencesTab.exists, "Residences tab should exist")
|
||||
residencesTab.tap()
|
||||
sleep(1)
|
||||
XCTAssertTrue(residencesTab.isSelected, "Should be on Residences tab")
|
||||
|
||||
// Navigate back to Contractors
|
||||
let contractorsTab = app.tabBars.buttons.containing(NSPredicate(format: "label CONTAINS[c] 'Contractors'")).firstMatch
|
||||
contractorsTab.tap()
|
||||
sleep(1)
|
||||
XCTAssertTrue(contractorsTab.isSelected, "Should be back on Contractors tab")
|
||||
|
||||
// Navigate to Tasks
|
||||
let tasksTab = app.tabBars.buttons.containing(NSPredicate(format: "label CONTAINS[c] 'Tasks'")).firstMatch
|
||||
XCTAssertTrue(tasksTab.exists, "Tasks tab should exist")
|
||||
tasksTab.tap()
|
||||
sleep(1)
|
||||
XCTAssertTrue(tasksTab.isSelected, "Should be on Tasks tab")
|
||||
|
||||
// Back to Contractors
|
||||
contractorsTab.tap()
|
||||
sleep(1)
|
||||
XCTAssertTrue(contractorsTab.isSelected, "Should be back on Contractors tab again")
|
||||
}
|
||||
|
||||
func testRefreshContractorsList() {
|
||||
navigateToContractorsTab()
|
||||
sleep(2)
|
||||
|
||||
// Pull to refresh (if implemented) or use refresh button
|
||||
let refreshButton = app.navigationBars.buttons.containing(NSPredicate(format: "label CONTAINS 'arrow.clockwise' OR label CONTAINS 'refresh'")).firstMatch
|
||||
if refreshButton.exists {
|
||||
refreshButton.tap()
|
||||
sleep(3)
|
||||
}
|
||||
|
||||
// Verify we're still on contractors tab
|
||||
let contractorsTab = app.tabBars.buttons.containing(NSPredicate(format: "label CONTAINS[c] 'Contractors'")).firstMatch
|
||||
XCTAssertTrue(contractorsTab.isSelected, "Should still be on Contractors tab after refresh")
|
||||
}
|
||||
|
||||
func testViewContractorDetails() {
|
||||
let timestamp = Int(Date().timeIntervalSince1970)
|
||||
let contractorName = "Detail View Test \(timestamp)"
|
||||
|
||||
// Create contractor
|
||||
guard createContractor(name: contractorName, email: "test@example.com", company: "Test Company") else {
|
||||
XCTFail("Failed to create contractor")
|
||||
return
|
||||
}
|
||||
|
||||
navigateToContractorsTab()
|
||||
sleep(2)
|
||||
|
||||
// Tap on contractor
|
||||
let contractor = findContractor(name: contractorName)
|
||||
XCTAssertTrue(contractor.exists, "Contractor should exist")
|
||||
contractor.tap()
|
||||
sleep(3)
|
||||
|
||||
// Verify detail view appears with contact info
|
||||
let phoneLabel = app.staticTexts.containing(NSPredicate(format: "label CONTAINS 'Phone' OR label CONTAINS '555'")).firstMatch
|
||||
let emailLabel = app.staticTexts.containing(NSPredicate(format: "label CONTAINS 'Email' OR label CONTAINS 'test@example.com'")).firstMatch
|
||||
|
||||
XCTAssertTrue(phoneLabel.exists || emailLabel.exists, "Detail view should show contact information")
|
||||
}
|
||||
|
||||
// MARK: - Data Persistence Tests
|
||||
|
||||
func testContractorPersistsAfterBackgroundingApp() {
|
||||
let timestamp = Int(Date().timeIntervalSince1970)
|
||||
let contractorName = "Persistence Test \(timestamp)"
|
||||
|
||||
// Create contractor
|
||||
guard createContractor(name: contractorName) else {
|
||||
XCTFail("Failed to create contractor")
|
||||
return
|
||||
}
|
||||
|
||||
navigateToContractorsTab()
|
||||
sleep(2)
|
||||
|
||||
// Verify contractor exists
|
||||
var contractor = findContractor(name: contractorName)
|
||||
XCTAssertTrue(contractor.exists, "Contractor should exist before backgrounding")
|
||||
|
||||
// Background and reactivate app
|
||||
XCUIDevice.shared.press(.home)
|
||||
sleep(2)
|
||||
app.activate()
|
||||
sleep(3)
|
||||
|
||||
// Navigate back to contractors
|
||||
navigateToContractorsTab()
|
||||
sleep(2)
|
||||
|
||||
// Verify contractor still exists
|
||||
contractor = findContractor(name: contractorName)
|
||||
XCTAssertTrue(contractor.exists, "Contractor should persist after backgrounding app")
|
||||
}
|
||||
|
||||
// MARK: - Performance Tests
|
||||
|
||||
func testContractorListPerformance() {
|
||||
measure(metrics: [XCTClockMetric(), XCTMemoryMetric()]) {
|
||||
navigateToContractorsTab()
|
||||
sleep(2)
|
||||
}
|
||||
}
|
||||
|
||||
func testContractorCreationPerformance() {
|
||||
let timestamp = Int(Date().timeIntervalSince1970)
|
||||
|
||||
measure(metrics: [XCTClockMetric()]) {
|
||||
let contractorName = "Performance Test \(timestamp)_\(UUID().uuidString.prefix(8))"
|
||||
_ = createContractor(name: contractorName)
|
||||
}
|
||||
}
|
||||
}
|
||||
931
iosApp/CaseraUITests/ComprehensiveDocumentWarrantyTests.swift
Normal file
931
iosApp/CaseraUITests/ComprehensiveDocumentWarrantyTests.swift
Normal file
@@ -0,0 +1,931 @@
|
||||
import XCTest
|
||||
|
||||
/// Comprehensive documents and warranties testing suite covering all scenarios, edge cases, and variations
|
||||
/// Tests both document types (permits, receipts, etc.) and warranties with filtering, searching, and CRUD operations
|
||||
final class ComprehensiveDocumentWarrantyTests: XCTestCase {
|
||||
var app: XCUIApplication!
|
||||
|
||||
// Test data tracking
|
||||
var createdDocumentTitles: [String] = []
|
||||
var currentResidenceId: Int32?
|
||||
|
||||
override func setUpWithError() throws {
|
||||
continueAfterFailure = false
|
||||
app = XCUIApplication()
|
||||
app.launch()
|
||||
|
||||
// Ensure user is logged in
|
||||
UITestHelpers.ensureLoggedIn(app: app)
|
||||
|
||||
// Navigate to a residence first (documents are residence-specific)
|
||||
navigateToFirstResidence()
|
||||
}
|
||||
|
||||
override func tearDownWithError() throws {
|
||||
createdDocumentTitles.removeAll()
|
||||
currentResidenceId = nil
|
||||
app = nil
|
||||
}
|
||||
|
||||
// MARK: - Helper Methods
|
||||
|
||||
private func navigateToFirstResidence() {
|
||||
// Tap Residences tab
|
||||
let residencesTab = app.tabBars.buttons.containing(NSPredicate(format: "label CONTAINS[c] 'Residences'")).firstMatch
|
||||
if residencesTab.waitForExistence(timeout: 5) {
|
||||
residencesTab.tap()
|
||||
sleep(3)
|
||||
}
|
||||
|
||||
// Tap first residence card
|
||||
let firstResidence = app.collectionViews.cells.firstMatch
|
||||
if firstResidence.waitForExistence(timeout: 5) {
|
||||
firstResidence.tap()
|
||||
sleep(2)
|
||||
}
|
||||
}
|
||||
|
||||
private func navigateToDocumentsTab() {
|
||||
// Look for Documents tab or navigation link
|
||||
let documentsButton = app.buttons.containing(NSPredicate(format: "label CONTAINS[c] 'Documents' OR label CONTAINS[c] 'Warranties'")).firstMatch
|
||||
if documentsButton.waitForExistence(timeout: 5) {
|
||||
documentsButton.tap()
|
||||
sleep(3)
|
||||
}
|
||||
}
|
||||
|
||||
private func openDocumentForm() -> Bool {
|
||||
let addButton = findAddButton()
|
||||
guard addButton.exists && addButton.isEnabled else { return false }
|
||||
addButton.tap()
|
||||
sleep(3)
|
||||
|
||||
// Verify form opened
|
||||
let titleField = app.textFields.containing(NSPredicate(format: "placeholderValue CONTAINS[c] 'Title'")).firstMatch
|
||||
return titleField.waitForExistence(timeout: 5)
|
||||
}
|
||||
|
||||
private func findAddButton() -> XCUIElement {
|
||||
sleep(2)
|
||||
|
||||
// Look for add button by various methods
|
||||
let navBarButtons = app.navigationBars.buttons
|
||||
for i in 0..<navBarButtons.count {
|
||||
let button = navBarButtons.element(boundBy: i)
|
||||
if button.label == "plus" || button.label.contains("Add") {
|
||||
if button.isEnabled {
|
||||
return button
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Fallback: look for any button with plus icon
|
||||
return app.buttons.containing(NSPredicate(format: "label CONTAINS 'plus'")).firstMatch
|
||||
}
|
||||
|
||||
private func fillTextField(placeholder: String, text: String) {
|
||||
let field = app.textFields.containing(NSPredicate(format: "placeholderValue CONTAINS[c] '\(placeholder)'")).firstMatch
|
||||
if field.exists {
|
||||
field.tap()
|
||||
field.typeText(text)
|
||||
}
|
||||
}
|
||||
|
||||
private func fillTextEditor(text: String) {
|
||||
let textEditor = app.textViews.firstMatch
|
||||
if textEditor.exists {
|
||||
textEditor.tap()
|
||||
textEditor.typeText(text)
|
||||
}
|
||||
}
|
||||
|
||||
private func selectProperty() {
|
||||
app/*@START_MENU_TOKEN@*/.buttons["Select Property, Select Property"]/*[[".buttons.containing(.staticText, identifier: \"Select Property\")",".otherElements.buttons[\"Select Property, Select Property\"]",".buttons[\"Select Property, Select Property\"]"],[[[-1,2],[-1,1],[-1,0]]],[0]]@END_MENU_TOKEN@*/.firstMatch.tap()
|
||||
app.buttons.containing(NSPredicate(format: "label CONTAINS[c] 'Performance'")).firstMatch.tap()
|
||||
}
|
||||
|
||||
private func selectDocumentType(type: String) {
|
||||
let typePicker = app.buttons.containing(NSPredicate(format: "label CONTAINS[c] 'Type'")).firstMatch
|
||||
if typePicker.exists {
|
||||
typePicker.tap()
|
||||
sleep(1)
|
||||
|
||||
let typeButton = app.buttons[type]
|
||||
if typeButton.exists {
|
||||
typeButton.tap()
|
||||
sleep(1)
|
||||
} else {
|
||||
// Try cells if it's a navigation style picker
|
||||
let cells = app.cells
|
||||
for i in 0..<cells.count {
|
||||
let cell = cells.element(boundBy: i)
|
||||
if cell.staticTexts[type].exists {
|
||||
cell.tap()
|
||||
sleep(1)
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func selectCategory(category: String) {
|
||||
let categoryPicker = app.buttons.containing(NSPredicate(format: "label CONTAINS[c] 'Category'")).firstMatch
|
||||
if categoryPicker.exists {
|
||||
categoryPicker.tap()
|
||||
sleep(1)
|
||||
|
||||
let categoryButton = app.buttons[category]
|
||||
if categoryButton.exists {
|
||||
categoryButton.tap()
|
||||
sleep(1)
|
||||
} else {
|
||||
let cells = app.cells
|
||||
for i in 0..<cells.count {
|
||||
let cell = cells.element(boundBy: i)
|
||||
if cell.staticTexts[category].exists {
|
||||
cell.tap()
|
||||
sleep(1)
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func selectDate(dateType: String, daysFromNow: Int) {
|
||||
let datePicker = app.buttons.containing(NSPredicate(format: "label CONTAINS[c] '\(dateType)'")).firstMatch
|
||||
if datePicker.exists {
|
||||
datePicker.tap()
|
||||
sleep(1)
|
||||
|
||||
// Look for date picker and set date
|
||||
let datePickerWheel = app.datePickers.firstMatch
|
||||
if datePickerWheel.exists {
|
||||
let calendar = Calendar.current
|
||||
let targetDate = calendar.date(byAdding: .day, value: daysFromNow, to: Date())!
|
||||
let formatter = DateFormatter()
|
||||
formatter.dateFormat = "MMM d, yyyy"
|
||||
let dateString = formatter.string(from: targetDate)
|
||||
|
||||
// Try to type the date or interact with picker
|
||||
sleep(1)
|
||||
}
|
||||
|
||||
// Dismiss picker
|
||||
app.buttons["Done"].tap()
|
||||
sleep(1)
|
||||
}
|
||||
}
|
||||
|
||||
private func submitForm() -> Bool {
|
||||
let submitButton = app.buttons.containing(NSPredicate(format: "label CONTAINS[c] 'Save' OR label CONTAINS[c] 'Add' OR label CONTAINS[c] 'Create'")).firstMatch
|
||||
guard submitButton.exists && submitButton.isEnabled else { return false }
|
||||
submitButton.tap()
|
||||
sleep(3)
|
||||
return true
|
||||
}
|
||||
|
||||
private func cancelForm() {
|
||||
let cancelButton = app.buttons.containing(NSPredicate(format: "label CONTAINS[c] 'Cancel'")).firstMatch
|
||||
if cancelButton.exists {
|
||||
cancelButton.tap()
|
||||
sleep(2)
|
||||
}
|
||||
}
|
||||
|
||||
private func switchToWarrantiesTab() {
|
||||
app/*@START_MENU_TOKEN@*/.buttons["checkmark.shield"]/*[[".segmentedControls",".buttons[\"Warranties\"]",".buttons[\"checkmark.shield\"]"],[[[-1,2],[-1,1],[-1,0,1]],[[-1,2],[-1,1]]],[0]]@END_MENU_TOKEN@*/.firstMatch.tap()
|
||||
}
|
||||
|
||||
private func switchToDocumentsTab() {
|
||||
app/*@START_MENU_TOKEN@*/.buttons["doc.text"]/*[[".segmentedControls",".buttons[\"Documents\"]",".buttons[\"doc.text\"]"],[[[-1,2],[-1,0,1]],[[-1,2],[-1,1]]],[0]]@END_MENU_TOKEN@*/.firstMatch.tap()
|
||||
}
|
||||
|
||||
private func searchFor(text: String) {
|
||||
let searchField = app.searchFields.firstMatch
|
||||
if searchField.exists {
|
||||
searchField.tap()
|
||||
searchField.typeText(text)
|
||||
sleep(2)
|
||||
}
|
||||
}
|
||||
|
||||
private func clearSearch() {
|
||||
let searchField = app.searchFields.firstMatch
|
||||
if searchField.exists {
|
||||
let clearButton = searchField.buttons["Clear text"]
|
||||
if clearButton.exists {
|
||||
clearButton.tap()
|
||||
sleep(1)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func applyFilter(filterName: String) {
|
||||
// Open filter menu
|
||||
let filterButton = app.buttons.containing(NSPredicate(format: "label CONTAINS 'line.3.horizontal.decrease'")).firstMatch
|
||||
if filterButton.exists {
|
||||
filterButton.tap()
|
||||
sleep(1)
|
||||
|
||||
// Select filter option
|
||||
let filterOption = app.buttons[filterName]
|
||||
if filterOption.exists {
|
||||
filterOption.tap()
|
||||
sleep(2)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func toggleActiveFilter() {
|
||||
let activeFilterButton = app.buttons.containing(NSPredicate(format: "label CONTAINS 'checkmark.circle'")).firstMatch
|
||||
if activeFilterButton.exists {
|
||||
activeFilterButton.tap()
|
||||
sleep(2)
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Test Cases
|
||||
|
||||
// MARK: Navigation Tests
|
||||
|
||||
func test01_NavigateToDocumentsScreen() {
|
||||
navigateToDocumentsTab()
|
||||
|
||||
// Verify we're on documents screen
|
||||
let navigationTitle = app.navigationBars["Documents & Warranties"]
|
||||
XCTAssertTrue(navigationTitle.waitForExistence(timeout: 5), "Should navigate to Documents & Warranties screen")
|
||||
|
||||
// Verify tabs are visible
|
||||
let warrantiesTab = app.buttons["Warranties"]
|
||||
let documentsTab = app.buttons["Documents"]
|
||||
XCTAssertTrue(warrantiesTab.exists || documentsTab.exists, "Should see tab switcher")
|
||||
}
|
||||
|
||||
func test02_SwitchBetweenWarrantiesAndDocuments() {
|
||||
navigateToDocumentsTab()
|
||||
|
||||
// Start on warranties tab
|
||||
switchToWarrantiesTab()
|
||||
sleep(1)
|
||||
|
||||
// Switch to documents tab
|
||||
switchToDocumentsTab()
|
||||
sleep(1)
|
||||
|
||||
// Switch back to warranties
|
||||
switchToWarrantiesTab()
|
||||
sleep(1)
|
||||
|
||||
// Should not crash and tabs should still exist
|
||||
let warrantiesTab = app.buttons["Warranties"]
|
||||
XCTAssertTrue(warrantiesTab.exists, "Tabs should remain functional after switching")
|
||||
}
|
||||
|
||||
// MARK: Document Creation Tests
|
||||
|
||||
func test03_CreateDocumentWithAllFields() {
|
||||
navigateToDocumentsTab()
|
||||
switchToDocumentsTab()
|
||||
|
||||
XCTAssertTrue(openDocumentForm(), "Should open document form")
|
||||
|
||||
let testTitle = "Test Permit \(UUID().uuidString.prefix(8))"
|
||||
createdDocumentTitles.append(testTitle)
|
||||
|
||||
// Fill all fields
|
||||
selectProperty() // REQUIRED - Select property first
|
||||
fillTextField(placeholder: "Title", text: testTitle)
|
||||
selectDocumentType(type: "Insurance")
|
||||
fillTextEditor(text: "Test permit description with detailed information")
|
||||
fillTextField(placeholder: "Tags", text: "construction,permit")
|
||||
fillTextField(placeholder: "Item Name", text: "Kitchen Renovation")
|
||||
fillTextField(placeholder: "Location", text: "Main Kitchen")
|
||||
|
||||
XCTAssertTrue(submitForm(), "Should submit form successfully")
|
||||
|
||||
// Verify document appears in list
|
||||
sleep(2)
|
||||
let documentCard = app.staticTexts[testTitle]
|
||||
XCTAssertTrue(documentCard.exists, "Created document should appear in list")
|
||||
}
|
||||
|
||||
func test04_CreateDocumentWithMinimalFields() {
|
||||
navigateToDocumentsTab()
|
||||
switchToDocumentsTab()
|
||||
|
||||
XCTAssertTrue(openDocumentForm(), "Should open document form")
|
||||
|
||||
let testTitle = "Min Doc \(UUID().uuidString.prefix(8))"
|
||||
createdDocumentTitles.append(testTitle)
|
||||
|
||||
// Fill only required fields
|
||||
selectProperty() // REQUIRED - Select property first
|
||||
fillTextField(placeholder: "Title", text: testTitle)
|
||||
selectDocumentType(type: "Insurance")
|
||||
|
||||
XCTAssertTrue(submitForm(), "Should submit form with minimal fields")
|
||||
|
||||
// Verify document appears
|
||||
sleep(2)
|
||||
let documentCard = app.staticTexts[testTitle]
|
||||
XCTAssertTrue(documentCard.exists, "Document with minimal fields should appear")
|
||||
}
|
||||
|
||||
func test05_CreateDocumentWithEmptyTitle_ShouldFail() {
|
||||
navigateToDocumentsTab()
|
||||
switchToDocumentsTab()
|
||||
|
||||
XCTAssertTrue(openDocumentForm(), "Should open document form")
|
||||
|
||||
// Try to submit without title
|
||||
selectProperty() // REQUIRED - Select property first
|
||||
selectDocumentType(type: "Insurance")
|
||||
|
||||
let submitButton = app.buttons.containing(NSPredicate(format: "label CONTAINS[c] 'Save' OR label CONTAINS[c] 'Add'")).firstMatch
|
||||
|
||||
// Submit button should be disabled or show error
|
||||
if submitButton.exists && submitButton.isEnabled {
|
||||
submitButton.tap()
|
||||
sleep(2)
|
||||
|
||||
// Should show error message
|
||||
let errorMessage = app.staticTexts.containing(NSPredicate(format: "label CONTAINS[c] 'required' OR label CONTAINS[c] 'title'")).firstMatch
|
||||
XCTAssertTrue(errorMessage.exists, "Should show validation error for missing title")
|
||||
}
|
||||
|
||||
cancelForm()
|
||||
}
|
||||
|
||||
// MARK: Warranty Creation Tests
|
||||
|
||||
func test06_CreateWarrantyWithAllFields() {
|
||||
navigateToDocumentsTab()
|
||||
switchToWarrantiesTab()
|
||||
|
||||
XCTAssertTrue(openDocumentForm(), "Should open warranty form")
|
||||
|
||||
let testTitle = "Test Warranty \(UUID().uuidString.prefix(8))"
|
||||
createdDocumentTitles.append(testTitle)
|
||||
|
||||
// Fill all warranty fields (including required fields)
|
||||
selectProperty() // REQUIRED - Select property first
|
||||
fillTextField(placeholder: "Title", text: testTitle)
|
||||
selectCategory(category: "Appliances")
|
||||
fillTextField(placeholder: "Item Name", text: "Dishwasher") // REQUIRED
|
||||
fillTextField(placeholder: "Provider", text: "Bosch") // REQUIRED
|
||||
fillTextField(placeholder: "Model", text: "SHPM65Z55N")
|
||||
fillTextField(placeholder: "Serial", text: "SN123456789")
|
||||
fillTextField(placeholder: "Provider Contact", text: "1-800-BOSCH-00")
|
||||
fillTextEditor(text: "Full warranty coverage for 2 years")
|
||||
|
||||
// Select dates
|
||||
selectDate(dateType: "Start Date", daysFromNow: -30)
|
||||
selectDate(dateType: "End Date", daysFromNow: 700) // ~2 years
|
||||
|
||||
XCTAssertTrue(submitForm(), "Should submit warranty successfully")
|
||||
|
||||
// Verify warranty appears
|
||||
sleep(2)
|
||||
let warrantyCard = app.staticTexts[testTitle]
|
||||
XCTAssertTrue(warrantyCard.exists, "Created warranty should appear in list")
|
||||
}
|
||||
|
||||
func test07_CreateWarrantyWithFutureDates() {
|
||||
navigateToDocumentsTab()
|
||||
switchToWarrantiesTab()
|
||||
|
||||
XCTAssertTrue(openDocumentForm(), "Should open warranty form")
|
||||
|
||||
let testTitle = "Future Warranty \(UUID().uuidString.prefix(8))"
|
||||
createdDocumentTitles.append(testTitle)
|
||||
|
||||
selectProperty() // REQUIRED - Select property first
|
||||
fillTextField(placeholder: "Title", text: testTitle)
|
||||
selectCategory(category: "HVAC")
|
||||
fillTextField(placeholder: "Item Name", text: "Air Conditioner") // REQUIRED
|
||||
fillTextField(placeholder: "Provider", text: "Carrier HVAC") // REQUIRED
|
||||
|
||||
// Set start date in future
|
||||
selectDate(dateType: "Start Date", daysFromNow: 30)
|
||||
selectDate(dateType: "End Date", daysFromNow: 400)
|
||||
|
||||
XCTAssertTrue(submitForm(), "Should create warranty with future dates")
|
||||
|
||||
sleep(2)
|
||||
let warrantyCard = app.staticTexts[testTitle]
|
||||
XCTAssertTrue(warrantyCard.exists, "Warranty with future dates should be created")
|
||||
}
|
||||
|
||||
func test08_CreateExpiredWarranty() {
|
||||
navigateToDocumentsTab()
|
||||
switchToWarrantiesTab()
|
||||
|
||||
XCTAssertTrue(openDocumentForm(), "Should open warranty form")
|
||||
|
||||
let testTitle = "Expired Warranty \(UUID().uuidString.prefix(8))"
|
||||
createdDocumentTitles.append(testTitle)
|
||||
|
||||
selectProperty() // REQUIRED - Select property first
|
||||
fillTextField(placeholder: "Title", text: testTitle)
|
||||
selectCategory(category: "Plumbing")
|
||||
fillTextField(placeholder: "Item Name", text: "Water Heater") // REQUIRED
|
||||
fillTextField(placeholder: "Provider", text: "AO Smith") // REQUIRED
|
||||
|
||||
// Set dates in the past
|
||||
selectDate(dateType: "Start Date", daysFromNow: -400)
|
||||
selectDate(dateType: "End Date", daysFromNow: -30)
|
||||
|
||||
XCTAssertTrue(submitForm(), "Should create expired warranty")
|
||||
|
||||
sleep(2)
|
||||
// Expired warranty might not show with active filter on
|
||||
// Toggle active filter off to see it
|
||||
toggleActiveFilter()
|
||||
sleep(1)
|
||||
|
||||
let warrantyCard = app.staticTexts[testTitle]
|
||||
XCTAssertTrue(warrantyCard.exists, "Expired warranty should be created and visible when filter is off")
|
||||
}
|
||||
|
||||
// MARK: Search and Filter Tests
|
||||
|
||||
func test09_SearchDocumentsByTitle() {
|
||||
navigateToDocumentsTab()
|
||||
switchToDocumentsTab()
|
||||
|
||||
// Create a test document first
|
||||
XCTAssertTrue(openDocumentForm(), "Should open form")
|
||||
let searchableTitle = "Searchable Doc \(UUID().uuidString.prefix(8))"
|
||||
createdDocumentTitles.append(searchableTitle)
|
||||
selectProperty() // REQUIRED - Select property first
|
||||
fillTextField(placeholder: "Title", text: searchableTitle)
|
||||
selectDocumentType(type: "Insurance")
|
||||
XCTAssertTrue(submitForm(), "Should create document")
|
||||
sleep(2)
|
||||
|
||||
// Search for it
|
||||
searchFor(text: String(searchableTitle.prefix(15)))
|
||||
|
||||
// Should find the document
|
||||
let foundDocument = app.staticTexts[searchableTitle]
|
||||
XCTAssertTrue(foundDocument.exists, "Should find document by search")
|
||||
|
||||
clearSearch()
|
||||
}
|
||||
|
||||
func test10_FilterWarrantiesByCategory() {
|
||||
navigateToDocumentsTab()
|
||||
switchToWarrantiesTab()
|
||||
|
||||
// Apply category filter
|
||||
applyFilter(filterName: "Appliances")
|
||||
|
||||
sleep(2)
|
||||
|
||||
// Should show filter chip or indication
|
||||
let filterChip = app.staticTexts["Appliances"]
|
||||
XCTAssertTrue(filterChip.exists || app.buttons["Appliances"].exists, "Should show active category filter")
|
||||
|
||||
// Clear filter
|
||||
applyFilter(filterName: "All Categories")
|
||||
}
|
||||
|
||||
func test11_FilterDocumentsByType() {
|
||||
navigateToDocumentsTab()
|
||||
switchToDocumentsTab()
|
||||
|
||||
// Apply type filter
|
||||
applyFilter(filterName: "Permit")
|
||||
|
||||
sleep(2)
|
||||
|
||||
// Should show filter indication
|
||||
let filterChip = app.staticTexts["Permit"]
|
||||
XCTAssertTrue(filterChip.exists || app.buttons["Permit"].exists, "Should show active type filter")
|
||||
|
||||
// Clear filter
|
||||
applyFilter(filterName: "All Types")
|
||||
}
|
||||
|
||||
func test12_ToggleActiveWarrantiesFilter() {
|
||||
navigateToDocumentsTab()
|
||||
switchToWarrantiesTab()
|
||||
|
||||
// Toggle active filter off
|
||||
toggleActiveFilter()
|
||||
sleep(1)
|
||||
|
||||
// Toggle it back on
|
||||
toggleActiveFilter()
|
||||
sleep(1)
|
||||
|
||||
// Should not crash
|
||||
let warrantiesTab = app.buttons["Warranties"]
|
||||
XCTAssertTrue(warrantiesTab.exists, "Active filter toggle should work without crashing")
|
||||
}
|
||||
|
||||
// MARK: Document Detail Tests
|
||||
|
||||
func test13_ViewDocumentDetail() {
|
||||
navigateToDocumentsTab()
|
||||
switchToDocumentsTab()
|
||||
|
||||
// Create a document
|
||||
XCTAssertTrue(openDocumentForm(), "Should open form")
|
||||
let testTitle = "Detail Test Doc \(UUID().uuidString.prefix(8))"
|
||||
createdDocumentTitles.append(testTitle)
|
||||
selectProperty() // REQUIRED - Select property first
|
||||
fillTextField(placeholder: "Title", text: testTitle)
|
||||
selectDocumentType(type: "Insurance")
|
||||
fillTextEditor(text: "This is a test receipt with details")
|
||||
XCTAssertTrue(submitForm(), "Should create document")
|
||||
sleep(2)
|
||||
|
||||
// Tap on the document card
|
||||
let documentCard = app.staticTexts[testTitle]
|
||||
XCTAssertTrue(documentCard.exists, "Document should exist in list")
|
||||
documentCard.tap()
|
||||
sleep(2)
|
||||
|
||||
// Should show detail screen
|
||||
let detailTitle = app.staticTexts[testTitle]
|
||||
XCTAssertTrue(detailTitle.exists, "Should show document detail screen")
|
||||
|
||||
// Go back
|
||||
let backButton = app.navigationBars.buttons.firstMatch
|
||||
backButton.tap()
|
||||
sleep(1)
|
||||
}
|
||||
|
||||
func test14_ViewWarrantyDetailWithDates() {
|
||||
navigateToDocumentsTab()
|
||||
switchToWarrantiesTab()
|
||||
|
||||
// Create a warranty
|
||||
XCTAssertTrue(openDocumentForm(), "Should open form")
|
||||
let testTitle = "Warranty Detail Test \(UUID().uuidString.prefix(8))"
|
||||
createdDocumentTitles.append(testTitle)
|
||||
selectProperty() // REQUIRED - Select property first
|
||||
fillTextField(placeholder: "Title", text: testTitle)
|
||||
selectCategory(category: "Appliances")
|
||||
fillTextField(placeholder: "Item Name", text: "Test Appliance") // REQUIRED
|
||||
fillTextField(placeholder: "Provider", text: "Test Company") // REQUIRED
|
||||
selectDate(dateType: "Start Date", daysFromNow: -30)
|
||||
selectDate(dateType: "End Date", daysFromNow: 335)
|
||||
XCTAssertTrue(submitForm(), "Should create warranty")
|
||||
sleep(2)
|
||||
|
||||
// Tap on warranty
|
||||
let warrantyCard = app.staticTexts[testTitle]
|
||||
XCTAssertTrue(warrantyCard.exists, "Warranty should exist")
|
||||
warrantyCard.tap()
|
||||
sleep(2)
|
||||
|
||||
// Should show warranty details with dates
|
||||
let detailScreen = app.staticTexts[testTitle]
|
||||
XCTAssertTrue(detailScreen.exists, "Should show warranty detail")
|
||||
|
||||
// Look for date information
|
||||
let dateLabels = app.staticTexts.matching(NSPredicate(format: "label CONTAINS[c] '20' OR label CONTAINS[c] 'Start' OR label CONTAINS[c] 'End'"))
|
||||
XCTAssertTrue(dateLabels.count > 0, "Should display date information")
|
||||
|
||||
// Go back
|
||||
app.navigationBars.buttons.firstMatch.tap()
|
||||
sleep(1)
|
||||
}
|
||||
|
||||
// MARK: Edit Tests
|
||||
|
||||
func test15_EditDocumentTitle() {
|
||||
navigateToDocumentsTab()
|
||||
switchToDocumentsTab()
|
||||
|
||||
// Create document
|
||||
XCTAssertTrue(openDocumentForm(), "Should open form")
|
||||
let originalTitle = "Edit Test \(UUID().uuidString.prefix(8))"
|
||||
createdDocumentTitles.append(originalTitle)
|
||||
selectProperty() // REQUIRED - Select property first
|
||||
fillTextField(placeholder: "Title", text: originalTitle)
|
||||
selectDocumentType(type: "Insurance")
|
||||
XCTAssertTrue(submitForm(), "Should create document")
|
||||
sleep(2)
|
||||
|
||||
// Open detail
|
||||
let documentCard = app.staticTexts[originalTitle]
|
||||
XCTAssertTrue(documentCard.exists, "Document should exist")
|
||||
documentCard.tap()
|
||||
sleep(2)
|
||||
|
||||
// Tap edit button
|
||||
let editButton = app.buttons.containing(NSPredicate(format: "label CONTAINS[c] 'Edit'")).firstMatch
|
||||
if editButton.exists {
|
||||
editButton.tap()
|
||||
sleep(2)
|
||||
|
||||
// Change title
|
||||
let titleField = app.textFields.containing(NSPredicate(format: "value == '\(originalTitle)'")).firstMatch
|
||||
if titleField.exists {
|
||||
titleField.tap()
|
||||
titleField.clearText()
|
||||
let newTitle = "Edited \(originalTitle)"
|
||||
titleField.typeText(newTitle)
|
||||
createdDocumentTitles.append(newTitle)
|
||||
|
||||
XCTAssertTrue(submitForm(), "Should save edited document")
|
||||
sleep(2)
|
||||
|
||||
// Verify new title appears
|
||||
let updatedTitle = app.staticTexts[newTitle]
|
||||
XCTAssertTrue(updatedTitle.exists, "Updated title should appear")
|
||||
}
|
||||
}
|
||||
|
||||
// Go back to list
|
||||
app.navigationBars.buttons.element(boundBy: 0).tap()
|
||||
sleep(1)
|
||||
}
|
||||
|
||||
func test16_EditWarrantyDates() {
|
||||
navigateToDocumentsTab()
|
||||
switchToWarrantiesTab()
|
||||
|
||||
// Create warranty
|
||||
XCTAssertTrue(openDocumentForm(), "Should open form")
|
||||
let testTitle = "Edit Dates Warranty \(UUID().uuidString.prefix(8))"
|
||||
createdDocumentTitles.append(testTitle)
|
||||
selectProperty() // REQUIRED - Select property first
|
||||
fillTextField(placeholder: "Title", text: testTitle)
|
||||
selectCategory(category: "Electronics")
|
||||
fillTextField(placeholder: "Item Name", text: "TV") // REQUIRED
|
||||
fillTextField(placeholder: "Provider", text: "Samsung") // REQUIRED
|
||||
selectDate(dateType: "Start Date", daysFromNow: -60)
|
||||
selectDate(dateType: "End Date", daysFromNow: 305)
|
||||
XCTAssertTrue(submitForm(), "Should create warranty")
|
||||
sleep(2)
|
||||
|
||||
// Open and edit
|
||||
let warrantyCard = app.staticTexts[testTitle]
|
||||
XCTAssertTrue(warrantyCard.exists, "Warranty should exist")
|
||||
warrantyCard.tap()
|
||||
sleep(2)
|
||||
|
||||
let editButton = app.buttons.containing(NSPredicate(format: "label CONTAINS[c] 'Edit'")).firstMatch
|
||||
if editButton.exists {
|
||||
editButton.tap()
|
||||
sleep(2)
|
||||
|
||||
// Change end date to extend warranty
|
||||
selectDate(dateType: "End Date", daysFromNow: 730) // 2 years
|
||||
|
||||
XCTAssertTrue(submitForm(), "Should save edited warranty dates")
|
||||
sleep(2)
|
||||
}
|
||||
|
||||
app.navigationBars.buttons.element(boundBy: 0).tap()
|
||||
sleep(1)
|
||||
}
|
||||
|
||||
// MARK: Delete Tests
|
||||
|
||||
func test17_DeleteDocument() {
|
||||
navigateToDocumentsTab()
|
||||
switchToDocumentsTab()
|
||||
|
||||
// Create document to delete
|
||||
XCTAssertTrue(openDocumentForm(), "Should open form")
|
||||
let deleteTitle = "To Delete \(UUID().uuidString.prefix(8))"
|
||||
selectProperty() // REQUIRED - Select property first
|
||||
fillTextField(placeholder: "Title", text: deleteTitle)
|
||||
selectDocumentType(type: "Insurance")
|
||||
XCTAssertTrue(submitForm(), "Should create document")
|
||||
sleep(2)
|
||||
|
||||
// Open detail
|
||||
let documentCard = app.staticTexts[deleteTitle]
|
||||
XCTAssertTrue(documentCard.exists, "Document should exist")
|
||||
documentCard.tap()
|
||||
sleep(2)
|
||||
|
||||
// Find and tap delete button
|
||||
let deleteButton = app.buttons.containing(NSPredicate(format: "label CONTAINS[c] 'Delete' OR label CONTAINS[c] 'trash'")).firstMatch
|
||||
if deleteButton.exists {
|
||||
deleteButton.tap()
|
||||
sleep(1)
|
||||
|
||||
// Confirm deletion
|
||||
let confirmButton = app.alerts.buttons.containing(NSPredicate(format: "label CONTAINS[c] 'Delete' OR label CONTAINS[c] 'Confirm'")).firstMatch
|
||||
if confirmButton.exists {
|
||||
confirmButton.tap()
|
||||
sleep(2)
|
||||
}
|
||||
|
||||
// Should navigate back to list
|
||||
sleep(2)
|
||||
|
||||
// Verify document no longer exists
|
||||
let deletedCard = app.staticTexts[deleteTitle]
|
||||
XCTAssertFalse(deletedCard.exists, "Deleted document should not appear in list")
|
||||
}
|
||||
}
|
||||
|
||||
func test18_DeleteWarranty() {
|
||||
navigateToDocumentsTab()
|
||||
switchToWarrantiesTab()
|
||||
|
||||
// Create warranty to delete
|
||||
XCTAssertTrue(openDocumentForm(), "Should open form")
|
||||
let deleteTitle = "Warranty to Delete \(UUID().uuidString.prefix(8))"
|
||||
selectProperty() // REQUIRED - Select property first
|
||||
fillTextField(placeholder: "Title", text: deleteTitle)
|
||||
selectCategory(category: "Other")
|
||||
fillTextField(placeholder: "Item Name", text: "Test Item") // REQUIRED
|
||||
fillTextField(placeholder: "Provider", text: "Test Provider") // REQUIRED
|
||||
XCTAssertTrue(submitForm(), "Should create warranty")
|
||||
sleep(2)
|
||||
|
||||
// Open and delete
|
||||
let warrantyCard = app.staticTexts[deleteTitle]
|
||||
XCTAssertTrue(warrantyCard.exists, "Warranty should exist")
|
||||
warrantyCard.tap()
|
||||
sleep(2)
|
||||
|
||||
let deleteButton = app.buttons.containing(NSPredicate(format: "label CONTAINS[c] 'Delete' OR label CONTAINS[c] 'trash'")).firstMatch
|
||||
if deleteButton.exists {
|
||||
deleteButton.tap()
|
||||
sleep(1)
|
||||
|
||||
// Confirm
|
||||
let confirmButton = app.alerts.buttons.containing(NSPredicate(format: "label CONTAINS[c] 'Delete'")).firstMatch
|
||||
if confirmButton.exists {
|
||||
confirmButton.tap()
|
||||
sleep(2)
|
||||
}
|
||||
|
||||
// Verify deleted
|
||||
sleep(2)
|
||||
let deletedCard = app.staticTexts[deleteTitle]
|
||||
XCTAssertFalse(deletedCard.exists, "Deleted warranty should not appear")
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: Edge Cases and Error Handling
|
||||
|
||||
func test19_CancelDocumentCreation() {
|
||||
navigateToDocumentsTab()
|
||||
switchToDocumentsTab()
|
||||
|
||||
XCTAssertTrue(openDocumentForm(), "Should open form")
|
||||
|
||||
// Fill some fields
|
||||
selectProperty() // REQUIRED - Select property first
|
||||
fillTextField(placeholder: "Title", text: "Cancelled Document")
|
||||
selectDocumentType(type: "Insurance")
|
||||
|
||||
// Cancel instead of save
|
||||
cancelForm()
|
||||
|
||||
// Should not appear in list
|
||||
sleep(2)
|
||||
let cancelledDoc = app.staticTexts["Cancelled Document"]
|
||||
XCTAssertFalse(cancelledDoc.exists, "Cancelled document should not be created")
|
||||
}
|
||||
|
||||
func test20_HandleEmptyDocumentsList() {
|
||||
navigateToDocumentsTab()
|
||||
switchToDocumentsTab()
|
||||
|
||||
// Apply very specific filter to get empty list
|
||||
searchFor(text: "NONEXISTENT_DOCUMENT_12345")
|
||||
|
||||
sleep(2)
|
||||
|
||||
// Should show empty state
|
||||
let emptyMessage = app.staticTexts.containing(NSPredicate(format: "label CONTAINS[c] 'No documents' OR label CONTAINS[c] 'No results' OR label CONTAINS[c] 'empty'")).firstMatch
|
||||
|
||||
// Either empty state exists or no items are shown
|
||||
let hasNoItems = app.cells.count == 0
|
||||
XCTAssertTrue(emptyMessage.exists || hasNoItems, "Should handle empty documents list gracefully")
|
||||
|
||||
clearSearch()
|
||||
}
|
||||
|
||||
func test21_HandleEmptyWarrantiesList() {
|
||||
navigateToDocumentsTab()
|
||||
switchToWarrantiesTab()
|
||||
|
||||
// Search for non-existent warranty
|
||||
searchFor(text: "NONEXISTENT_WARRANTY_99999")
|
||||
|
||||
sleep(2)
|
||||
|
||||
let emptyMessage = app.staticTexts.containing(NSPredicate(format: "label CONTAINS[c] 'No warranties' OR label CONTAINS[c] 'No results' OR label CONTAINS[c] 'empty'")).firstMatch
|
||||
let hasNoItems = app.cells.count == 0
|
||||
XCTAssertTrue(emptyMessage.exists || hasNoItems, "Should handle empty warranties list gracefully")
|
||||
|
||||
clearSearch()
|
||||
}
|
||||
|
||||
func test22_CreateDocumentWithLongTitle() {
|
||||
navigateToDocumentsTab()
|
||||
switchToDocumentsTab()
|
||||
|
||||
XCTAssertTrue(openDocumentForm(), "Should open form")
|
||||
|
||||
let longTitle = "This is a very long document title that exceeds normal length expectations to test how the UI handles lengthy text input " + UUID().uuidString
|
||||
createdDocumentTitles.append(longTitle)
|
||||
|
||||
selectProperty() // REQUIRED - Select property first
|
||||
fillTextField(placeholder: "Title", text: longTitle)
|
||||
selectDocumentType(type: "Insurance")
|
||||
|
||||
XCTAssertTrue(submitForm(), "Should handle long title")
|
||||
|
||||
sleep(2)
|
||||
// Just verify it was created (partial match)
|
||||
let partialTitle = String(longTitle.prefix(30))
|
||||
let documentExists = app.staticTexts.containing(NSPredicate(format: "label CONTAINS[c] '\(partialTitle)'")).firstMatch.exists
|
||||
XCTAssertTrue(documentExists, "Document with long title should be created")
|
||||
}
|
||||
|
||||
func test23_CreateWarrantyWithSpecialCharacters() {
|
||||
navigateToDocumentsTab()
|
||||
switchToWarrantiesTab()
|
||||
|
||||
XCTAssertTrue(openDocumentForm(), "Should open form")
|
||||
|
||||
let specialTitle = "Warranty w/ Special #Chars: @ & $ % \(UUID().uuidString.prefix(8))"
|
||||
createdDocumentTitles.append(specialTitle)
|
||||
|
||||
selectProperty() // REQUIRED - Select property first
|
||||
fillTextField(placeholder: "Title", text: specialTitle)
|
||||
selectCategory(category: "Other")
|
||||
fillTextField(placeholder: "Item Name", text: "Test @#$ Item") // REQUIRED
|
||||
fillTextField(placeholder: "Provider", text: "Special & Co.") // REQUIRED
|
||||
|
||||
XCTAssertTrue(submitForm(), "Should handle special characters")
|
||||
|
||||
sleep(2)
|
||||
let partialTitle = String(specialTitle.prefix(20))
|
||||
let warrantyExists = app.staticTexts.containing(NSPredicate(format: "label CONTAINS '\(partialTitle)'")).firstMatch.exists
|
||||
XCTAssertTrue(warrantyExists, "Warranty with special characters should be created")
|
||||
}
|
||||
|
||||
func test24_RapidTabSwitching() {
|
||||
navigateToDocumentsTab()
|
||||
|
||||
// Rapidly switch between tabs
|
||||
for _ in 0..<5 {
|
||||
switchToWarrantiesTab()
|
||||
usleep(500000) // 0.5 seconds
|
||||
switchToDocumentsTab()
|
||||
usleep(500000) // 0.5 seconds
|
||||
}
|
||||
|
||||
// Should remain stable
|
||||
let warrantiesTab = app.buttons["Warranties"]
|
||||
let documentsTab = app.buttons["Documents"]
|
||||
XCTAssertTrue(warrantiesTab.exists && documentsTab.exists, "Should handle rapid tab switching without crashing")
|
||||
}
|
||||
|
||||
func test25_MultipleFiltersCombined() {
|
||||
navigateToDocumentsTab()
|
||||
switchToWarrantiesTab()
|
||||
|
||||
// Apply multiple filters
|
||||
toggleActiveFilter() // Turn off active filter
|
||||
sleep(1)
|
||||
applyFilter(filterName: "Appliances")
|
||||
sleep(1)
|
||||
searchFor(text: "Test")
|
||||
|
||||
sleep(2)
|
||||
|
||||
// Should apply all filters without crashing
|
||||
let searchField = app.searchFields.firstMatch
|
||||
XCTAssertTrue(searchField.exists, "Should handle multiple filters simultaneously")
|
||||
|
||||
// Clean up
|
||||
clearSearch()
|
||||
sleep(1)
|
||||
applyFilter(filterName: "All Categories")
|
||||
sleep(1)
|
||||
toggleActiveFilter() // Turn active filter back on
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - XCUIElement Extension for Clearing Text
|
||||
|
||||
extension XCUIElement {
|
||||
func clearText() {
|
||||
guard let stringValue = self.value as? String else {
|
||||
return
|
||||
}
|
||||
|
||||
self.tap()
|
||||
|
||||
let deleteString = String(repeating: XCUIKeyboardKey.delete.rawValue, count: stringValue.count)
|
||||
self.typeText(deleteString)
|
||||
}
|
||||
}
|
||||
669
iosApp/CaseraUITests/ComprehensiveResidenceTests.swift
Normal file
669
iosApp/CaseraUITests/ComprehensiveResidenceTests.swift
Normal file
@@ -0,0 +1,669 @@
|
||||
import XCTest
|
||||
|
||||
/// Comprehensive residence testing suite covering all scenarios, edge cases, and variations
|
||||
/// This test suite is designed to be bulletproof and catch regressions early
|
||||
final class ComprehensiveResidenceTests: XCTestCase {
|
||||
var app: XCUIApplication!
|
||||
|
||||
// Test data tracking
|
||||
var createdResidenceNames: [String] = []
|
||||
|
||||
override func setUpWithError() throws {
|
||||
continueAfterFailure = false
|
||||
app = XCUIApplication()
|
||||
app.launch()
|
||||
|
||||
// Ensure user is logged in
|
||||
UITestHelpers.ensureLoggedIn(app: app)
|
||||
|
||||
// Navigate to Residences tab
|
||||
navigateToResidencesTab()
|
||||
}
|
||||
|
||||
override func tearDownWithError() throws {
|
||||
createdResidenceNames.removeAll()
|
||||
app = nil
|
||||
}
|
||||
|
||||
// MARK: - Helper Methods
|
||||
|
||||
private func navigateToResidencesTab() {
|
||||
let residencesTab = app.tabBars.buttons.containing(NSPredicate(format: "label CONTAINS[c] 'Residences'")).firstMatch
|
||||
if residencesTab.waitForExistence(timeout: 5) {
|
||||
if !residencesTab.isSelected {
|
||||
residencesTab.tap()
|
||||
sleep(3)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func openResidenceForm() -> Bool {
|
||||
let addButton = findAddResidenceButton()
|
||||
guard addButton.exists && addButton.isEnabled else { return false }
|
||||
addButton.tap()
|
||||
sleep(3)
|
||||
|
||||
// Verify form opened
|
||||
let nameField = app.textFields.containing(NSPredicate(format: "placeholderValue CONTAINS[c] 'Name'")).firstMatch
|
||||
return nameField.waitForExistence(timeout: 5)
|
||||
}
|
||||
|
||||
private func findAddResidenceButton() -> XCUIElement {
|
||||
sleep(2)
|
||||
|
||||
let addButtonById = app.buttons[AccessibilityIdentifiers.Residence.addButton]
|
||||
if addButtonById.exists && addButtonById.isEnabled {
|
||||
return addButtonById
|
||||
}
|
||||
|
||||
let navBarButtons = app.navigationBars.buttons
|
||||
for i in 0..<navBarButtons.count {
|
||||
let button = navBarButtons.element(boundBy: i)
|
||||
if button.label == "plus" || button.label.contains("Add") {
|
||||
if button.isEnabled {
|
||||
return button
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return addButtonById
|
||||
}
|
||||
|
||||
private func fillTextField(placeholder: String, text: String) {
|
||||
let field = app.textFields.containing(NSPredicate(format: "placeholderValue CONTAINS[c] '\(placeholder)'")).firstMatch
|
||||
if field.exists {
|
||||
field.tap()
|
||||
field.typeText(text)
|
||||
}
|
||||
}
|
||||
|
||||
private func selectPropertyType(type: String) {
|
||||
let propertyTypePicker = app.buttons.containing(NSPredicate(format: "label CONTAINS[c] 'Property Type'")).firstMatch
|
||||
if propertyTypePicker.exists {
|
||||
propertyTypePicker.tap()
|
||||
sleep(1)
|
||||
|
||||
// Try to find and tap the type option
|
||||
let typeButton = app.buttons[type]
|
||||
if typeButton.exists {
|
||||
typeButton.tap()
|
||||
sleep(1)
|
||||
} else {
|
||||
// Try cells if it's a navigation style picker
|
||||
let cells = app.cells
|
||||
for i in 0..<cells.count {
|
||||
let cell = cells.element(boundBy: i)
|
||||
if cell.staticTexts[type].exists {
|
||||
cell.tap()
|
||||
sleep(1)
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func createResidence(
|
||||
name: String,
|
||||
propertyType: String = "House",
|
||||
street: String = "123 Test St",
|
||||
city: String = "TestCity",
|
||||
state: String = "TS",
|
||||
postal: String = "12345",
|
||||
scrollBeforeAddress: Bool = true
|
||||
) -> Bool {
|
||||
guard openResidenceForm() else { return false }
|
||||
|
||||
// Fill name
|
||||
let nameField = app.textFields.containing(NSPredicate(format: "placeholderValue CONTAINS[c] 'Name'")).firstMatch
|
||||
nameField.tap()
|
||||
nameField.typeText(name)
|
||||
|
||||
// Select property type
|
||||
selectPropertyType(type: propertyType)
|
||||
|
||||
// Scroll to address section
|
||||
if scrollBeforeAddress {
|
||||
app.swipeUp()
|
||||
sleep(1)
|
||||
}
|
||||
|
||||
// Fill address fields
|
||||
fillTextField(placeholder: "Street", text: street)
|
||||
fillTextField(placeholder: "City", text: city)
|
||||
fillTextField(placeholder: "State", text: state)
|
||||
fillTextField(placeholder: "Postal", text: postal)
|
||||
|
||||
// Save
|
||||
let saveButton = app.buttons.containing(NSPredicate(format: "label CONTAINS[c] 'Save'")).firstMatch
|
||||
guard saveButton.exists else { return false }
|
||||
saveButton.tap()
|
||||
|
||||
sleep(4) // Wait for API call
|
||||
|
||||
// Track created residence
|
||||
createdResidenceNames.append(name)
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
private func findResidence(name: String) -> XCUIElement {
|
||||
return app.staticTexts.containing(NSPredicate(format: "label CONTAINS '\(name)'")).firstMatch
|
||||
}
|
||||
|
||||
// MARK: - Basic Residence Creation Tests
|
||||
|
||||
func testCreateResidenceWithMinimalData() {
|
||||
let timestamp = Int(Date().timeIntervalSince1970)
|
||||
let residenceName = "Minimal Home \(timestamp)"
|
||||
|
||||
let success = createResidence(name: residenceName)
|
||||
XCTAssertTrue(success, "Should successfully create residence with minimal data")
|
||||
|
||||
let residenceInList = findResidence(name: residenceName)
|
||||
XCTAssertTrue(residenceInList.waitForExistence(timeout: 10), "Residence should appear in list")
|
||||
}
|
||||
|
||||
func testCreateResidenceWithAllPropertyTypes() {
|
||||
let timestamp = Int(Date().timeIntervalSince1970)
|
||||
let propertyTypes = ["House", "Apartment", "Condo"]
|
||||
|
||||
for (index, type) in propertyTypes.enumerated() {
|
||||
let residenceName = "\(type) Test \(timestamp)_\(index)"
|
||||
let success = createResidence(name: residenceName, propertyType: type)
|
||||
XCTAssertTrue(success, "Should create \(type) residence")
|
||||
|
||||
navigateToResidencesTab()
|
||||
sleep(2)
|
||||
}
|
||||
|
||||
// Verify all residences exist
|
||||
for (index, type) in propertyTypes.enumerated() {
|
||||
let residenceName = "\(type) Test \(timestamp)_\(index)"
|
||||
let residence = findResidence(name: residenceName)
|
||||
XCTAssertTrue(residence.exists, "\(type) residence should exist in list")
|
||||
}
|
||||
}
|
||||
|
||||
func testCreateMultipleResidencesInSequence() {
|
||||
let timestamp = Int(Date().timeIntervalSince1970)
|
||||
|
||||
for i in 1...3 {
|
||||
let residenceName = "Sequential Home \(i) - \(timestamp)"
|
||||
let success = createResidence(name: residenceName)
|
||||
XCTAssertTrue(success, "Should create residence \(i)")
|
||||
|
||||
navigateToResidencesTab()
|
||||
sleep(2)
|
||||
}
|
||||
|
||||
// Verify all residences exist
|
||||
for i in 1...3 {
|
||||
let residenceName = "Sequential Home \(i) - \(timestamp)"
|
||||
let residence = findResidence(name: residenceName)
|
||||
XCTAssertTrue(residence.exists, "Residence \(i) should exist in list")
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Residence Editing Tests
|
||||
|
||||
func testEditResidenceName() {
|
||||
let timestamp = Int(Date().timeIntervalSince1970)
|
||||
let originalName = "Original Name \(timestamp)"
|
||||
let newName = "Edited Name \(timestamp)"
|
||||
|
||||
// Create residence
|
||||
guard createResidence(name: originalName) else {
|
||||
XCTFail("Failed to create residence")
|
||||
return
|
||||
}
|
||||
|
||||
navigateToResidencesTab()
|
||||
sleep(2)
|
||||
|
||||
// Find and tap residence
|
||||
let residence = findResidence(name: originalName)
|
||||
XCTAssertTrue(residence.waitForExistence(timeout: 5), "Residence should exist")
|
||||
residence.tap()
|
||||
sleep(2)
|
||||
|
||||
// Tap edit button
|
||||
let editButton = app.buttons.containing(NSPredicate(format: "label CONTAINS[c] 'Edit'")).firstMatch
|
||||
if editButton.exists {
|
||||
editButton.tap()
|
||||
sleep(2)
|
||||
|
||||
// Edit name
|
||||
let nameField = app.textFields.containing(NSPredicate(format: "placeholderValue CONTAINS[c] 'Name'")).firstMatch
|
||||
if nameField.exists {
|
||||
nameField.tap()
|
||||
// Clear existing text
|
||||
nameField.tap()
|
||||
sleep(1)
|
||||
nameField.tap()
|
||||
sleep(1)
|
||||
app.menuItems["Select All"].tap()
|
||||
sleep(1)
|
||||
nameField.typeText(newName)
|
||||
|
||||
// Save
|
||||
let saveButton = app.buttons.containing(NSPredicate(format: "label CONTAINS[c] 'Save'")).firstMatch
|
||||
if saveButton.exists {
|
||||
saveButton.tap()
|
||||
sleep(3)
|
||||
|
||||
// Track new name
|
||||
createdResidenceNames.append(newName)
|
||||
|
||||
// Verify new name appears
|
||||
navigateToResidencesTab()
|
||||
sleep(2)
|
||||
let updatedResidence = findResidence(name: newName)
|
||||
XCTAssertTrue(updatedResidence.exists, "Residence should show updated name")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func testUpdateAllResidenceFields() {
|
||||
let timestamp = Int(Date().timeIntervalSince1970)
|
||||
let originalName = "Update All Fields \(timestamp)"
|
||||
let newName = "All Fields Updated \(timestamp)"
|
||||
let newStreet = "999 Updated Avenue"
|
||||
let newCity = "NewCity"
|
||||
let newState = "NC"
|
||||
let newPostal = "99999"
|
||||
|
||||
// Create residence with initial values
|
||||
guard createResidence(name: originalName, street: "123 Old St", city: "OldCity", state: "OC", postal: "11111") else {
|
||||
XCTFail("Failed to create residence")
|
||||
return
|
||||
}
|
||||
|
||||
navigateToResidencesTab()
|
||||
sleep(2)
|
||||
|
||||
// Find and tap residence
|
||||
let residence = findResidence(name: originalName)
|
||||
XCTAssertTrue(residence.waitForExistence(timeout: 5), "Residence should exist")
|
||||
residence.tap()
|
||||
sleep(2)
|
||||
|
||||
// Tap edit button
|
||||
let editButton = app.buttons.containing(NSPredicate(format: "label CONTAINS[c] 'Edit'")).firstMatch
|
||||
XCTAssertTrue(editButton.exists, "Edit button should exist")
|
||||
editButton.tap()
|
||||
sleep(2)
|
||||
|
||||
// Update name
|
||||
let nameField = app.textFields.containing(NSPredicate(format: "placeholderValue CONTAINS[c] 'Name'")).firstMatch
|
||||
XCTAssertTrue(nameField.exists, "Name field should exist")
|
||||
nameField.tap()
|
||||
nameField.doubleTap()
|
||||
sleep(1)
|
||||
if app.buttons["Select All"].exists {
|
||||
app.buttons["Select All"].tap()
|
||||
sleep(1)
|
||||
}
|
||||
nameField.typeText(newName)
|
||||
|
||||
// Update property type (if available)
|
||||
let propertyTypePicker = app.buttons.containing(NSPredicate(format: "label CONTAINS[c] 'Property Type'")).firstMatch
|
||||
if propertyTypePicker.exists {
|
||||
propertyTypePicker.tap()
|
||||
sleep(1)
|
||||
// Select Condo
|
||||
let condoOption = app.buttons["Condo"]
|
||||
if condoOption.exists {
|
||||
condoOption.tap()
|
||||
sleep(1)
|
||||
} else {
|
||||
// Try cells navigation
|
||||
let cells = app.cells
|
||||
for i in 0..<cells.count {
|
||||
let cell = cells.element(boundBy: i)
|
||||
if cell.staticTexts["Condo"].exists {
|
||||
cell.tap()
|
||||
sleep(1)
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Scroll to address fields
|
||||
app.swipeUp()
|
||||
sleep(1)
|
||||
|
||||
// Update street
|
||||
let streetField = app.textFields.containing(NSPredicate(format: "placeholderValue CONTAINS[c] 'Street'")).firstMatch
|
||||
if streetField.exists {
|
||||
streetField.tap()
|
||||
streetField.doubleTap()
|
||||
sleep(1)
|
||||
if app.buttons["Select All"].exists {
|
||||
app.buttons["Select All"].tap()
|
||||
sleep(1)
|
||||
}
|
||||
streetField.typeText(newStreet)
|
||||
}
|
||||
|
||||
// Update city
|
||||
let cityField = app.textFields.containing(NSPredicate(format: "placeholderValue CONTAINS[c] 'City'")).firstMatch
|
||||
if cityField.exists {
|
||||
cityField.tap()
|
||||
cityField.doubleTap()
|
||||
sleep(1)
|
||||
if app.buttons["Select All"].exists {
|
||||
app.buttons["Select All"].tap()
|
||||
sleep(1)
|
||||
}
|
||||
cityField.typeText(newCity)
|
||||
}
|
||||
|
||||
// Update state
|
||||
let stateField = app.textFields.containing(NSPredicate(format: "placeholderValue CONTAINS[c] 'State'")).firstMatch
|
||||
if stateField.exists {
|
||||
stateField.tap()
|
||||
stateField.doubleTap()
|
||||
sleep(1)
|
||||
if app.buttons["Select All"].exists {
|
||||
app.buttons["Select All"].tap()
|
||||
sleep(1)
|
||||
}
|
||||
stateField.typeText(newState)
|
||||
}
|
||||
|
||||
// Update postal code
|
||||
let postalField = app.textFields.containing(NSPredicate(format: "placeholderValue CONTAINS[c] 'Postal' OR placeholderValue CONTAINS[c] 'Zip'")).firstMatch
|
||||
if postalField.exists {
|
||||
postalField.tap()
|
||||
postalField.doubleTap()
|
||||
sleep(1)
|
||||
if app.buttons["Select All"].exists {
|
||||
app.buttons["Select All"].tap()
|
||||
sleep(1)
|
||||
}
|
||||
postalField.typeText(newPostal)
|
||||
}
|
||||
|
||||
// Scroll to save button
|
||||
app.swipeUp()
|
||||
sleep(1)
|
||||
|
||||
// Save
|
||||
let saveButton = app.buttons.containing(NSPredicate(format: "label CONTAINS[c] 'Save'")).firstMatch
|
||||
XCTAssertTrue(saveButton.exists, "Save button should exist")
|
||||
saveButton.tap()
|
||||
sleep(4)
|
||||
|
||||
// Track new name
|
||||
createdResidenceNames.append(newName)
|
||||
|
||||
// Verify updated residence appears in list with new name
|
||||
navigateToResidencesTab()
|
||||
sleep(2)
|
||||
let updatedResidence = findResidence(name: newName)
|
||||
XCTAssertTrue(updatedResidence.exists, "Residence should show updated name in list")
|
||||
|
||||
// Tap on residence to verify details were updated
|
||||
updatedResidence.tap()
|
||||
sleep(2)
|
||||
|
||||
// Verify updated address appears in detail view
|
||||
let streetText = app.staticTexts.containing(NSPredicate(format: "label CONTAINS '\(newStreet)'")).firstMatch
|
||||
XCTAssertTrue(streetText.exists || true, "Updated street should be visible in detail view")
|
||||
|
||||
let cityText = app.staticTexts.containing(NSPredicate(format: "label CONTAINS '\(newCity)'")).firstMatch
|
||||
XCTAssertTrue(cityText.exists || true, "Updated city should be visible in detail view")
|
||||
|
||||
let postalText = app.staticTexts.containing(NSPredicate(format: "label CONTAINS '\(newPostal)'")).firstMatch
|
||||
XCTAssertTrue(postalText.exists || true, "Updated postal code should be visible in detail view")
|
||||
|
||||
// Verify property type was updated to Condo
|
||||
let condoBadge = app.staticTexts.containing(NSPredicate(format: "label CONTAINS 'Condo'")).firstMatch
|
||||
XCTAssertTrue(condoBadge.exists || true, "Updated property type should be visible (if shown in detail)")
|
||||
}
|
||||
|
||||
// MARK: - Validation & Error Handling Tests
|
||||
|
||||
func testCannotCreateResidenceWithEmptyName() {
|
||||
guard openResidenceForm() else {
|
||||
XCTFail("Failed to open residence form")
|
||||
return
|
||||
}
|
||||
|
||||
// Leave name empty, fill only address
|
||||
app.swipeUp()
|
||||
sleep(1)
|
||||
fillTextField(placeholder: "Street", text: "123 Test St")
|
||||
fillTextField(placeholder: "City", text: "TestCity")
|
||||
fillTextField(placeholder: "State", text: "TS")
|
||||
fillTextField(placeholder: "Postal", text: "12345")
|
||||
|
||||
// Scroll to save button if needed
|
||||
app.swipeUp()
|
||||
sleep(1)
|
||||
|
||||
// Save button should be disabled when name is empty
|
||||
let saveButton = app.buttons.containing(NSPredicate(format: "label CONTAINS[c] 'Save'")).firstMatch
|
||||
XCTAssertTrue(saveButton.exists, "Save button should exist")
|
||||
XCTAssertFalse(saveButton.isEnabled, "Save button should be disabled when name is empty")
|
||||
}
|
||||
|
||||
func testCancelResidenceCreation() {
|
||||
guard openResidenceForm() else {
|
||||
XCTFail("Failed to open residence form")
|
||||
return
|
||||
}
|
||||
|
||||
// Fill some data
|
||||
let nameField = app.textFields.containing(NSPredicate(format: "placeholderValue CONTAINS[c] 'Name'")).firstMatch
|
||||
nameField.tap()
|
||||
nameField.typeText("This will be canceled")
|
||||
|
||||
// Tap cancel
|
||||
let cancelButton = app.buttons.containing(NSPredicate(format: "label CONTAINS[c] 'Cancel'")).firstMatch
|
||||
XCTAssertTrue(cancelButton.exists, "Cancel button should exist")
|
||||
cancelButton.tap()
|
||||
sleep(2)
|
||||
|
||||
// Should be back on residences list
|
||||
let residencesTab = app.tabBars.buttons.containing(NSPredicate(format: "label CONTAINS[c] 'Residences'")).firstMatch
|
||||
XCTAssertTrue(residencesTab.exists, "Should be back on residences list")
|
||||
|
||||
// Residence should not exist
|
||||
let residence = findResidence(name: "This will be canceled")
|
||||
XCTAssertFalse(residence.exists, "Canceled residence should not exist")
|
||||
}
|
||||
|
||||
// MARK: - Edge Case Tests
|
||||
|
||||
func testCreateResidenceWithVeryLongName() {
|
||||
let timestamp = Int(Date().timeIntervalSince1970)
|
||||
let longName = "This is an extremely long residence name that goes on and on and on to test how the system handles very long text input in the name field \(timestamp)"
|
||||
|
||||
let success = createResidence(name: longName)
|
||||
XCTAssertTrue(success, "Should handle very long names")
|
||||
|
||||
// Verify it appears (may be truncated in display)
|
||||
let residence = app.staticTexts.containing(NSPredicate(format: "label CONTAINS 'extremely long residence'")).firstMatch
|
||||
XCTAssertTrue(residence.waitForExistence(timeout: 10), "Long name residence should exist")
|
||||
}
|
||||
|
||||
func testCreateResidenceWithSpecialCharacters() {
|
||||
let timestamp = Int(Date().timeIntervalSince1970)
|
||||
let specialName = "Special !@#$%^&*() Home \(timestamp)"
|
||||
|
||||
let success = createResidence(name: specialName)
|
||||
XCTAssertTrue(success, "Should handle special characters")
|
||||
|
||||
let residence = findResidence(name: "Special")
|
||||
XCTAssertTrue(residence.waitForExistence(timeout: 10), "Residence with special chars should exist")
|
||||
}
|
||||
|
||||
func testCreateResidenceWithEmojis() {
|
||||
let timestamp = Int(Date().timeIntervalSince1970)
|
||||
let emojiName = "Beach House 🏖️🌊 \(timestamp)"
|
||||
|
||||
let success = createResidence(name: emojiName)
|
||||
XCTAssertTrue(success, "Should handle emojis")
|
||||
|
||||
let residence = findResidence(name: "Beach House")
|
||||
XCTAssertTrue(residence.waitForExistence(timeout: 10), "Residence with emojis should exist")
|
||||
}
|
||||
|
||||
func testCreateResidenceWithInternationalCharacters() {
|
||||
let timestamp = Int(Date().timeIntervalSince1970)
|
||||
let internationalName = "Château Montréal \(timestamp)"
|
||||
|
||||
let success = createResidence(name: internationalName)
|
||||
XCTAssertTrue(success, "Should handle international characters")
|
||||
|
||||
let residence = findResidence(name: "Château")
|
||||
XCTAssertTrue(residence.waitForExistence(timeout: 10), "Residence with international chars should exist")
|
||||
}
|
||||
|
||||
func testCreateResidenceWithVeryLongAddress() {
|
||||
let timestamp = Int(Date().timeIntervalSince1970)
|
||||
let residenceName = "Long Address Home \(timestamp)"
|
||||
|
||||
let success = createResidence(
|
||||
name: residenceName,
|
||||
street: "123456789 Very Long Street Name That Goes On And On Boulevard Apartment Complex Unit 42B",
|
||||
city: "VeryLongCityNameThatTestsTheLimit",
|
||||
state: "CA",
|
||||
postal: "12345-6789"
|
||||
)
|
||||
XCTAssertTrue(success, "Should handle very long addresses")
|
||||
|
||||
let residence = findResidence(name: residenceName)
|
||||
XCTAssertTrue(residence.waitForExistence(timeout: 10), "Residence with long address should exist")
|
||||
}
|
||||
|
||||
// MARK: - Navigation & List Tests
|
||||
|
||||
func testNavigateFromResidencesToOtherTabs() {
|
||||
// From Residences tab
|
||||
navigateToResidencesTab()
|
||||
|
||||
// Navigate to Tasks
|
||||
let tasksTab = app.tabBars.buttons.containing(NSPredicate(format: "label CONTAINS[c] 'Tasks'")).firstMatch
|
||||
XCTAssertTrue(tasksTab.exists, "Tasks tab should exist")
|
||||
tasksTab.tap()
|
||||
sleep(1)
|
||||
XCTAssertTrue(tasksTab.isSelected, "Should be on Tasks tab")
|
||||
|
||||
// Navigate back to Residences
|
||||
let residencesTab = app.tabBars.buttons.containing(NSPredicate(format: "label CONTAINS[c] 'Residences'")).firstMatch
|
||||
residencesTab.tap()
|
||||
sleep(1)
|
||||
XCTAssertTrue(residencesTab.isSelected, "Should be back on Residences tab")
|
||||
|
||||
// Navigate to Contractors
|
||||
let contractorsTab = app.tabBars.buttons.containing(NSPredicate(format: "label CONTAINS[c] 'Contractors'")).firstMatch
|
||||
XCTAssertTrue(contractorsTab.exists, "Contractors tab should exist")
|
||||
contractorsTab.tap()
|
||||
sleep(1)
|
||||
XCTAssertTrue(contractorsTab.isSelected, "Should be on Contractors tab")
|
||||
|
||||
// Back to Residences
|
||||
residencesTab.tap()
|
||||
sleep(1)
|
||||
XCTAssertTrue(residencesTab.isSelected, "Should be back on Residences tab again")
|
||||
}
|
||||
|
||||
func testRefreshResidencesList() {
|
||||
navigateToResidencesTab()
|
||||
sleep(2)
|
||||
|
||||
// Pull to refresh (if implemented) or use refresh button
|
||||
let refreshButton = app.navigationBars.buttons.containing(NSPredicate(format: "label CONTAINS 'arrow.clockwise' OR label CONTAINS 'refresh'")).firstMatch
|
||||
if refreshButton.exists {
|
||||
refreshButton.tap()
|
||||
sleep(3)
|
||||
}
|
||||
|
||||
// Verify we're still on residences tab
|
||||
let residencesTab = app.tabBars.buttons.containing(NSPredicate(format: "label CONTAINS[c] 'Residences'")).firstMatch
|
||||
XCTAssertTrue(residencesTab.isSelected, "Should still be on Residences tab after refresh")
|
||||
}
|
||||
|
||||
func testViewResidenceDetails() {
|
||||
let timestamp = Int(Date().timeIntervalSince1970)
|
||||
let residenceName = "Detail View Test \(timestamp)"
|
||||
|
||||
// Create residence
|
||||
guard createResidence(name: residenceName) else {
|
||||
XCTFail("Failed to create residence")
|
||||
return
|
||||
}
|
||||
|
||||
navigateToResidencesTab()
|
||||
sleep(2)
|
||||
|
||||
// Tap on residence
|
||||
let residence = findResidence(name: residenceName)
|
||||
XCTAssertTrue(residence.exists, "Residence should exist")
|
||||
residence.tap()
|
||||
sleep(3)
|
||||
|
||||
// Verify detail view appears with edit button or tasks section
|
||||
let editButton = app.buttons.containing(NSPredicate(format: "label CONTAINS[c] 'Edit'")).firstMatch
|
||||
let tasksSection = app.staticTexts.containing(NSPredicate(format: "label CONTAINS[c] 'Tasks' OR label CONTAINS[c] 'Maintenance'")).firstMatch
|
||||
|
||||
XCTAssertTrue(editButton.exists || tasksSection.exists, "Detail view should show with edit button or tasks section")
|
||||
}
|
||||
|
||||
// MARK: - Data Persistence Tests
|
||||
|
||||
func testResidencePersistsAfterBackgroundingApp() {
|
||||
let timestamp = Int(Date().timeIntervalSince1970)
|
||||
let residenceName = "Persistence Test \(timestamp)"
|
||||
|
||||
// Create residence
|
||||
guard createResidence(name: residenceName) else {
|
||||
XCTFail("Failed to create residence")
|
||||
return
|
||||
}
|
||||
|
||||
navigateToResidencesTab()
|
||||
sleep(2)
|
||||
|
||||
// Verify residence exists
|
||||
var residence = findResidence(name: residenceName)
|
||||
XCTAssertTrue(residence.exists, "Residence should exist before backgrounding")
|
||||
|
||||
// Background and reactivate app
|
||||
XCUIDevice.shared.press(.home)
|
||||
sleep(2)
|
||||
app.activate()
|
||||
sleep(3)
|
||||
|
||||
// Navigate back to residences
|
||||
navigateToResidencesTab()
|
||||
sleep(2)
|
||||
|
||||
// Verify residence still exists
|
||||
residence = findResidence(name: residenceName)
|
||||
XCTAssertTrue(residence.exists, "Residence should persist after backgrounding app")
|
||||
}
|
||||
|
||||
// MARK: - Performance Tests
|
||||
|
||||
func testResidenceListPerformance() {
|
||||
measure(metrics: [XCTClockMetric(), XCTMemoryMetric()]) {
|
||||
navigateToResidencesTab()
|
||||
sleep(2)
|
||||
}
|
||||
}
|
||||
|
||||
func testResidenceCreationPerformance() {
|
||||
let timestamp = Int(Date().timeIntervalSince1970)
|
||||
|
||||
measure(metrics: [XCTClockMetric()]) {
|
||||
let residenceName = "Performance Test \(timestamp)_\(UUID().uuidString.prefix(8))"
|
||||
_ = createResidence(name: residenceName)
|
||||
}
|
||||
}
|
||||
}
|
||||
658
iosApp/CaseraUITests/ComprehensiveTaskTests.swift
Normal file
658
iosApp/CaseraUITests/ComprehensiveTaskTests.swift
Normal file
@@ -0,0 +1,658 @@
|
||||
import XCTest
|
||||
|
||||
/// Comprehensive task testing suite covering all scenarios, edge cases, and variations
|
||||
/// This test suite is designed to be bulletproof and catch regressions early
|
||||
final class ComprehensiveTaskTests: XCTestCase {
|
||||
var app: XCUIApplication!
|
||||
|
||||
// Test data tracking
|
||||
var createdTaskTitles: [String] = []
|
||||
|
||||
override func setUpWithError() throws {
|
||||
continueAfterFailure = false
|
||||
app = XCUIApplication()
|
||||
app.launch()
|
||||
|
||||
// Ensure user is logged in
|
||||
UITestHelpers.ensureLoggedIn(app: app)
|
||||
|
||||
// CRITICAL: Ensure at least one residence exists
|
||||
ensureResidenceExists()
|
||||
|
||||
// Navigate to Tasks tab
|
||||
navigateToTasksTab()
|
||||
}
|
||||
|
||||
override func tearDownWithError() throws {
|
||||
createdTaskTitles.removeAll()
|
||||
app = nil
|
||||
}
|
||||
|
||||
// MARK: - Helper Methods
|
||||
|
||||
/// Ensures at least one residence exists (required for tasks to work)
|
||||
private func ensureResidenceExists() {
|
||||
let residencesTab = app.tabBars.buttons.containing(NSPredicate(format: "label CONTAINS[c] 'Residences'")).firstMatch
|
||||
if residencesTab.waitForExistence(timeout: 5) {
|
||||
residencesTab.tap()
|
||||
sleep(2)
|
||||
|
||||
let emptyStateText = app.staticTexts.containing(NSPredicate(format: "label CONTAINS[c] 'No properties' OR label CONTAINS[c] 'No residences'")).firstMatch
|
||||
|
||||
if emptyStateText.exists {
|
||||
createTestResidence()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func createTestResidence() {
|
||||
let addButton = app.buttons[AccessibilityIdentifiers.Residence.addButton]
|
||||
guard addButton.waitForExistence(timeout: 5) else { return }
|
||||
addButton.tap()
|
||||
sleep(2)
|
||||
|
||||
let nameField = app.textFields.containing(NSPredicate(format: "placeholderValue CONTAINS[c] 'Name'")).firstMatch
|
||||
guard nameField.waitForExistence(timeout: 5) else { return }
|
||||
nameField.tap()
|
||||
nameField.typeText("Test Home for Comprehensive Tasks")
|
||||
|
||||
app.swipeUp()
|
||||
sleep(1)
|
||||
|
||||
fillField(placeholder: "Street", text: "123 Test St")
|
||||
fillField(placeholder: "City", text: "TestCity")
|
||||
fillField(placeholder: "State", text: "TS")
|
||||
fillField(placeholder: "Postal", text: "12345")
|
||||
|
||||
let saveButton = app.buttons.containing(NSPredicate(format: "label CONTAINS[c] 'Save'")).firstMatch
|
||||
if saveButton.exists {
|
||||
saveButton.tap()
|
||||
sleep(3)
|
||||
}
|
||||
}
|
||||
|
||||
private func navigateToTasksTab() {
|
||||
let tasksTab = app.tabBars.buttons.containing(NSPredicate(format: "label CONTAINS[c] 'Tasks'")).firstMatch
|
||||
if tasksTab.waitForExistence(timeout: 5) {
|
||||
if !tasksTab.isSelected {
|
||||
tasksTab.tap()
|
||||
sleep(3)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func openTaskForm() -> Bool {
|
||||
let addButton = findAddTaskButton()
|
||||
guard addButton.exists && addButton.isEnabled else { return false }
|
||||
addButton.tap()
|
||||
sleep(3)
|
||||
|
||||
// Verify form opened
|
||||
let titleField = app.textFields.containing(NSPredicate(format: "placeholderValue CONTAINS[c] 'Title'")).firstMatch
|
||||
return titleField.waitForExistence(timeout: 5)
|
||||
}
|
||||
|
||||
private func findAddTaskButton() -> XCUIElement {
|
||||
sleep(2)
|
||||
|
||||
let addButtonById = app.buttons[AccessibilityIdentifiers.Task.addButton].firstMatch
|
||||
if addButtonById.exists && addButtonById.isEnabled {
|
||||
return addButtonById
|
||||
}
|
||||
|
||||
let navBarButtons = app.navigationBars.buttons
|
||||
for i in 0..<navBarButtons.count {
|
||||
let button = navBarButtons.element(boundBy: i)
|
||||
if button.label == "plus" || button.label.contains("Add") {
|
||||
if button.isEnabled {
|
||||
return button
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return addButtonById
|
||||
}
|
||||
|
||||
private func fillField(placeholder: String, text: String) {
|
||||
let field = app.textFields.containing(NSPredicate(format: "placeholderValue CONTAINS[c] '\(placeholder)'")).firstMatch
|
||||
if field.exists {
|
||||
field.tap()
|
||||
field.typeText(text)
|
||||
}
|
||||
}
|
||||
|
||||
private func selectPicker(label: String, option: String) {
|
||||
let picker = app.buttons.containing(NSPredicate(format: "label CONTAINS[c] '\(label)'")).firstMatch
|
||||
if picker.exists {
|
||||
picker.tap()
|
||||
sleep(1)
|
||||
|
||||
// Try to find and tap the option
|
||||
let optionButton = app.buttons[option]
|
||||
if optionButton.exists {
|
||||
optionButton.tap()
|
||||
sleep(1)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func createTask(
|
||||
title: String,
|
||||
description: String? = nil,
|
||||
scrollToFindFields: Bool = true
|
||||
) -> Bool {
|
||||
guard openTaskForm() else { return false }
|
||||
|
||||
let titleField = app.textFields.containing(NSPredicate(format: "placeholderValue CONTAINS[c] 'Title'")).firstMatch
|
||||
titleField.tap()
|
||||
titleField.typeText(title)
|
||||
|
||||
if let desc = description {
|
||||
if scrollToFindFields { app.swipeUp(); sleep(1) }
|
||||
let descField = app.textViews.containing(NSPredicate(format: "placeholderValue CONTAINS[c] 'Description'")).firstMatch
|
||||
if descField.exists {
|
||||
descField.tap()
|
||||
descField.typeText(desc)
|
||||
}
|
||||
}
|
||||
|
||||
// Scroll to Save button
|
||||
app.swipeUp()
|
||||
sleep(1)
|
||||
|
||||
let saveButton = app.buttons.containing(NSPredicate(format: "label CONTAINS[c] 'Save'")).firstMatch
|
||||
guard saveButton.exists else { return false }
|
||||
saveButton.tap()
|
||||
|
||||
sleep(4) // Wait for API call
|
||||
|
||||
// Track created task
|
||||
createdTaskTitles.append(title)
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
private func findTask(title: String) -> XCUIElement {
|
||||
return app.staticTexts.containing(NSPredicate(format: "label CONTAINS '\(title)'")).firstMatch
|
||||
}
|
||||
|
||||
private func deleteAllTestTasks() {
|
||||
for title in createdTaskTitles {
|
||||
let task = findTask(title: title)
|
||||
if task.exists {
|
||||
task.tap()
|
||||
sleep(2)
|
||||
|
||||
// Try to find delete button
|
||||
let deleteButton = app.buttons.containing(NSPredicate(format: "label CONTAINS[c] 'Delete' OR label CONTAINS[c] 'Cancel'")).firstMatch
|
||||
if deleteButton.exists {
|
||||
deleteButton.tap()
|
||||
sleep(1)
|
||||
|
||||
// Confirm deletion
|
||||
let confirmButton = app.alerts.buttons.containing(NSPredicate(format: "label CONTAINS[c] 'Delete' OR label CONTAINS[c] 'Archive' OR label CONTAINS[c] 'Confirm'")).firstMatch
|
||||
if confirmButton.exists {
|
||||
confirmButton.tap()
|
||||
sleep(2)
|
||||
}
|
||||
}
|
||||
|
||||
// Go back to list
|
||||
let backButton = app.navigationBars.buttons.firstMatch
|
||||
if backButton.exists {
|
||||
backButton.tap()
|
||||
sleep(1)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Basic Task Creation Tests
|
||||
|
||||
func testCreateTaskWithMinimalData() {
|
||||
let timestamp = Int(Date().timeIntervalSince1970)
|
||||
let taskTitle = "Minimal Task \(timestamp)"
|
||||
|
||||
let success = createTask(title: taskTitle)
|
||||
XCTAssertTrue(success, "Should successfully create task with minimal data")
|
||||
|
||||
let taskInList = findTask(title: taskTitle)
|
||||
XCTAssertTrue(taskInList.waitForExistence(timeout: 10), "Task should appear in list")
|
||||
}
|
||||
|
||||
func testCreateTaskWithAllFields() {
|
||||
let timestamp = Int(Date().timeIntervalSince1970)
|
||||
let taskTitle = "Complete Task \(timestamp)"
|
||||
let description = "This is a comprehensive test task with all fields populated including a very detailed description."
|
||||
|
||||
let success = createTask(title: taskTitle, description: description)
|
||||
XCTAssertTrue(success, "Should successfully create task with all fields")
|
||||
|
||||
let taskInList = findTask(title: taskTitle)
|
||||
XCTAssertTrue(taskInList.waitForExistence(timeout: 10), "Complete task should appear in list")
|
||||
}
|
||||
|
||||
func testCreateMultipleTasksInSequence() {
|
||||
let timestamp = Int(Date().timeIntervalSince1970)
|
||||
|
||||
for i in 1...3 {
|
||||
let taskTitle = "Sequential Task \(i) - \(timestamp)"
|
||||
let success = createTask(title: taskTitle)
|
||||
XCTAssertTrue(success, "Should create task \(i)")
|
||||
|
||||
navigateToTasksTab()
|
||||
sleep(2)
|
||||
}
|
||||
|
||||
// Verify all tasks exist
|
||||
for i in 1...3 {
|
||||
let taskTitle = "Sequential Task \(i) - \(timestamp)"
|
||||
let task = findTask(title: taskTitle)
|
||||
XCTAssertTrue(task.exists, "Task \(i) should exist in list")
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Task Editing Tests
|
||||
|
||||
func testEditTaskTitle() {
|
||||
let timestamp = Int(Date().timeIntervalSince1970)
|
||||
let originalTitle = "Original Title \(timestamp)"
|
||||
let newTitle = "Edited Title \(timestamp)"
|
||||
|
||||
// Create task
|
||||
guard createTask(title: originalTitle) else {
|
||||
XCTFail("Failed to create task")
|
||||
return
|
||||
}
|
||||
|
||||
navigateToTasksTab()
|
||||
sleep(2)
|
||||
|
||||
// Find and tap task
|
||||
let task = findTask(title: originalTitle)
|
||||
XCTAssertTrue(task.waitForExistence(timeout: 5), "Task should exist")
|
||||
task.tap()
|
||||
sleep(2)
|
||||
|
||||
// Tap edit button
|
||||
let editButton = app.buttons.containing(NSPredicate(format: "label CONTAINS[c] 'Edit'")).firstMatch
|
||||
if editButton.exists {
|
||||
editButton.tap()
|
||||
sleep(2)
|
||||
|
||||
// Edit title
|
||||
let titleField = app.textFields.containing(NSPredicate(format: "placeholderValue CONTAINS[c] 'Title'")).firstMatch
|
||||
if titleField.exists {
|
||||
titleField.tap()
|
||||
// Clear existing text
|
||||
titleField.doubleTap()
|
||||
sleep(1)
|
||||
app.buttons["Select All"].tap()
|
||||
sleep(1)
|
||||
titleField.typeText(newTitle)
|
||||
|
||||
// Save
|
||||
let saveButton = app.buttons.containing(NSPredicate(format: "label CONTAINS[c] 'Save'")).firstMatch
|
||||
if saveButton.exists {
|
||||
saveButton.tap()
|
||||
sleep(3)
|
||||
|
||||
// Track new title
|
||||
createdTaskTitles.append(newTitle)
|
||||
|
||||
// Verify new title appears
|
||||
navigateToTasksTab()
|
||||
sleep(2)
|
||||
let updatedTask = findTask(title: newTitle)
|
||||
XCTAssertTrue(updatedTask.exists, "Task should show updated title")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func testUpdateAllTaskFields() {
|
||||
let timestamp = Int(Date().timeIntervalSince1970)
|
||||
let originalTitle = "Update All Fields \(timestamp)"
|
||||
let newTitle = "All Fields Updated \(timestamp)"
|
||||
let newDescription = "This task has been fully updated with all new values including description, category, priority, and status."
|
||||
|
||||
// Create task with initial values
|
||||
guard createTask(title: originalTitle, description: "Original description") else {
|
||||
XCTFail("Failed to create task")
|
||||
return
|
||||
}
|
||||
|
||||
navigateToTasksTab()
|
||||
sleep(2)
|
||||
|
||||
// Find and tap task
|
||||
let task = findTask(title: originalTitle)
|
||||
XCTAssertTrue(task.waitForExistence(timeout: 5), "Task should exist")
|
||||
task.tap()
|
||||
sleep(2)
|
||||
|
||||
// Tap edit button
|
||||
let editButton = app.staticTexts.matching(identifier: "Actions").element(boundBy: 0).firstMatch
|
||||
XCTAssertTrue(editButton.exists, "Edit button should exist")
|
||||
editButton.tap()
|
||||
app/*@START_MENU_TOKEN@*/.buttons["pencil"]/*[[".buttons.containing(.image, identifier: \"pencil\")",".cells",".buttons[\"Edit Task\"]",".buttons[\"pencil\"]"],[[[-1,3],[-1,2],[-1,1,1],[-1,0]],[[-1,3],[-1,2]]],[0]]@END_MENU_TOKEN@*/.firstMatch.tap()
|
||||
sleep(2)
|
||||
|
||||
// Update title
|
||||
let titleField = app.textFields.containing(NSPredicate(format: "placeholderValue CONTAINS[c] 'Title'")).firstMatch
|
||||
XCTAssertTrue(titleField.exists, "Title field should exist")
|
||||
titleField.tap()
|
||||
sleep(1)
|
||||
titleField.tap()
|
||||
sleep(1)
|
||||
app.menuItems["Select All"].tap()
|
||||
sleep(1)
|
||||
titleField.typeText(newTitle)
|
||||
|
||||
// Scroll to description
|
||||
app.swipeUp()
|
||||
sleep(1)
|
||||
|
||||
// Update description
|
||||
let descField = app.textViews.containing(NSPredicate(format: "placeholderValue CONTAINS[c] 'Description'")).firstMatch
|
||||
if descField.exists {
|
||||
descField.tap()
|
||||
sleep(1)
|
||||
// Clear existing text
|
||||
descField.doubleTap()
|
||||
sleep(1)
|
||||
if app.buttons["Select All"].exists {
|
||||
app.buttons["Select All"].tap()
|
||||
sleep(1)
|
||||
}
|
||||
descField.typeText(newDescription)
|
||||
}
|
||||
|
||||
// Update category (if picker exists)
|
||||
let categoryPicker = app.buttons.containing(NSPredicate(format: "label CONTAINS[c] 'Category'")).firstMatch
|
||||
if categoryPicker.exists {
|
||||
categoryPicker.tap()
|
||||
sleep(1)
|
||||
// Select a different category
|
||||
let electricalOption = app.buttons["Electrical"]
|
||||
if electricalOption.exists {
|
||||
electricalOption.tap()
|
||||
sleep(1)
|
||||
}
|
||||
}
|
||||
|
||||
// Scroll to more fields
|
||||
app.swipeUp()
|
||||
sleep(1)
|
||||
|
||||
// Update priority (if picker exists)
|
||||
let priorityPicker = app.buttons.containing(NSPredicate(format: "label CONTAINS[c] 'Priority'")).firstMatch
|
||||
if priorityPicker.exists {
|
||||
priorityPicker.tap()
|
||||
sleep(1)
|
||||
// Select high priority
|
||||
let highOption = app.buttons["High"]
|
||||
if highOption.exists {
|
||||
highOption.tap()
|
||||
sleep(1)
|
||||
}
|
||||
}
|
||||
|
||||
// Update status (if picker exists)
|
||||
let statusPicker = app.buttons.containing(NSPredicate(format: "label CONTAINS[c] 'Status'")).firstMatch
|
||||
if statusPicker.exists {
|
||||
statusPicker.tap()
|
||||
sleep(1)
|
||||
// Select in progress status
|
||||
let inProgressOption = app.buttons.containing(NSPredicate(format: "label CONTAINS[c] 'In Progress' OR label CONTAINS[c] 'InProgress'")).firstMatch
|
||||
if inProgressOption.exists {
|
||||
inProgressOption.tap()
|
||||
sleep(1)
|
||||
}
|
||||
}
|
||||
|
||||
// Scroll to save button
|
||||
app.swipeUp()
|
||||
sleep(1)
|
||||
|
||||
// Save
|
||||
let saveButton = app.buttons.containing(NSPredicate(format: "label CONTAINS[c] 'Save'")).firstMatch
|
||||
XCTAssertTrue(saveButton.exists, "Save button should exist")
|
||||
saveButton.tap()
|
||||
sleep(4)
|
||||
|
||||
// Track new title
|
||||
createdTaskTitles.append(newTitle)
|
||||
|
||||
// Verify updated task appears in list with new title
|
||||
navigateToTasksTab()
|
||||
sleep(2)
|
||||
let updatedTask = findTask(title: newTitle)
|
||||
XCTAssertTrue(updatedTask.exists, "Task should show updated title in list")
|
||||
|
||||
// Tap on task to verify details were updated
|
||||
updatedTask.tap()
|
||||
sleep(2)
|
||||
|
||||
// // Verify updated description appears in detail view
|
||||
// let descriptionText = app.staticTexts.containing(NSPredicate(format: "label CONTAINS 'fully updated'")).firstMatch
|
||||
// XCTAssertTrue(descriptionText.exists, "Updated description should be visible in detail view")
|
||||
//
|
||||
// // Verify updated category (Electrical) appears
|
||||
// let electricalBadge = app.staticTexts.containing(NSPredicate(format: "label CONTAINS 'Electrical'")).firstMatch
|
||||
// XCTAssertTrue(electricalBadge.exists || true, "Updated category should be visible (if category is shown in detail)")
|
||||
|
||||
// Verify updated priority (High) appears
|
||||
let highPriorityBadge = app.staticTexts.containing(NSPredicate(format: "label CONTAINS[c] 'High'")).firstMatch
|
||||
XCTAssertTrue(highPriorityBadge.exists || true, "Updated priority should be visible (if priority is shown in detail)")
|
||||
}
|
||||
|
||||
// MARK: - Validation & Error Handling Tests
|
||||
|
||||
func testCannotCreateTaskWithEmptyTitle() {
|
||||
guard openTaskForm() else {
|
||||
XCTFail("Failed to open task form")
|
||||
return
|
||||
}
|
||||
|
||||
// Leave title empty but fill other required fields
|
||||
// Select category
|
||||
let categoryPicker = app.buttons.containing(NSPredicate(format: "label CONTAINS[c] 'Category'")).firstMatch
|
||||
if categoryPicker.exists {
|
||||
app.staticTexts["Appliances"].firstMatch.tap()
|
||||
app.buttons["Plumbing"].firstMatch.tap()
|
||||
}
|
||||
|
||||
// Select frequency
|
||||
let frequencyPicker = app.buttons.containing(NSPredicate(format: "label CONTAINS[c] 'Frequency'")).firstMatch
|
||||
if frequencyPicker.exists {
|
||||
app/*@START_MENU_TOKEN@*/.staticTexts["Annually"]/*[[".buttons[\"Frequency, Annually\"].staticTexts",".buttons.staticTexts[\"Annually\"]",".staticTexts[\"Annually\"]"],[[[-1,2],[-1,1],[-1,0]]],[0]]@END_MENU_TOKEN@*/.firstMatch.tap()
|
||||
app/*@START_MENU_TOKEN@*/.buttons["Once"]/*[[".cells.buttons[\"Once\"]",".buttons[\"Once\"]"],[[[-1,1],[-1,0]]],[0]]@END_MENU_TOKEN@*/.firstMatch.tap()
|
||||
}
|
||||
|
||||
// Select priority
|
||||
let priorityPicker = app.buttons.containing(NSPredicate(format: "label CONTAINS[c] 'Priority'")).firstMatch
|
||||
if priorityPicker.exists {
|
||||
app.staticTexts["High"].firstMatch.tap()
|
||||
app.buttons["Low"].firstMatch.tap()
|
||||
}
|
||||
|
||||
// Select status
|
||||
let statusPicker = app.buttons.containing(NSPredicate(format: "label CONTAINS[c] 'Status'")).firstMatch
|
||||
if statusPicker.exists {
|
||||
app.staticTexts["Pending"].firstMatch.tap()
|
||||
app.buttons["Pending"].firstMatch.tap()
|
||||
}
|
||||
|
||||
// Scroll to save button
|
||||
app.swipeUp()
|
||||
sleep(1)
|
||||
|
||||
// Save button should be disabled when title is empty
|
||||
let saveButton = app.buttons.containing(NSPredicate(format: "label CONTAINS[c] 'Save'")).firstMatch
|
||||
XCTAssertTrue(saveButton.exists, "Save button should exist")
|
||||
XCTAssertFalse(saveButton.isEnabled, "Save button should be disabled when title is empty")
|
||||
}
|
||||
|
||||
func testCancelTaskCreation() {
|
||||
guard openTaskForm() else {
|
||||
XCTFail("Failed to open task form")
|
||||
return
|
||||
}
|
||||
|
||||
// Fill some data
|
||||
let titleField = app.textFields.containing(NSPredicate(format: "placeholderValue CONTAINS[c] 'Title'")).firstMatch
|
||||
titleField.tap()
|
||||
titleField.typeText("This will be canceled")
|
||||
|
||||
// Tap cancel
|
||||
let cancelButton = app.buttons.containing(NSPredicate(format: "label CONTAINS[c] 'Cancel'")).firstMatch
|
||||
XCTAssertTrue(cancelButton.exists, "Cancel button should exist")
|
||||
cancelButton.tap()
|
||||
sleep(2)
|
||||
|
||||
// Should be back on tasks list
|
||||
let tasksTab = app.tabBars.buttons.containing(NSPredicate(format: "label CONTAINS[c] 'Tasks'")).firstMatch
|
||||
XCTAssertTrue(tasksTab.exists, "Should be back on tasks list")
|
||||
|
||||
// Task should not exist
|
||||
let task = findTask(title: "This will be canceled")
|
||||
XCTAssertFalse(task.exists, "Canceled task should not exist")
|
||||
}
|
||||
|
||||
// MARK: - Edge Case Tests
|
||||
|
||||
func testCreateTaskWithVeryLongTitle() {
|
||||
let timestamp = Int(Date().timeIntervalSince1970)
|
||||
let longTitle = "This is an extremely long task title that goes on and on and on to test how the system handles very long text input in the title field \(timestamp)"
|
||||
|
||||
let success = createTask(title: longTitle)
|
||||
XCTAssertTrue(success, "Should handle very long titles")
|
||||
|
||||
// Verify it appears (may be truncated in display)
|
||||
let task = app.staticTexts.containing(NSPredicate(format: "label CONTAINS 'extremely long task title'")).firstMatch
|
||||
XCTAssertTrue(task.waitForExistence(timeout: 10), "Long title task should exist")
|
||||
}
|
||||
|
||||
func testCreateTaskWithSpecialCharacters() {
|
||||
let timestamp = Int(Date().timeIntervalSince1970)
|
||||
let specialTitle = "Special !@#$%^&*() Task \(timestamp)"
|
||||
|
||||
let success = createTask(title: specialTitle)
|
||||
XCTAssertTrue(success, "Should handle special characters")
|
||||
|
||||
let task = findTask(title: "Special")
|
||||
XCTAssertTrue(task.waitForExistence(timeout: 10), "Task with special chars should exist")
|
||||
}
|
||||
|
||||
func testCreateTaskWithEmojis() {
|
||||
let timestamp = Int(Date().timeIntervalSince1970)
|
||||
let emojiTitle = "Fix Plumbing 🔧💧 Task \(timestamp)"
|
||||
|
||||
let success = createTask(title: emojiTitle)
|
||||
XCTAssertTrue(success, "Should handle emojis")
|
||||
|
||||
let task = findTask(title: "Fix Plumbing")
|
||||
XCTAssertTrue(task.waitForExistence(timeout: 10), "Task with emojis should exist")
|
||||
}
|
||||
|
||||
// MARK: - Task List & Navigation Tests
|
||||
|
||||
func testNavigateFromTasksToOtherTabs() {
|
||||
// From Tasks tab
|
||||
navigateToTasksTab()
|
||||
|
||||
// Navigate to Residences
|
||||
let residencesTab = app.tabBars.buttons.containing(NSPredicate(format: "label CONTAINS[c] 'Residences'")).firstMatch
|
||||
XCTAssertTrue(residencesTab.exists, "Residences tab should exist")
|
||||
residencesTab.tap()
|
||||
sleep(1)
|
||||
XCTAssertTrue(residencesTab.isSelected, "Should be on Residences tab")
|
||||
|
||||
// Navigate back to Tasks
|
||||
let tasksTab = app.tabBars.buttons.containing(NSPredicate(format: "label CONTAINS[c] 'Tasks'")).firstMatch
|
||||
tasksTab.tap()
|
||||
sleep(1)
|
||||
XCTAssertTrue(tasksTab.isSelected, "Should be back on Tasks tab")
|
||||
|
||||
// Navigate to Contractors
|
||||
let contractorsTab = app.tabBars.buttons.containing(NSPredicate(format: "label CONTAINS[c] 'Contractors'")).firstMatch
|
||||
XCTAssertTrue(contractorsTab.exists, "Contractors tab should exist")
|
||||
contractorsTab.tap()
|
||||
sleep(1)
|
||||
XCTAssertTrue(contractorsTab.isSelected, "Should be on Contractors tab")
|
||||
|
||||
// Back to Tasks
|
||||
tasksTab.tap()
|
||||
sleep(1)
|
||||
XCTAssertTrue(tasksTab.isSelected, "Should be back on Tasks tab again")
|
||||
}
|
||||
|
||||
func testRefreshTasksList() {
|
||||
navigateToTasksTab()
|
||||
sleep(2)
|
||||
|
||||
// Pull to refresh (if implemented) or use refresh button
|
||||
let refreshButton = app.navigationBars.buttons.containing(NSPredicate(format: "label CONTAINS 'arrow.clockwise' OR label CONTAINS 'refresh'")).firstMatch
|
||||
if refreshButton.exists {
|
||||
refreshButton.tap()
|
||||
sleep(3)
|
||||
}
|
||||
|
||||
// Verify we're still on tasks tab
|
||||
let tasksTab = app.tabBars.buttons.containing(NSPredicate(format: "label CONTAINS[c] 'Tasks'")).firstMatch
|
||||
XCTAssertTrue(tasksTab.isSelected, "Should still be on Tasks tab after refresh")
|
||||
}
|
||||
|
||||
// MARK: - Data Persistence Tests
|
||||
|
||||
func testTaskPersistsAfterBackgroundingApp() {
|
||||
let timestamp = Int(Date().timeIntervalSince1970)
|
||||
let taskTitle = "Persistence Test \(timestamp)"
|
||||
|
||||
// Create task
|
||||
guard createTask(title: taskTitle) else {
|
||||
XCTFail("Failed to create task")
|
||||
return
|
||||
}
|
||||
|
||||
navigateToTasksTab()
|
||||
sleep(2)
|
||||
|
||||
// Verify task exists
|
||||
var task = findTask(title: taskTitle)
|
||||
XCTAssertTrue(task.exists, "Task should exist before backgrounding")
|
||||
|
||||
// Background and reactivate app
|
||||
XCUIDevice.shared.press(.home)
|
||||
sleep(2)
|
||||
app.activate()
|
||||
sleep(3)
|
||||
|
||||
// Navigate back to tasks
|
||||
navigateToTasksTab()
|
||||
sleep(2)
|
||||
|
||||
// Verify task still exists
|
||||
task = findTask(title: taskTitle)
|
||||
XCTAssertTrue(task.exists, "Task should persist after backgrounding app")
|
||||
}
|
||||
|
||||
// MARK: - Performance Tests
|
||||
|
||||
func testTaskListPerformance() {
|
||||
measure(metrics: [XCTClockMetric(), XCTMemoryMetric()]) {
|
||||
navigateToTasksTab()
|
||||
sleep(2)
|
||||
}
|
||||
}
|
||||
|
||||
func testTaskCreationPerformance() {
|
||||
let timestamp = Int(Date().timeIntervalSince1970)
|
||||
|
||||
measure(metrics: [XCTClockMetric()]) {
|
||||
let taskTitle = "Performance Test \(timestamp)_\(UUID().uuidString.prefix(8))"
|
||||
_ = createTask(title: taskTitle)
|
||||
}
|
||||
}
|
||||
}
|
||||
41
iosApp/CaseraUITests/MyCribUITests.swift
Normal file
41
iosApp/CaseraUITests/MyCribUITests.swift
Normal file
@@ -0,0 +1,41 @@
|
||||
//
|
||||
// CaseraUITests.swift
|
||||
// CaseraUITests
|
||||
//
|
||||
// Created by Trey Tartt on 11/19/25.
|
||||
//
|
||||
|
||||
import XCTest
|
||||
|
||||
final class CaseraUITests: XCTestCase {
|
||||
|
||||
override func setUpWithError() throws {
|
||||
// Put setup code here. This method is called before the invocation of each test method in the class.
|
||||
|
||||
// In UI tests it is usually best to stop immediately when a failure occurs.
|
||||
continueAfterFailure = false
|
||||
|
||||
// In UI tests it's important to set the initial state - such as interface orientation - required for your tests before they run. The setUp method is a good place to do this.
|
||||
}
|
||||
|
||||
override func tearDownWithError() throws {
|
||||
// Put teardown code here. This method is called after the invocation of each test method in the class.
|
||||
}
|
||||
|
||||
@MainActor
|
||||
func testExample() throws {
|
||||
// UI tests must launch the application that they test.
|
||||
let app = XCUIApplication()
|
||||
app.launch()
|
||||
|
||||
// Use XCTAssert and related functions to verify your tests produce the correct results.
|
||||
}
|
||||
|
||||
@MainActor
|
||||
func testLaunchPerformance() throws {
|
||||
// This measures how long it takes to launch your application.
|
||||
measure(metrics: [XCTApplicationLaunchMetric()]) {
|
||||
XCUIApplication().launch()
|
||||
}
|
||||
}
|
||||
}
|
||||
33
iosApp/CaseraUITests/MyCribUITestsLaunchTests.swift
Normal file
33
iosApp/CaseraUITests/MyCribUITestsLaunchTests.swift
Normal file
@@ -0,0 +1,33 @@
|
||||
//
|
||||
// CaseraUITestsLaunchTests.swift
|
||||
// CaseraUITests
|
||||
//
|
||||
// Created by Trey Tartt on 11/19/25.
|
||||
//
|
||||
|
||||
import XCTest
|
||||
|
||||
final class CaseraUITestsLaunchTests: XCTestCase {
|
||||
|
||||
override class var runsForEachTargetApplicationUIConfiguration: Bool {
|
||||
true
|
||||
}
|
||||
|
||||
override func setUpWithError() throws {
|
||||
continueAfterFailure = false
|
||||
}
|
||||
|
||||
@MainActor
|
||||
func testLaunch() throws {
|
||||
let app = XCUIApplication()
|
||||
app.launch()
|
||||
|
||||
// Insert steps here to perform after app launch but before taking a screenshot,
|
||||
// such as logging into a test account or navigating somewhere in the app
|
||||
|
||||
let attachment = XCTAttachment(screenshot: app.screenshot())
|
||||
attachment.name = "Launch Screen"
|
||||
attachment.lifetime = .keepAlways
|
||||
add(attachment)
|
||||
}
|
||||
}
|
||||
600
iosApp/CaseraUITests/RegistrationTests.swift
Normal file
600
iosApp/CaseraUITests/RegistrationTests.swift
Normal file
@@ -0,0 +1,600 @@
|
||||
import XCTest
|
||||
#if os(macOS)
|
||||
import Foundation
|
||||
#endif
|
||||
|
||||
/// Comprehensive registration flow tests
|
||||
/// Tests the complete registration and email verification flow
|
||||
///
|
||||
/// NOTE: Tests that require database access (fetchVerificationCode, cleanupTestUser)
|
||||
/// use shell scripts that run on the host machine. These tests are designed to run
|
||||
/// in the iOS Simulator with the backend running locally.
|
||||
final class RegistrationTests: XCTestCase {
|
||||
var app: XCUIApplication!
|
||||
|
||||
// Test user credentials - using timestamp to ensure unique users
|
||||
private var testUsername: String {
|
||||
return "testuser_\(Int(Date().timeIntervalSince1970))"
|
||||
}
|
||||
private var testEmail: String {
|
||||
return "test_\(Int(Date().timeIntervalSince1970))@example.com"
|
||||
}
|
||||
private let testPassword = "TestPass123!"
|
||||
|
||||
override func setUpWithError() throws {
|
||||
continueAfterFailure = false
|
||||
app = XCUIApplication()
|
||||
app.launch()
|
||||
ensureLoggedOut()
|
||||
}
|
||||
|
||||
override func tearDownWithError() throws {
|
||||
// Clean up: logout if logged in
|
||||
ensureLoggedOut()
|
||||
app = nil
|
||||
}
|
||||
|
||||
// MARK: - Helper Methods
|
||||
|
||||
private func ensureLoggedOut() {
|
||||
UITestHelpers.ensureLoggedOut(app: app)
|
||||
}
|
||||
|
||||
private func navigateToRegistration() {
|
||||
let signUpButton = app.buttons.containing(NSPredicate(format: "label CONTAINS[c] 'Sign Up'")).firstMatch
|
||||
XCTAssertTrue(signUpButton.waitForExistence(timeout: 5), "Sign Up button should exist on login screen")
|
||||
signUpButton.tap()
|
||||
sleep(1)
|
||||
}
|
||||
|
||||
/// Dismisses the iOS Strong Password suggestion overlay if it appears
|
||||
private func dismissStrongPasswordSuggestion() {
|
||||
// Look for "Choose My Own Password" or similar button in the password suggestion
|
||||
let chooseOwnPassword = app.buttons["Choose My Own Password"]
|
||||
if chooseOwnPassword.waitForExistence(timeout: 2) {
|
||||
chooseOwnPassword.tap()
|
||||
sleep(1)
|
||||
return
|
||||
}
|
||||
|
||||
// Try alternate labels
|
||||
let notNowButton = app.buttons["Not Now"]
|
||||
if notNowButton.exists {
|
||||
notNowButton.tap()
|
||||
sleep(1)
|
||||
return
|
||||
}
|
||||
|
||||
// Try tapping outside the suggestion to dismiss it
|
||||
let strongPasswordText = app.staticTexts.containing(NSPredicate(format: "label CONTAINS[c] 'Strong Password'")).firstMatch
|
||||
if strongPasswordText.exists {
|
||||
// Tap somewhere else to dismiss
|
||||
app.tap()
|
||||
sleep(1)
|
||||
}
|
||||
}
|
||||
|
||||
/// Fixed test verification code - Django uses this code for emails starting with "test_" in DEBUG mode
|
||||
/// This matches ConfirmationCode.TEST_VERIFICATION_CODE in the Django backend
|
||||
private let testVerificationCode = "123456"
|
||||
|
||||
/// Note: cleanupTestUser should be called from command line after tests complete
|
||||
/// Run: cd /Users/treyt/Desktop/code/Casera/myCribAPI && python manage.py shell -c "from django.contrib.auth import get_user_model; User = get_user_model(); User.objects.filter(email__startswith='test_').delete()"
|
||||
private func cleanupTestUser(email: String) {
|
||||
print("Cleanup test user: \(email)")
|
||||
print("Run manually if needed: cd /Users/treyt/Desktop/code/Casera/myCribAPI && python manage.py shell -c \"from django.contrib.auth import get_user_model; User = get_user_model(); User.objects.filter(email='\(email)').delete()\"")
|
||||
}
|
||||
|
||||
// MARK: - Registration Form Tests
|
||||
|
||||
func testRegistrationScreenElements() {
|
||||
// Given: User is on login screen
|
||||
navigateToRegistration()
|
||||
|
||||
// Then: Registration form should have all expected elements
|
||||
let usernameField = app.textFields[AccessibilityIdentifiers.Authentication.registerUsernameField]
|
||||
let emailField = app.textFields[AccessibilityIdentifiers.Authentication.registerEmailField]
|
||||
let passwordField = app.secureTextFields[AccessibilityIdentifiers.Authentication.registerPasswordField]
|
||||
let confirmPasswordField = app.secureTextFields[AccessibilityIdentifiers.Authentication.registerConfirmPasswordField]
|
||||
let createAccountButton = app.buttons[AccessibilityIdentifiers.Authentication.registerButton]
|
||||
let cancelButton = app.buttons[AccessibilityIdentifiers.Authentication.registerCancelButton]
|
||||
|
||||
XCTAssertTrue(usernameField.waitForExistence(timeout: 5), "Username field should exist")
|
||||
XCTAssertTrue(emailField.exists, "Email field should exist")
|
||||
XCTAssertTrue(passwordField.exists, "Password field should exist")
|
||||
XCTAssertTrue(confirmPasswordField.exists, "Confirm password field should exist")
|
||||
XCTAssertTrue(createAccountButton.exists, "Create Account button should exist")
|
||||
XCTAssertTrue(cancelButton.exists, "Cancel button should exist")
|
||||
}
|
||||
|
||||
func testRegistrationWithEmptyFields() {
|
||||
// Given: User is on registration screen
|
||||
navigateToRegistration()
|
||||
|
||||
// When: User taps Create Account without filling fields
|
||||
let createAccountButton = app.buttons[AccessibilityIdentifiers.Authentication.registerButton]
|
||||
XCTAssertTrue(createAccountButton.waitForExistence(timeout: 5))
|
||||
createAccountButton.tap()
|
||||
|
||||
// Then: Error message should appear
|
||||
sleep(2)
|
||||
let errorExists = app.staticTexts.containing(NSPredicate(format: "label CONTAINS[c] 'required' OR label CONTAINS[c] 'error' OR label CONTAINS[c] 'invalid'")).firstMatch.waitForExistence(timeout: 3)
|
||||
XCTAssertTrue(errorExists, "Error message should appear for empty fields")
|
||||
}
|
||||
|
||||
func testRegistrationWithInvalidEmail() {
|
||||
// Given: User is on registration screen
|
||||
navigateToRegistration()
|
||||
|
||||
// When: User fills form with invalid email
|
||||
let usernameField = app.textFields[AccessibilityIdentifiers.Authentication.registerUsernameField]
|
||||
let emailField = app.textFields[AccessibilityIdentifiers.Authentication.registerEmailField]
|
||||
let passwordField = app.secureTextFields[AccessibilityIdentifiers.Authentication.registerPasswordField]
|
||||
let confirmPasswordField = app.secureTextFields[AccessibilityIdentifiers.Authentication.registerConfirmPasswordField]
|
||||
|
||||
XCTAssertTrue(usernameField.waitForExistence(timeout: 5))
|
||||
|
||||
usernameField.tap()
|
||||
usernameField.typeText("testuser")
|
||||
|
||||
emailField.tap()
|
||||
emailField.typeText("invalid-email") // Invalid email format
|
||||
|
||||
passwordField.tap()
|
||||
passwordField.typeText(testPassword)
|
||||
|
||||
confirmPasswordField.tap()
|
||||
confirmPasswordField.typeText(testPassword)
|
||||
|
||||
let createAccountButton = app.buttons[AccessibilityIdentifiers.Authentication.registerButton]
|
||||
createAccountButton.tap()
|
||||
|
||||
// Then: Error message for invalid email should appear
|
||||
sleep(2)
|
||||
let errorExists = app.staticTexts.containing(NSPredicate(format: "label CONTAINS[c] 'email' OR label CONTAINS[c] 'invalid'")).firstMatch.waitForExistence(timeout: 3)
|
||||
XCTAssertTrue(errorExists, "Error message should appear for invalid email")
|
||||
}
|
||||
|
||||
func testRegistrationWithMismatchedPasswords() {
|
||||
// Given: User is on registration screen
|
||||
navigateToRegistration()
|
||||
|
||||
// When: User fills form with mismatched passwords
|
||||
let usernameField = app.textFields[AccessibilityIdentifiers.Authentication.registerUsernameField]
|
||||
let emailField = app.textFields[AccessibilityIdentifiers.Authentication.registerEmailField]
|
||||
let passwordField = app.secureTextFields[AccessibilityIdentifiers.Authentication.registerPasswordField]
|
||||
let confirmPasswordField = app.secureTextFields[AccessibilityIdentifiers.Authentication.registerConfirmPasswordField]
|
||||
|
||||
XCTAssertTrue(usernameField.waitForExistence(timeout: 5))
|
||||
|
||||
usernameField.tap()
|
||||
usernameField.typeText("testuser")
|
||||
|
||||
emailField.tap()
|
||||
emailField.typeText("test@example.com")
|
||||
|
||||
passwordField.tap()
|
||||
passwordField.typeText("Password123!")
|
||||
|
||||
confirmPasswordField.tap()
|
||||
confirmPasswordField.typeText("DifferentPassword123!") // Mismatched password
|
||||
|
||||
let createAccountButton = app.buttons[AccessibilityIdentifiers.Authentication.registerButton]
|
||||
createAccountButton.tap()
|
||||
|
||||
// Then: Error message for mismatched passwords should appear
|
||||
sleep(2)
|
||||
let errorExists = app.staticTexts.containing(NSPredicate(format: "label CONTAINS[c] 'match' OR label CONTAINS[c] 'password'")).firstMatch.waitForExistence(timeout: 3)
|
||||
XCTAssertTrue(errorExists, "Error message should appear for mismatched passwords")
|
||||
}
|
||||
|
||||
func testRegistrationWithWeakPassword() {
|
||||
// Given: User is on registration screen
|
||||
navigateToRegistration()
|
||||
|
||||
// When: User fills form with weak password
|
||||
let usernameField = app.textFields[AccessibilityIdentifiers.Authentication.registerUsernameField]
|
||||
let emailField = app.textFields[AccessibilityIdentifiers.Authentication.registerEmailField]
|
||||
let passwordField = app.secureTextFields[AccessibilityIdentifiers.Authentication.registerPasswordField]
|
||||
let confirmPasswordField = app.secureTextFields[AccessibilityIdentifiers.Authentication.registerConfirmPasswordField]
|
||||
|
||||
XCTAssertTrue(usernameField.waitForExistence(timeout: 5))
|
||||
|
||||
usernameField.tap()
|
||||
usernameField.typeText("testuser")
|
||||
|
||||
emailField.tap()
|
||||
emailField.typeText("test@example.com")
|
||||
|
||||
passwordField.tap()
|
||||
passwordField.typeText("weak") // Too short/weak password
|
||||
|
||||
confirmPasswordField.tap()
|
||||
confirmPasswordField.typeText("weak")
|
||||
|
||||
let createAccountButton = app.buttons[AccessibilityIdentifiers.Authentication.registerButton]
|
||||
createAccountButton.tap()
|
||||
|
||||
// Then: Error message for weak password should appear
|
||||
sleep(2)
|
||||
let errorExists = app.staticTexts.containing(NSPredicate(format: "label CONTAINS[c] 'password' OR label CONTAINS[c] 'character' OR label CONTAINS[c] 'strong'")).firstMatch.waitForExistence(timeout: 3)
|
||||
XCTAssertTrue(errorExists, "Error message should appear for weak password")
|
||||
}
|
||||
|
||||
func testCancelRegistration() {
|
||||
// Given: User is on registration screen
|
||||
navigateToRegistration()
|
||||
|
||||
// When: User taps Cancel button
|
||||
let cancelButton = app.buttons[AccessibilityIdentifiers.Authentication.registerCancelButton]
|
||||
XCTAssertTrue(cancelButton.waitForExistence(timeout: 5))
|
||||
cancelButton.tap()
|
||||
|
||||
// Then: Should return to login screen
|
||||
sleep(1)
|
||||
let welcomeText = app.staticTexts["Welcome Back"]
|
||||
XCTAssertTrue(welcomeText.waitForExistence(timeout: 5), "Should return to login screen")
|
||||
}
|
||||
|
||||
// MARK: - Full Registration Flow Tests
|
||||
|
||||
func testSuccessfulRegistrationAndVerification() {
|
||||
// Use unique credentials for this test
|
||||
let username = testUsername
|
||||
let email = testEmail
|
||||
|
||||
// Given: User is on registration screen
|
||||
navigateToRegistration()
|
||||
|
||||
// When: User fills in valid registration details
|
||||
let usernameField = app.textFields[AccessibilityIdentifiers.Authentication.registerUsernameField]
|
||||
let emailField = app.textFields[AccessibilityIdentifiers.Authentication.registerEmailField]
|
||||
let passwordField = app.secureTextFields[AccessibilityIdentifiers.Authentication.registerPasswordField]
|
||||
let confirmPasswordField = app.secureTextFields[AccessibilityIdentifiers.Authentication.registerConfirmPasswordField]
|
||||
|
||||
XCTAssertTrue(usernameField.waitForExistence(timeout: 5))
|
||||
|
||||
usernameField.tap()
|
||||
usernameField.typeText(username)
|
||||
|
||||
emailField.tap()
|
||||
emailField.typeText(email)
|
||||
|
||||
// Handle strong password suggestion by dismissing it
|
||||
passwordField.tap()
|
||||
sleep(1)
|
||||
|
||||
// Dismiss the strong password suggestion if it appears
|
||||
dismissStrongPasswordSuggestion()
|
||||
|
||||
// Now type the password
|
||||
passwordField.tap()
|
||||
passwordField.typeText(testPassword)
|
||||
|
||||
confirmPasswordField.tap()
|
||||
sleep(1)
|
||||
dismissStrongPasswordSuggestion()
|
||||
confirmPasswordField.tap()
|
||||
confirmPasswordField.typeText(testPassword)
|
||||
|
||||
// Submit registration
|
||||
let createAccountButton = app.buttons[AccessibilityIdentifiers.Authentication.registerButton]
|
||||
createAccountButton.tap()
|
||||
|
||||
// Wait for verification screen to appear
|
||||
let verifyEmailTitle = app.staticTexts["Verify Your Email"]
|
||||
XCTAssertTrue(verifyEmailTitle.waitForExistence(timeout: 10), "Should navigate to email verification screen")
|
||||
|
||||
// Use the fixed test verification code
|
||||
// Django uses "123456" for emails starting with "test_" when DEBUG=True
|
||||
let verificationCode = testVerificationCode
|
||||
print("Using test verification code: \(verificationCode)")
|
||||
|
||||
// Enter the verification code
|
||||
let codeField = app.textFields[AccessibilityIdentifiers.Authentication.verificationCodeField]
|
||||
XCTAssertTrue(codeField.waitForExistence(timeout: 5), "Verification code field should exist")
|
||||
codeField.tap()
|
||||
codeField.typeText(verificationCode)
|
||||
|
||||
// Submit verification
|
||||
let verifyButton = app.buttons.containing(NSPredicate(format: "label CONTAINS[c] 'Verify'")).firstMatch
|
||||
XCTAssertTrue(verifyButton.exists, "Verify button should exist")
|
||||
verifyButton.tap()
|
||||
|
||||
// Then: Should navigate to main app screen (home/residences tab)
|
||||
let residencesTab = app.tabBars.buttons.containing(NSPredicate(format: "label CONTAINS[c] 'Residences'")).firstMatch
|
||||
XCTAssertTrue(residencesTab.waitForExistence(timeout: 10), "Should navigate to main app after successful verification")
|
||||
|
||||
// Verify we're on the home screen by checking for residences-related content
|
||||
let homeScreenVisible = residencesTab.isSelected || app.navigationBars.containing(NSPredicate(format: "identifier CONTAINS[c] 'Residences' OR identifier CONTAINS[c] 'Home' OR identifier CONTAINS[c] 'Properties'")).firstMatch.exists
|
||||
XCTAssertTrue(homeScreenVisible || residencesTab.exists, "Should be on home/residences screen after registration")
|
||||
|
||||
// Navigate to Profile tab and log out
|
||||
let profileTab = app.tabBars.buttons.containing(NSPredicate(format: "label CONTAINS[c] 'Profile'")).firstMatch
|
||||
XCTAssertTrue(profileTab.waitForExistence(timeout: 5), "Profile tab should exist")
|
||||
profileTab.tap()
|
||||
sleep(1)
|
||||
|
||||
// Tap logout button
|
||||
let logoutButton = app.buttons.containing(NSPredicate(format: "label CONTAINS[c] 'Logout' OR label CONTAINS[c] 'Log Out' OR label CONTAINS[c] 'Sign Out'")).firstMatch
|
||||
XCTAssertTrue(logoutButton.waitForExistence(timeout: 5), "Logout button should exist on profile screen")
|
||||
logoutButton.tap()
|
||||
sleep(1)
|
||||
|
||||
// Confirm logout in alert if present
|
||||
let alertLogoutButton = app.alerts.buttons["Log Out"]
|
||||
if alertLogoutButton.waitForExistence(timeout: 3) {
|
||||
alertLogoutButton.tap()
|
||||
sleep(1)
|
||||
}
|
||||
|
||||
// Verify we're back on login screen
|
||||
let welcomeText = app.staticTexts["Welcome Back"]
|
||||
XCTAssertTrue(welcomeText.waitForExistence(timeout: 5), "Should return to login screen after logout")
|
||||
|
||||
// Cleanup test user
|
||||
cleanupTestUser(email: email)
|
||||
}
|
||||
|
||||
func testRegistrationWithInvalidVerificationCode() {
|
||||
// Use unique credentials for this test
|
||||
let username = testUsername
|
||||
let email = testEmail
|
||||
|
||||
// Given: User is on registration screen
|
||||
navigateToRegistration()
|
||||
|
||||
// Register a new user
|
||||
let usernameField = app.textFields[AccessibilityIdentifiers.Authentication.registerUsernameField]
|
||||
let emailField = app.textFields[AccessibilityIdentifiers.Authentication.registerEmailField]
|
||||
let passwordField = app.secureTextFields[AccessibilityIdentifiers.Authentication.registerPasswordField]
|
||||
let confirmPasswordField = app.secureTextFields[AccessibilityIdentifiers.Authentication.registerConfirmPasswordField]
|
||||
|
||||
XCTAssertTrue(usernameField.waitForExistence(timeout: 5))
|
||||
|
||||
usernameField.tap()
|
||||
usernameField.typeText(username)
|
||||
|
||||
emailField.tap()
|
||||
emailField.typeText(email)
|
||||
|
||||
passwordField.tap()
|
||||
sleep(1)
|
||||
dismissStrongPasswordSuggestion()
|
||||
passwordField.tap()
|
||||
passwordField.typeText(testPassword)
|
||||
|
||||
confirmPasswordField.tap()
|
||||
sleep(1)
|
||||
dismissStrongPasswordSuggestion()
|
||||
confirmPasswordField.tap()
|
||||
confirmPasswordField.typeText(testPassword)
|
||||
|
||||
let createAccountButton = app.buttons[AccessibilityIdentifiers.Authentication.registerButton]
|
||||
createAccountButton.tap()
|
||||
|
||||
// Wait for verification screen
|
||||
let verifyEmailTitle = app.staticTexts["Verify Your Email"]
|
||||
XCTAssertTrue(verifyEmailTitle.waitForExistence(timeout: 10), "Should navigate to email verification screen")
|
||||
|
||||
// Enter an invalid verification code
|
||||
let codeField = app.textFields[AccessibilityIdentifiers.Authentication.verificationCodeField]
|
||||
XCTAssertTrue(codeField.waitForExistence(timeout: 5))
|
||||
codeField.tap()
|
||||
codeField.typeText("000000") // Invalid code
|
||||
|
||||
// Submit verification
|
||||
let verifyButton = app.buttons.containing(NSPredicate(format: "label CONTAINS[c] 'Verify'")).firstMatch
|
||||
verifyButton.tap()
|
||||
|
||||
// Then: Error message should appear
|
||||
sleep(3)
|
||||
let errorExists = app.staticTexts.containing(NSPredicate(format: "label CONTAINS[c] 'invalid' OR label CONTAINS[c] 'error' OR label CONTAINS[c] 'incorrect'")).firstMatch.waitForExistence(timeout: 5)
|
||||
XCTAssertTrue(errorExists, "Error message should appear for invalid verification code")
|
||||
|
||||
// Cleanup: Logout and delete test user
|
||||
let logoutButton = app.buttons.containing(NSPredicate(format: "label CONTAINS[c] 'Logout'")).firstMatch
|
||||
if logoutButton.exists {
|
||||
logoutButton.tap()
|
||||
sleep(2)
|
||||
}
|
||||
cleanupTestUser(email: email)
|
||||
}
|
||||
|
||||
func testLogoutFromVerificationScreen() {
|
||||
// Use unique credentials for this test
|
||||
let username = testUsername
|
||||
let email = testEmail
|
||||
|
||||
// Given: User is on registration screen
|
||||
navigateToRegistration()
|
||||
|
||||
// Register a new user
|
||||
let usernameField = app.textFields[AccessibilityIdentifiers.Authentication.registerUsernameField]
|
||||
let emailField = app.textFields[AccessibilityIdentifiers.Authentication.registerEmailField]
|
||||
let passwordField = app.secureTextFields[AccessibilityIdentifiers.Authentication.registerPasswordField]
|
||||
let confirmPasswordField = app.secureTextFields[AccessibilityIdentifiers.Authentication.registerConfirmPasswordField]
|
||||
|
||||
XCTAssertTrue(usernameField.waitForExistence(timeout: 5))
|
||||
|
||||
usernameField.tap()
|
||||
usernameField.typeText(username)
|
||||
|
||||
emailField.tap()
|
||||
emailField.typeText(email)
|
||||
|
||||
passwordField.tap()
|
||||
sleep(1)
|
||||
dismissStrongPasswordSuggestion()
|
||||
passwordField.tap()
|
||||
passwordField.typeText(testPassword)
|
||||
|
||||
confirmPasswordField.tap()
|
||||
sleep(1)
|
||||
dismissStrongPasswordSuggestion()
|
||||
confirmPasswordField.tap()
|
||||
confirmPasswordField.typeText(testPassword)
|
||||
|
||||
let createAccountButton = app.buttons[AccessibilityIdentifiers.Authentication.registerButton]
|
||||
createAccountButton.tap()
|
||||
|
||||
// Wait for verification screen
|
||||
let verifyEmailTitle = app.staticTexts["Verify Your Email"]
|
||||
XCTAssertTrue(verifyEmailTitle.waitForExistence(timeout: 10), "Should navigate to email verification screen")
|
||||
|
||||
// When: User taps Logout button
|
||||
let logoutButton = app.buttons.containing(NSPredicate(format: "label CONTAINS[c] 'Logout'")).firstMatch
|
||||
XCTAssertTrue(logoutButton.waitForExistence(timeout: 5), "Logout button should exist on verification screen")
|
||||
logoutButton.tap()
|
||||
|
||||
// Then: Should return to login screen
|
||||
sleep(2)
|
||||
let welcomeText = app.staticTexts["Welcome Back"]
|
||||
XCTAssertTrue(welcomeText.waitForExistence(timeout: 5), "Should return to login screen after logout")
|
||||
|
||||
// Cleanup
|
||||
cleanupTestUser(email: email)
|
||||
}
|
||||
|
||||
func testVerificationCodeFieldValidation() {
|
||||
// Use unique credentials for this test
|
||||
let username = testUsername
|
||||
let email = testEmail
|
||||
|
||||
// Given: User is on registration screen and registers
|
||||
navigateToRegistration()
|
||||
|
||||
let usernameField = app.textFields[AccessibilityIdentifiers.Authentication.registerUsernameField]
|
||||
let emailField = app.textFields[AccessibilityIdentifiers.Authentication.registerEmailField]
|
||||
let passwordField = app.secureTextFields[AccessibilityIdentifiers.Authentication.registerPasswordField]
|
||||
let confirmPasswordField = app.secureTextFields[AccessibilityIdentifiers.Authentication.registerConfirmPasswordField]
|
||||
|
||||
XCTAssertTrue(usernameField.waitForExistence(timeout: 5))
|
||||
|
||||
usernameField.tap()
|
||||
usernameField.typeText(username)
|
||||
|
||||
emailField.tap()
|
||||
emailField.typeText(email)
|
||||
|
||||
passwordField.tap()
|
||||
sleep(1)
|
||||
dismissStrongPasswordSuggestion()
|
||||
passwordField.tap()
|
||||
passwordField.typeText(testPassword)
|
||||
|
||||
confirmPasswordField.tap()
|
||||
sleep(1)
|
||||
dismissStrongPasswordSuggestion()
|
||||
confirmPasswordField.tap()
|
||||
confirmPasswordField.typeText(testPassword)
|
||||
|
||||
let createAccountButton = app.buttons[AccessibilityIdentifiers.Authentication.registerButton]
|
||||
createAccountButton.tap()
|
||||
|
||||
// Wait for verification screen
|
||||
let verifyEmailTitle = app.staticTexts["Verify Your Email"]
|
||||
XCTAssertTrue(verifyEmailTitle.waitForExistence(timeout: 10))
|
||||
|
||||
// When: User tries to verify with incomplete code
|
||||
let codeField = app.textFields[AccessibilityIdentifiers.Authentication.verificationCodeField]
|
||||
XCTAssertTrue(codeField.waitForExistence(timeout: 5))
|
||||
codeField.tap()
|
||||
codeField.typeText("123") // Only 3 digits
|
||||
|
||||
// Then: Verify button should be disabled or show error
|
||||
let verifyButton = app.buttons.containing(NSPredicate(format: "label CONTAINS[c] 'Verify'")).firstMatch
|
||||
XCTAssertTrue(verifyButton.exists)
|
||||
|
||||
// The button might be disabled or tapping it shows an error
|
||||
// Check that verification doesn't proceed with incomplete code
|
||||
verifyButton.tap()
|
||||
sleep(1)
|
||||
|
||||
// Should still be on verification screen
|
||||
XCTAssertTrue(verifyEmailTitle.exists, "Should still be on verification screen with incomplete code")
|
||||
|
||||
// Cleanup
|
||||
let logoutButton = app.buttons.containing(NSPredicate(format: "label CONTAINS[c] 'Logout'")).firstMatch
|
||||
if logoutButton.exists {
|
||||
logoutButton.tap()
|
||||
sleep(2)
|
||||
}
|
||||
cleanupTestUser(email: email)
|
||||
}
|
||||
|
||||
func testRegistrationWithExistingUsername() {
|
||||
// This test requires an existing user in the database
|
||||
// First, we need to ensure testuser exists
|
||||
|
||||
// Given: User is on registration screen
|
||||
navigateToRegistration()
|
||||
|
||||
// When: User tries to register with existing username
|
||||
let usernameField = app.textFields[AccessibilityIdentifiers.Authentication.registerUsernameField]
|
||||
let emailField = app.textFields[AccessibilityIdentifiers.Authentication.registerEmailField]
|
||||
let passwordField = app.secureTextFields[AccessibilityIdentifiers.Authentication.registerPasswordField]
|
||||
let confirmPasswordField = app.secureTextFields[AccessibilityIdentifiers.Authentication.registerConfirmPasswordField]
|
||||
|
||||
XCTAssertTrue(usernameField.waitForExistence(timeout: 5))
|
||||
|
||||
usernameField.tap()
|
||||
usernameField.typeText("testuser") // Assuming this user already exists
|
||||
|
||||
emailField.tap()
|
||||
emailField.typeText("newemail_\(Int(Date().timeIntervalSince1970))@example.com")
|
||||
|
||||
passwordField.tap()
|
||||
passwordField.typeText(testPassword)
|
||||
|
||||
confirmPasswordField.tap()
|
||||
confirmPasswordField.typeText(testPassword)
|
||||
|
||||
let createAccountButton = app.buttons[AccessibilityIdentifiers.Authentication.registerButton]
|
||||
createAccountButton.tap()
|
||||
|
||||
// Then: Error message for existing username should appear
|
||||
sleep(3)
|
||||
let errorExists = app.staticTexts.containing(NSPredicate(format: "label CONTAINS[c] 'exists' OR label CONTAINS[c] 'already' OR label CONTAINS[c] 'taken'")).firstMatch.waitForExistence(timeout: 5)
|
||||
XCTAssertTrue(errorExists, "Error message should appear for existing username")
|
||||
}
|
||||
|
||||
func testKeyboardNavigationDuringRegistration() {
|
||||
// Given: User is on registration screen
|
||||
navigateToRegistration()
|
||||
|
||||
// When: User navigates through fields using keyboard
|
||||
let usernameField = app.textFields[AccessibilityIdentifiers.Authentication.registerUsernameField]
|
||||
let emailField = app.textFields[AccessibilityIdentifiers.Authentication.registerEmailField]
|
||||
let passwordField = app.secureTextFields[AccessibilityIdentifiers.Authentication.registerPasswordField]
|
||||
|
||||
XCTAssertTrue(usernameField.waitForExistence(timeout: 5))
|
||||
|
||||
// Start with username field
|
||||
usernameField.tap()
|
||||
XCTAssertTrue(usernameField.hasKeyboardFocus, "Username field should have keyboard focus")
|
||||
|
||||
usernameField.typeText("testuser\n") // Press return to move to next field
|
||||
|
||||
sleep(1)
|
||||
|
||||
// Email field should now be focused (or at least exist)
|
||||
XCTAssertTrue(emailField.exists, "Email field should exist")
|
||||
|
||||
emailField.tap()
|
||||
emailField.typeText("test@example.com\n")
|
||||
|
||||
sleep(1)
|
||||
|
||||
// Password field should now be accessible
|
||||
XCTAssertTrue(passwordField.exists, "Password field should exist")
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - XCUIElement Extension for keyboard focus
|
||||
|
||||
extension XCUIElement {
|
||||
var hasKeyboardFocus: Bool {
|
||||
return (value(forKey: "hasKeyboardFocus") as? Bool) ?? false
|
||||
}
|
||||
}
|
||||
224
iosApp/CaseraUITests/ResidenceTests.swift
Normal file
224
iosApp/CaseraUITests/ResidenceTests.swift
Normal file
@@ -0,0 +1,224 @@
|
||||
import XCTest
|
||||
|
||||
/// Residence management tests
|
||||
/// Based on working SimpleLoginTest pattern
|
||||
final class ResidenceTests: XCTestCase {
|
||||
var app: XCUIApplication!
|
||||
|
||||
override func setUpWithError() throws {
|
||||
continueAfterFailure = false
|
||||
app = XCUIApplication()
|
||||
app.launch()
|
||||
ensureLoggedIn()
|
||||
}
|
||||
|
||||
override func tearDownWithError() throws {
|
||||
app = nil
|
||||
}
|
||||
|
||||
// MARK: - Helper Methods
|
||||
|
||||
private func ensureLoggedIn() {
|
||||
UITestHelpers.ensureLoggedIn(app: app)
|
||||
|
||||
// Navigate to Residences tab
|
||||
let residencesTab = app.tabBars.buttons.containing(NSPredicate(format: "label CONTAINS[c] 'Residences'")).firstMatch
|
||||
if residencesTab.exists {
|
||||
residencesTab.tap()
|
||||
sleep(1)
|
||||
}
|
||||
}
|
||||
|
||||
private func navigateToResidencesTab() {
|
||||
let residencesTab = app.tabBars.buttons.containing(NSPredicate(format: "label CONTAINS[c] 'Residences'")).firstMatch
|
||||
if !residencesTab.isSelected {
|
||||
residencesTab.tap()
|
||||
sleep(1)
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Tests
|
||||
|
||||
func testViewResidencesList() {
|
||||
// Given: User is logged in and on Residences tab
|
||||
navigateToResidencesTab()
|
||||
|
||||
// Then: Should see residences list header (must exist even if empty)
|
||||
let residencesHeader = app.staticTexts.containing(NSPredicate(format: "label CONTAINS[c] 'Your Properties' OR label CONTAINS[c] 'My Properties' OR label CONTAINS[c] 'Residences'")).firstMatch
|
||||
XCTAssertTrue(residencesHeader.waitForExistence(timeout: 5), "Residences list screen must be visible")
|
||||
|
||||
// Add button must exist
|
||||
let addButton = app.buttons[AccessibilityIdentifiers.Residence.addButton]
|
||||
XCTAssertTrue(addButton.exists, "Add residence button must exist")
|
||||
}
|
||||
|
||||
func testNavigateToAddResidence() {
|
||||
// Given: User is on Residences tab
|
||||
navigateToResidencesTab()
|
||||
|
||||
// When: User taps add residence button (using accessibility identifier to avoid wrong button)
|
||||
let addButton = app.buttons[AccessibilityIdentifiers.Residence.addButton]
|
||||
XCTAssertTrue(addButton.waitForExistence(timeout: 5), "Add residence button should exist")
|
||||
addButton.tap()
|
||||
|
||||
// Then: Should show add residence form with all required fields
|
||||
sleep(2)
|
||||
let nameField = app.textFields.containing(NSPredicate(format: "placeholderValue CONTAINS[c] 'Property Name' OR placeholderValue CONTAINS[c] 'Name'")).firstMatch
|
||||
XCTAssertTrue(nameField.exists, "Name field should exist in residence form")
|
||||
|
||||
// Verify property type picker exists
|
||||
let propertyTypePicker = app.buttons.containing(NSPredicate(format: "label CONTAINS[c] 'Property Type'")).firstMatch
|
||||
XCTAssertTrue(propertyTypePicker.exists, "Property type picker should exist in residence form")
|
||||
|
||||
let saveButton = app.buttons.containing(NSPredicate(format: "label CONTAINS[c] 'Save'")).firstMatch
|
||||
XCTAssertTrue(saveButton.exists, "Save button should exist in residence form")
|
||||
}
|
||||
|
||||
func testCreateResidenceWithMinimalData() {
|
||||
// Given: User is on add residence form
|
||||
navigateToResidencesTab()
|
||||
|
||||
// Use accessibility identifier to get the correct add button
|
||||
let addButton = app.buttons[AccessibilityIdentifiers.Residence.addButton]
|
||||
XCTAssertTrue(addButton.exists, "Add residence button should exist")
|
||||
addButton.tap()
|
||||
sleep(2)
|
||||
|
||||
// When: Verify form loaded correctly
|
||||
let nameField = app.textFields.containing(NSPredicate(format: "placeholderValue CONTAINS[c] 'Property Name' OR placeholderValue CONTAINS[c] 'Name'")).firstMatch
|
||||
XCTAssertTrue(nameField.waitForExistence(timeout: 5), "Name field should appear - form did not load correctly!")
|
||||
|
||||
// Fill name field
|
||||
let timestamp = Int(Date().timeIntervalSince1970)
|
||||
let residenceName = "UITest Home \(timestamp)"
|
||||
nameField.tap()
|
||||
nameField.typeText(residenceName)
|
||||
|
||||
// Select property type (required field)
|
||||
let propertyTypePicker = app.buttons.containing(NSPredicate(format: "label CONTAINS[c] 'Property Type'")).firstMatch
|
||||
if propertyTypePicker.exists {
|
||||
propertyTypePicker.tap()
|
||||
sleep(2)
|
||||
|
||||
// After tapping picker, look for any selectable option
|
||||
// Try common property types as buttons
|
||||
if app.buttons["House"].exists {
|
||||
app.buttons["House"].tap()
|
||||
} else if app.buttons["Apartment"].exists {
|
||||
app.buttons["Apartment"].tap()
|
||||
} else if app.buttons["Condo"].exists {
|
||||
app.buttons["Condo"].tap()
|
||||
} else {
|
||||
// If navigation style, try cells
|
||||
let cells = app.cells
|
||||
if cells.count > 1 {
|
||||
cells.element(boundBy: 1).tap() // Skip first which might be "Select Type"
|
||||
}
|
||||
}
|
||||
sleep(1)
|
||||
}
|
||||
|
||||
// Scroll down to see more fields
|
||||
app.swipeUp()
|
||||
sleep(1)
|
||||
|
||||
// Fill address fields - MUST exist for residence
|
||||
let streetField = app.textFields.containing(NSPredicate(format: "placeholderValue CONTAINS[c] 'Street'")).firstMatch
|
||||
XCTAssertTrue(streetField.exists, "Street field should exist in residence form")
|
||||
streetField.tap()
|
||||
streetField.typeText("123 Test St")
|
||||
|
||||
let cityField = app.textFields.containing(NSPredicate(format: "placeholderValue CONTAINS[c] 'City'")).firstMatch
|
||||
XCTAssertTrue(cityField.exists, "City field should exist in residence form")
|
||||
cityField.tap()
|
||||
cityField.typeText("TestCity")
|
||||
|
||||
let stateField = app.textFields.containing(NSPredicate(format: "placeholderValue CONTAINS[c] 'State'")).firstMatch
|
||||
XCTAssertTrue(stateField.exists, "State field should exist in residence form")
|
||||
stateField.tap()
|
||||
stateField.typeText("TS")
|
||||
|
||||
let postalField = app.textFields.containing(NSPredicate(format: "placeholderValue CONTAINS[c] 'Postal' OR placeholderValue CONTAINS[c] 'Zip'")).firstMatch
|
||||
XCTAssertTrue(postalField.exists, "Postal code field should exist in residence form")
|
||||
postalField.tap()
|
||||
postalField.typeText("12345")
|
||||
|
||||
// Save
|
||||
let saveButton = app.buttons.containing(NSPredicate(format: "label CONTAINS[c] 'Save'")).firstMatch
|
||||
XCTAssertTrue(saveButton.exists, "Save button should exist")
|
||||
saveButton.tap()
|
||||
|
||||
// Then: Should return to residences list and verify residence was created
|
||||
sleep(3) // Wait for save to complete
|
||||
|
||||
// First check we're back on the list
|
||||
let residencesList = app.staticTexts.containing(NSPredicate(format: "label CONTAINS 'Your Properties' OR label CONTAINS 'My Properties'")).firstMatch
|
||||
XCTAssertTrue(residencesList.waitForExistence(timeout: 10), "Should return to residences list after saving")
|
||||
|
||||
// CRITICAL: Verify the residence actually appears in the list
|
||||
let newResidence = app.staticTexts.containing(NSPredicate(format: "label CONTAINS '\(residenceName)'")).firstMatch
|
||||
XCTAssertTrue(newResidence.waitForExistence(timeout: 10), "New residence '\(residenceName)' should appear in the list - network call may have failed!")
|
||||
}
|
||||
|
||||
func testCancelResidenceCreation() {
|
||||
// Given: User is on add residence form
|
||||
navigateToResidencesTab()
|
||||
|
||||
let addButton = app.buttons[AccessibilityIdentifiers.Residence.addButton]
|
||||
addButton.tap()
|
||||
sleep(2)
|
||||
|
||||
// When: User taps cancel
|
||||
let cancelButton = app.buttons.containing(NSPredicate(format: "label CONTAINS[c] 'Cancel'")).firstMatch
|
||||
XCTAssertTrue(cancelButton.waitForExistence(timeout: 5), "Cancel button should exist")
|
||||
cancelButton.tap()
|
||||
|
||||
// Then: Should return to residences list
|
||||
sleep(1)
|
||||
let residencesTab = app.tabBars.buttons.containing(NSPredicate(format: "label CONTAINS[c] 'Residences'")).firstMatch
|
||||
XCTAssertTrue(residencesTab.exists, "Should be back on residences list")
|
||||
}
|
||||
|
||||
func testViewResidenceDetails() {
|
||||
// Given: User is on Residences tab with at least one residence
|
||||
// This test requires testCreateResidenceWithMinimalData to have run first
|
||||
navigateToResidencesTab()
|
||||
sleep(2)
|
||||
|
||||
// Find a residence card by looking for UITest Home text
|
||||
let residenceCard = app.staticTexts.containing(NSPredicate(format: "label CONTAINS 'UITest Home' OR label CONTAINS 'Test'")).firstMatch
|
||||
XCTAssertTrue(residenceCard.waitForExistence(timeout: 5), "At least one residence must exist - run testCreateResidenceWithMinimalData first")
|
||||
|
||||
// When: User taps on the residence
|
||||
residenceCard.tap()
|
||||
sleep(2)
|
||||
|
||||
// Then: Should show residence details screen with edit/delete buttons
|
||||
let editButton = app.buttons.containing(NSPredicate(format: "label CONTAINS[c] 'Edit'")).firstMatch
|
||||
let deleteButton = app.buttons.containing(NSPredicate(format: "label CONTAINS[c] 'Delete'")).firstMatch
|
||||
|
||||
XCTAssertTrue(editButton.exists || deleteButton.exists, "Residence details screen must show with edit or delete button")
|
||||
}
|
||||
|
||||
func testNavigationBetweenTabs() {
|
||||
// Given: User is on Residences tab
|
||||
navigateToResidencesTab()
|
||||
|
||||
// When: User navigates to Tasks tab
|
||||
let tasksTab = app.tabBars.buttons.containing(NSPredicate(format: "label CONTAINS[c] 'Tasks'")).firstMatch
|
||||
XCTAssertTrue(tasksTab.exists, "Tasks tab should exist")
|
||||
tasksTab.tap()
|
||||
sleep(1)
|
||||
|
||||
// Then: Should be on Tasks tab
|
||||
XCTAssertTrue(tasksTab.isSelected, "Should be on Tasks tab")
|
||||
|
||||
// When: User navigates back to Residences
|
||||
let residencesTab = app.tabBars.buttons.containing(NSPredicate(format: "label CONTAINS[c] 'Residences'")).firstMatch
|
||||
residencesTab.tap()
|
||||
sleep(1)
|
||||
|
||||
// Then: Should be back on Residences tab
|
||||
XCTAssertTrue(residencesTab.isSelected, "Should be back on Residences tab")
|
||||
}
|
||||
}
|
||||
36
iosApp/CaseraUITests/Scripts/cleanup_test_users.sh
Executable file
36
iosApp/CaseraUITests/Scripts/cleanup_test_users.sh
Executable file
@@ -0,0 +1,36 @@
|
||||
#!/bin/bash
|
||||
# Script to clean up test users from Django database
|
||||
# Usage: ./cleanup_test_users.sh [email]
|
||||
# If no email provided, cleans up all users with email starting with 'test_'
|
||||
|
||||
EMAIL="$1"
|
||||
|
||||
cd /Users/treyt/Desktop/code/MyCrib/myCribAPI
|
||||
|
||||
if [ -n "$EMAIL" ]; then
|
||||
FILTER="email='$EMAIL'"
|
||||
else
|
||||
FILTER="email__startswith='test_'"
|
||||
fi
|
||||
|
||||
# Try docker exec first (if running in Docker)
|
||||
if docker ps --format '{{.Names}}' | grep -q 'mycrib-web\|myCrib-web'; then
|
||||
CONTAINER_NAME=$(docker ps --format '{{.Names}}' | grep -E 'mycrib-web|myCrib-web' | head -1)
|
||||
docker exec "$CONTAINER_NAME" python manage.py shell -c "
|
||||
from django.contrib.auth import get_user_model
|
||||
User = get_user_model()
|
||||
deleted = User.objects.filter($FILTER).delete()
|
||||
print(f'Deleted: {deleted}')
|
||||
" 2>/dev/null
|
||||
else
|
||||
# Fallback to local Python
|
||||
export DJANGO_SETTINGS_MODULE=myCrib.settings
|
||||
python manage.py shell -c "
|
||||
from django.contrib.auth import get_user_model
|
||||
User = get_user_model()
|
||||
deleted = User.objects.filter($FILTER).delete()
|
||||
print(f'Deleted: {deleted}')
|
||||
" 2>/dev/null
|
||||
fi
|
||||
|
||||
echo "Test users cleanup complete"
|
||||
57
iosApp/CaseraUITests/Scripts/get_verification_code.sh
Executable file
57
iosApp/CaseraUITests/Scripts/get_verification_code.sh
Executable file
@@ -0,0 +1,57 @@
|
||||
#!/bin/bash
|
||||
# Script to fetch verification code from Django database
|
||||
# Usage: ./get_verification_code.sh <email>
|
||||
# Output: Writes the verification code to /tmp/mycrib_verification_code_<sanitized_email>.txt
|
||||
|
||||
EMAIL="$1"
|
||||
|
||||
if [ -z "$EMAIL" ]; then
|
||||
echo "Usage: $0 <email>"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Sanitize email for filename
|
||||
SANITIZED_EMAIL=$(echo "$EMAIL" | sed 's/@/_at_/g' | sed 's/\./_dot_/g')
|
||||
OUTPUT_FILE="/tmp/mycrib_verification_code_${SANITIZED_EMAIL}.txt"
|
||||
|
||||
cd /Users/treyt/Desktop/code/MyCrib/myCribAPI
|
||||
|
||||
# Try docker exec first (if running in Docker)
|
||||
if docker ps --format '{{.Names}}' | grep -q 'mycrib-web\|myCrib-web'; then
|
||||
CONTAINER_NAME=$(docker ps --format '{{.Names}}' | grep -E 'mycrib-web|myCrib-web' | head -1)
|
||||
CODE=$(docker exec "$CONTAINER_NAME" python manage.py shell -c "
|
||||
from user.models import ConfirmationCode
|
||||
from django.contrib.auth import get_user_model
|
||||
User = get_user_model()
|
||||
try:
|
||||
user = User.objects.get(email='$EMAIL')
|
||||
code = ConfirmationCode.objects.filter(user=user, is_used=False).latest('created_at')
|
||||
print(code.code)
|
||||
except Exception as e:
|
||||
print('ERROR:', e)
|
||||
" 2>/dev/null)
|
||||
else
|
||||
# Fallback to local Python
|
||||
export DJANGO_SETTINGS_MODULE=myCrib.settings
|
||||
CODE=$(python manage.py shell -c "
|
||||
from user.models import ConfirmationCode
|
||||
from django.contrib.auth import get_user_model
|
||||
User = get_user_model()
|
||||
try:
|
||||
user = User.objects.get(email='$EMAIL')
|
||||
code = ConfirmationCode.objects.filter(user=user, is_used=False).latest('created_at')
|
||||
print(code.code)
|
||||
except Exception as e:
|
||||
print('ERROR:', e)
|
||||
" 2>/dev/null)
|
||||
fi
|
||||
|
||||
# Check if we got a valid 6-digit code
|
||||
if [[ "$CODE" =~ ^[0-9]{6}$ ]]; then
|
||||
echo "$CODE" > "$OUTPUT_FILE"
|
||||
echo "Verification code saved to $OUTPUT_FILE: $CODE"
|
||||
exit 0
|
||||
else
|
||||
echo "Failed to get verification code: $CODE"
|
||||
exit 1
|
||||
fi
|
||||
63
iosApp/CaseraUITests/SimpleLoginTest.swift
Normal file
63
iosApp/CaseraUITests/SimpleLoginTest.swift
Normal file
@@ -0,0 +1,63 @@
|
||||
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: XCTestCase {
|
||||
var app: XCUIApplication!
|
||||
|
||||
override func setUpWithError() throws {
|
||||
continueAfterFailure = false
|
||||
app = XCUIApplication()
|
||||
app.launch()
|
||||
|
||||
// CRITICAL: Ensure we're logged out before each test
|
||||
ensureLoggedOut()
|
||||
}
|
||||
|
||||
override func tearDownWithError() throws {
|
||||
app = nil
|
||||
}
|
||||
|
||||
// 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.staticTexts["Welcome Back"]
|
||||
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")
|
||||
}
|
||||
}
|
||||
361
iosApp/CaseraUITests/TaskTests.swift
Normal file
361
iosApp/CaseraUITests/TaskTests.swift
Normal file
@@ -0,0 +1,361 @@
|
||||
import XCTest
|
||||
|
||||
/// Task management tests
|
||||
/// Uses UITestHelpers for consistent login/logout behavior
|
||||
/// IMPORTANT: Tasks require at least one residence to exist
|
||||
final class TaskTests: XCTestCase {
|
||||
var app: XCUIApplication!
|
||||
|
||||
override func setUpWithError() throws {
|
||||
continueAfterFailure = false
|
||||
app = XCUIApplication()
|
||||
app.launch()
|
||||
|
||||
// Ensure user is logged in
|
||||
UITestHelpers.ensureLoggedIn(app: app)
|
||||
|
||||
// CRITICAL: Ensure at least one residence exists
|
||||
// Tasks are disabled if no residences exist
|
||||
ensureResidenceExists()
|
||||
|
||||
// Now navigate to Tasks tab
|
||||
navigateToTasksTab()
|
||||
}
|
||||
|
||||
override func tearDownWithError() throws {
|
||||
app = nil
|
||||
}
|
||||
|
||||
// MARK: - Helper Methods
|
||||
|
||||
/// Ensures at least one residence exists (required for tasks to work)
|
||||
private func ensureResidenceExists() {
|
||||
// Navigate to Residences tab
|
||||
let residencesTab = app.tabBars.buttons.containing(NSPredicate(format: "label CONTAINS[c] 'Residences'")).firstMatch
|
||||
if residencesTab.waitForExistence(timeout: 5) {
|
||||
residencesTab.tap()
|
||||
sleep(2)
|
||||
|
||||
// Check if we have any residences
|
||||
// Look for the add button - if we see "Add a property" text or empty state, create one
|
||||
let emptyStateText = app.staticTexts.containing(NSPredicate(format: "label CONTAINS[c] 'No properties' OR label CONTAINS[c] 'No residences'")).firstMatch
|
||||
|
||||
if emptyStateText.exists {
|
||||
// No residences exist, create a quick one
|
||||
let addButton = app.buttons[AccessibilityIdentifiers.Residence.addButton]
|
||||
if addButton.waitForExistence(timeout: 5) {
|
||||
addButton.tap()
|
||||
sleep(2)
|
||||
|
||||
// Fill minimal required fields
|
||||
let nameField = app.textFields.containing(NSPredicate(format: "placeholderValue CONTAINS[c] 'Name'")).firstMatch
|
||||
if nameField.waitForExistence(timeout: 5) {
|
||||
nameField.tap()
|
||||
nameField.typeText("Test Home for Tasks")
|
||||
|
||||
// Scroll to address fields
|
||||
app.swipeUp()
|
||||
sleep(1)
|
||||
|
||||
// Fill required address fields
|
||||
let streetField = app.textFields.containing(NSPredicate(format: "placeholderValue CONTAINS[c] 'Street'")).firstMatch
|
||||
if streetField.exists {
|
||||
streetField.tap()
|
||||
streetField.typeText("123 Test St")
|
||||
}
|
||||
|
||||
let cityField = app.textFields.containing(NSPredicate(format: "placeholderValue CONTAINS[c] 'City'")).firstMatch
|
||||
if cityField.exists {
|
||||
cityField.tap()
|
||||
cityField.typeText("TestCity")
|
||||
}
|
||||
|
||||
let stateField = app.textFields.containing(NSPredicate(format: "placeholderValue CONTAINS[c] 'State'")).firstMatch
|
||||
if stateField.exists {
|
||||
stateField.tap()
|
||||
stateField.typeText("TS")
|
||||
}
|
||||
|
||||
let postalField = app.textFields.containing(NSPredicate(format: "placeholderValue CONTAINS[c] 'Postal' OR placeholderValue CONTAINS[c] 'Zip'")).firstMatch
|
||||
if postalField.exists {
|
||||
postalField.tap()
|
||||
postalField.typeText("12345")
|
||||
}
|
||||
|
||||
// Save
|
||||
let saveButton = app.buttons.containing(NSPredicate(format: "label CONTAINS[c] 'Save'")).firstMatch
|
||||
if saveButton.exists {
|
||||
saveButton.tap()
|
||||
sleep(3) // Wait for save to complete
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func navigateToTasksTab() {
|
||||
let tasksTab = app.tabBars.buttons.containing(NSPredicate(format: "label CONTAINS[c] 'Tasks'")).firstMatch
|
||||
if tasksTab.waitForExistence(timeout: 5) {
|
||||
if !tasksTab.isSelected {
|
||||
tasksTab.tap()
|
||||
sleep(3) // Give it time to load
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Finds the Add Task button using multiple strategies
|
||||
/// The button exists in two places:
|
||||
/// 1. Toolbar (always visible when residences exist)
|
||||
/// 2. Empty state (visible when no tasks exist)
|
||||
private func findAddTaskButton() -> XCUIElement {
|
||||
sleep(2) // Wait for screen to fully render
|
||||
|
||||
// Strategy 1: Try accessibility identifier
|
||||
let addButtonById = app.buttons[AccessibilityIdentifiers.Task.addButton].firstMatch
|
||||
if addButtonById.exists && addButtonById.isEnabled {
|
||||
return addButtonById
|
||||
}
|
||||
|
||||
// Strategy 2: Look for toolbar add button (navigation bar plus button)
|
||||
let navBarButtons = app.navigationBars.buttons
|
||||
for i in 0..<navBarButtons.count {
|
||||
let button = navBarButtons.element(boundBy: i)
|
||||
if button.label == "plus" || button.label.contains("Add") {
|
||||
if button.isEnabled {
|
||||
return button
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Strategy 3: Try finding "Add Task" button in empty state by text
|
||||
let emptyStateButton = app.buttons.containing(NSPredicate(format: "label CONTAINS[c] 'Add Task'")).firstMatch
|
||||
if emptyStateButton.exists && emptyStateButton.isEnabled {
|
||||
return emptyStateButton
|
||||
}
|
||||
|
||||
// Strategy 4: Look for any enabled button with a plus icon
|
||||
let allButtons = app.buttons
|
||||
for i in 0..<min(allButtons.count, 20) { // Check first 20 buttons
|
||||
let button = allButtons.element(boundBy: i)
|
||||
if button.isEnabled && (button.label.contains("plus") || button.label.contains("Add")) {
|
||||
return button
|
||||
}
|
||||
}
|
||||
|
||||
// Return the identifier one as fallback (will fail assertion if doesn't exist)
|
||||
return addButtonById
|
||||
}
|
||||
|
||||
// MARK: - Tests
|
||||
|
||||
func testTasksTabExists() {
|
||||
// Given: User is logged in
|
||||
// When: User looks for Tasks tab
|
||||
let tasksTab = app.tabBars.buttons.containing(NSPredicate(format: "label CONTAINS[c] 'Tasks'")).firstMatch
|
||||
|
||||
// Then: Tasks tab should exist
|
||||
XCTAssertTrue(tasksTab.exists, "Tasks tab should exist in main tab bar")
|
||||
XCTAssertTrue(tasksTab.isSelected, "Tasks tab should be selected after navigation")
|
||||
}
|
||||
|
||||
func testViewTasksList() {
|
||||
// Given: User is on Tasks tab
|
||||
navigateToTasksTab()
|
||||
sleep(3)
|
||||
|
||||
// Then: Tasks screen should be visible
|
||||
// Verify we're on the right screen by checking for the navigation title
|
||||
let tasksTitle = app.staticTexts.containing(NSPredicate(format: "label CONTAINS[c] 'All Tasks' OR label CONTAINS[c] 'Tasks'")).firstMatch
|
||||
XCTAssertTrue(tasksTitle.waitForExistence(timeout: 5), "Tasks screen title should be visible")
|
||||
}
|
||||
|
||||
func testAddTaskButtonExists() {
|
||||
// Given: User is on Tasks tab with at least one residence
|
||||
navigateToTasksTab()
|
||||
sleep(3)
|
||||
|
||||
// Then: Add task button should exist and be enabled
|
||||
let addButton = findAddTaskButton()
|
||||
XCTAssertTrue(addButton.exists, "Add task button should exist on Tasks screen")
|
||||
XCTAssertTrue(addButton.isEnabled, "Add task button should be enabled when residence exists")
|
||||
}
|
||||
|
||||
func testNavigateToAddTask() {
|
||||
// Given: User is on Tasks tab
|
||||
navigateToTasksTab()
|
||||
sleep(3)
|
||||
|
||||
// When: User taps add task button
|
||||
let addButton = findAddTaskButton()
|
||||
XCTAssertTrue(addButton.exists, "Add task button should exist")
|
||||
XCTAssertTrue(addButton.isEnabled, "Add task button should be enabled")
|
||||
|
||||
addButton.tap()
|
||||
sleep(3)
|
||||
|
||||
// Then: Should show add task form with required fields
|
||||
let titleField = app.textFields.containing(NSPredicate(format: "placeholderValue CONTAINS[c] 'Title' OR placeholderValue CONTAINS[c] 'Task'")).firstMatch
|
||||
XCTAssertTrue(titleField.waitForExistence(timeout: 5), "Task title field should appear in add form")
|
||||
|
||||
let saveButton = app.buttons.containing(NSPredicate(format: "label CONTAINS[c] 'Save'")).firstMatch
|
||||
XCTAssertTrue(saveButton.exists, "Save button should exist in add task form")
|
||||
}
|
||||
|
||||
func testCancelTaskCreation() {
|
||||
// Given: User is on add task form
|
||||
navigateToTasksTab()
|
||||
sleep(3)
|
||||
|
||||
let addButton = findAddTaskButton()
|
||||
XCTAssertTrue(addButton.exists && addButton.isEnabled, "Add task button should exist and be enabled")
|
||||
addButton.tap()
|
||||
sleep(3)
|
||||
|
||||
// Verify form opened
|
||||
let titleField = app.textFields.containing(NSPredicate(format: "placeholderValue CONTAINS[c] 'Title'")).firstMatch
|
||||
XCTAssertTrue(titleField.waitForExistence(timeout: 5), "Task form should open")
|
||||
|
||||
// When: User taps cancel
|
||||
let cancelButton = app.buttons.containing(NSPredicate(format: "label CONTAINS[c] 'Cancel'")).firstMatch
|
||||
XCTAssertTrue(cancelButton.exists, "Cancel button should exist in task form")
|
||||
cancelButton.tap()
|
||||
sleep(2)
|
||||
|
||||
// Then: Should return to tasks list
|
||||
let tasksTab = app.tabBars.buttons.containing(NSPredicate(format: "label CONTAINS[c] 'Tasks'")).firstMatch
|
||||
XCTAssertTrue(tasksTab.exists, "Should be back on tasks list after cancel")
|
||||
}
|
||||
|
||||
func testCreateBasicTask() {
|
||||
// Given: User is on Tasks tab
|
||||
navigateToTasksTab()
|
||||
sleep(3)
|
||||
|
||||
// When: User taps add task button
|
||||
let addButton = findAddTaskButton()
|
||||
XCTAssertTrue(addButton.exists && addButton.isEnabled, "Add task button should exist and be enabled")
|
||||
addButton.tap()
|
||||
sleep(3)
|
||||
|
||||
// Verify task form loaded
|
||||
let titleField = app.textFields.containing(NSPredicate(format: "placeholderValue CONTAINS[c] 'Title'")).firstMatch
|
||||
XCTAssertTrue(titleField.waitForExistence(timeout: 5), "Task title field should appear")
|
||||
|
||||
// Fill in task title with unique timestamp
|
||||
let timestamp = Int(Date().timeIntervalSince1970)
|
||||
let taskTitle = "UITest Task \(timestamp)"
|
||||
titleField.tap()
|
||||
titleField.typeText(taskTitle)
|
||||
|
||||
// Scroll down to find and fill description
|
||||
app.swipeUp()
|
||||
sleep(1)
|
||||
|
||||
let descField = app.textViews.containing(NSPredicate(format: "placeholderValue CONTAINS[c] 'Description'")).firstMatch
|
||||
if descField.exists {
|
||||
descField.tap()
|
||||
descField.typeText("Test task")
|
||||
}
|
||||
|
||||
// Scroll to find Save button
|
||||
app.swipeUp()
|
||||
sleep(1)
|
||||
|
||||
// When: User taps save
|
||||
let saveButton = app.buttons.containing(NSPredicate(format: "label CONTAINS[c] 'Save'")).firstMatch
|
||||
XCTAssertTrue(saveButton.exists, "Save button should exist")
|
||||
saveButton.tap()
|
||||
|
||||
// Then: Should return to tasks list
|
||||
sleep(5) // Wait for API call to complete
|
||||
|
||||
// Verify we're back on tasks list by checking tab exists
|
||||
let tasksTab = app.tabBars.buttons.containing(NSPredicate(format: "label CONTAINS[c] 'Tasks'")).firstMatch
|
||||
XCTAssertTrue(tasksTab.exists, "Should be back on tasks list after saving")
|
||||
|
||||
// Verify task appears in the list (may be in kanban columns)
|
||||
let newTask = app.staticTexts.containing(NSPredicate(format: "label CONTAINS '\(taskTitle)'")).firstMatch
|
||||
XCTAssertTrue(newTask.waitForExistence(timeout: 10), "New task '\(taskTitle)' should appear in the list")
|
||||
}
|
||||
|
||||
func testViewTaskDetails() {
|
||||
// Given: User is on Tasks tab and at least one task exists
|
||||
navigateToTasksTab()
|
||||
sleep(3)
|
||||
|
||||
// Look for any task in the list
|
||||
let taskCard = app.staticTexts.containing(NSPredicate(format: "label CONTAINS 'UITest Task' OR label CONTAINS 'Test'")).firstMatch
|
||||
|
||||
if !taskCard.waitForExistence(timeout: 5) {
|
||||
// No task found - skip this test
|
||||
print("⚠️ No tasks found - run testCreateBasicTask first")
|
||||
return
|
||||
}
|
||||
|
||||
// When: User taps on a task
|
||||
taskCard.tap()
|
||||
sleep(2)
|
||||
|
||||
// Then: Should show task details screen
|
||||
let editButton = app.buttons.containing(NSPredicate(format: "label CONTAINS[c] 'Edit'")).firstMatch
|
||||
let completeButton = app.buttons.containing(NSPredicate(format: "label CONTAINS[c] 'Complete' OR label CONTAINS[c] 'Mark'")).firstMatch
|
||||
let backButton = app.buttons.containing(NSPredicate(format: "label CONTAINS[c] 'Back' OR label CONTAINS[c] 'Tasks'")).firstMatch
|
||||
|
||||
let detailScreenVisible = editButton.exists || completeButton.exists || backButton.exists
|
||||
XCTAssertTrue(detailScreenVisible, "Task details screen should show with action buttons")
|
||||
}
|
||||
|
||||
func testNavigateToContractors() {
|
||||
// Given: User is on Tasks tab
|
||||
navigateToTasksTab()
|
||||
sleep(1)
|
||||
|
||||
// When: User taps Contractors tab
|
||||
let contractorsTab = app.tabBars.buttons.containing(NSPredicate(format: "label CONTAINS[c] 'Contractors'")).firstMatch
|
||||
XCTAssertTrue(contractorsTab.waitForExistence(timeout: 5), "Contractors tab should exist")
|
||||
contractorsTab.tap()
|
||||
sleep(1)
|
||||
|
||||
// Then: Should be on Contractors tab
|
||||
XCTAssertTrue(contractorsTab.isSelected, "Contractors tab should be selected")
|
||||
}
|
||||
|
||||
func testNavigateToDocuments() {
|
||||
// Given: User is on Tasks tab
|
||||
navigateToTasksTab()
|
||||
sleep(1)
|
||||
|
||||
// When: User taps Documents tab
|
||||
let documentsTab = app.tabBars.buttons.containing(NSPredicate(format: "label CONTAINS[c] 'Documents'")).firstMatch
|
||||
XCTAssertTrue(documentsTab.waitForExistence(timeout: 5), "Documents tab should exist")
|
||||
documentsTab.tap()
|
||||
sleep(1)
|
||||
|
||||
// Then: Should be on Documents tab
|
||||
XCTAssertTrue(documentsTab.isSelected, "Documents tab should be selected")
|
||||
}
|
||||
|
||||
func testNavigateBetweenTabs() {
|
||||
// Given: User is on Tasks tab
|
||||
navigateToTasksTab()
|
||||
sleep(1)
|
||||
|
||||
// When: User navigates to Residences tab
|
||||
let residencesTab = app.tabBars.buttons.containing(NSPredicate(format: "label CONTAINS[c] 'Residences'")).firstMatch
|
||||
XCTAssertTrue(residencesTab.exists, "Residences tab should exist")
|
||||
residencesTab.tap()
|
||||
sleep(1)
|
||||
|
||||
// Then: Should be on Residences tab
|
||||
XCTAssertTrue(residencesTab.isSelected, "Should be on Residences tab")
|
||||
|
||||
// When: User navigates back to Tasks
|
||||
let tasksTab = app.tabBars.buttons.containing(NSPredicate(format: "label CONTAINS[c] 'Tasks'")).firstMatch
|
||||
tasksTab.tap()
|
||||
sleep(2)
|
||||
|
||||
// Then: Should be back on Tasks tab
|
||||
XCTAssertTrue(tasksTab.isSelected, "Should be back on Tasks tab")
|
||||
}
|
||||
}
|
||||
98
iosApp/CaseraUITests/UITestHelpers.swift
Normal file
98
iosApp/CaseraUITests/UITestHelpers.swift
Normal file
@@ -0,0 +1,98 @@
|
||||
import XCTest
|
||||
|
||||
/// Reusable helper functions for UI tests
|
||||
struct UITestHelpers {
|
||||
|
||||
// MARK: - Authentication Helpers
|
||||
|
||||
/// Logs out the user if they are currently logged in
|
||||
/// - Parameter app: The XCUIApplication instance
|
||||
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
|
||||
return
|
||||
}
|
||||
|
||||
// User is logged in, need to log them out
|
||||
let profileTab = app.tabBars.buttons.containing(NSPredicate(format: "label CONTAINS[c] 'Profile'")).firstMatch
|
||||
if profileTab.exists {
|
||||
profileTab.tap()
|
||||
sleep(1)
|
||||
|
||||
let logoutButton = app.buttons.containing(NSPredicate(format: "label CONTAINS[c] 'Logout' OR label CONTAINS[c] 'Log Out' OR label CONTAINS[c] 'Sign Out'")).firstMatch
|
||||
if logoutButton.waitForExistence(timeout: 5) {
|
||||
logoutButton.tap()
|
||||
sleep(1)
|
||||
|
||||
// Tap the "Log Out" button on the alert
|
||||
let alertLogoutButton = app.alerts.buttons["Log Out"]
|
||||
if alertLogoutButton.exists {
|
||||
alertLogoutButton.tap()
|
||||
sleep(2)
|
||||
} else {
|
||||
// Fallback to broader search if exact match not found
|
||||
let confirmButton = app.alerts.buttons.containing(NSPredicate(format: "label CONTAINS[c] 'Logout' OR label CONTAINS[c] 'Log Out' OR label CONTAINS[c] 'Confirm' OR label CONTAINS[c] 'Yes'")).firstMatch
|
||||
if confirmButton.exists {
|
||||
confirmButton.tap()
|
||||
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")
|
||||
}
|
||||
|
||||
/// 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
|
||||
static func login(app: XCUIApplication, username: String, password: String) {
|
||||
let usernameField = app.textFields.containing(NSPredicate(format: "placeholderValue CONTAINS[c] 'email'")).firstMatch
|
||||
XCTAssertTrue(usernameField.waitForExistence(timeout: 5), "Username field should exist")
|
||||
usernameField.tap()
|
||||
usernameField.typeText(username)
|
||||
|
||||
let passwordField = app.secureTextFields.containing(NSPredicate(format: "placeholderValue CONTAINS[c] 'password'")).firstMatch
|
||||
XCTAssertTrue(passwordField.exists, "Password field should exist")
|
||||
passwordField.tap()
|
||||
passwordField.typeText(password)
|
||||
|
||||
let signInButton = app.buttons.containing(NSPredicate(format: "label CONTAINS[c] 'Sign In'")).firstMatch
|
||||
XCTAssertTrue(signInButton.exists, "Sign In button should exist")
|
||||
signInButton.tap()
|
||||
}
|
||||
|
||||
/// Ensures the user is logged out before running a test
|
||||
/// - Parameter app: The XCUIApplication instance
|
||||
static func ensureLoggedOut(app: XCUIApplication) {
|
||||
sleep(3)
|
||||
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(3)
|
||||
|
||||
// Need to login
|
||||
let usernameField = app.textFields.containing(NSPredicate(format: "placeholderValue CONTAINS[c] 'email'")).firstMatch
|
||||
if usernameField.waitForExistence(timeout: 5) {
|
||||
login(app: app, username: username, password: password)
|
||||
|
||||
// Wait for main screen to appear
|
||||
let mainTab = app.tabBars.buttons.containing(NSPredicate(format: "label CONTAINS[c] 'Residences' OR label CONTAINS[c] 'Tasks'")).firstMatch
|
||||
_ = mainTab.waitForExistence(timeout: 10)
|
||||
} else {
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user