Refactor iOS UI tests to blueprint architecture

This commit is contained in:
treyt
2026-02-20 10:38:15 -06:00
parent 710a8bd1d6
commit fe28034f3d
28 changed files with 7354 additions and 83 deletions

View File

@@ -7,6 +7,9 @@ import Combine
/// Kicks off API calls that update DataManager, letting views react to cache updates.
@MainActor
class ResidenceViewModel: ObservableObject {
private static var uiTestMockResidences: [ResidenceResponse] = []
private static var uiTestNextResidenceId: Int = 1000
// MARK: - Published Properties (from DataManager observation)
@Published var myResidences: MyResidencesResponse?
@Published var residences: [ResidenceResponse] = []
@@ -93,6 +96,18 @@ class ResidenceViewModel: ObservableObject {
/// Load my residences - checks cache first, then fetches if needed
func loadMyResidences(forceRefresh: Bool = false) {
if UITestRuntime.shouldMockAuth {
if Self.uiTestMockResidences.isEmpty || forceRefresh {
if Self.uiTestMockResidences.isEmpty {
Self.uiTestMockResidences = [makeMockResidence(name: "Seed Residence")]
}
}
myResidences = MyResidencesResponse(residences: Self.uiTestMockResidences)
isLoading = false
errorMessage = nil
return
}
errorMessage = nil
// Check if we have cached data and don't need to refresh
@@ -122,6 +137,13 @@ class ResidenceViewModel: ObservableObject {
}
func getResidence(id: Int32) {
if UITestRuntime.shouldMockAuth {
selectedResidence = Self.uiTestMockResidences.first(where: { $0.id == id })
isLoading = false
errorMessage = selectedResidence == nil ? "Residence not found" : nil
return
}
isLoading = true
errorMessage = nil
@@ -151,6 +173,22 @@ class ResidenceViewModel: ObservableObject {
/// Creates a residence and returns the created residence on success
func createResidence(request: ResidenceCreateRequest, completion: @escaping (ResidenceResponse?) -> Void) {
if UITestRuntime.shouldMockAuth {
let residence = makeMockResidence(
name: request.name,
streetAddress: request.streetAddress ?? "",
city: request.city ?? "",
stateProvince: request.stateProvince ?? "",
postalCode: request.postalCode ?? ""
)
Self.uiTestMockResidences.append(residence)
myResidences = MyResidencesResponse(residences: Self.uiTestMockResidences)
isLoading = false
errorMessage = nil
completion(residence)
return
}
isLoading = true
errorMessage = nil
@@ -279,4 +317,44 @@ class ResidenceViewModel: ObservableObject {
}
}
}
private func makeMockResidence(
name: String,
streetAddress: String = "",
city: String = "",
stateProvince: String = "",
postalCode: String = ""
) -> ResidenceResponse {
let id = Self.uiTestNextResidenceId
Self.uiTestNextResidenceId += 1
let now = "2026-02-20T00:00:00Z"
return ResidenceResponse(
id: Int32(id),
ownerId: 1,
owner: ResidenceUserResponse(id: 1, username: "testuser", email: "test@example.com", firstName: "UI", lastName: "Tester"),
users: [],
name: name,
propertyTypeId: 1,
propertyType: ResidenceType(id: 1, name: "House"),
streetAddress: streetAddress,
apartmentUnit: "",
city: city,
stateProvince: stateProvince,
postalCode: postalCode,
country: "USA",
bedrooms: nil,
bathrooms: nil,
squareFootage: nil,
lotSize: nil,
yearBuilt: nil,
description: "",
purchaseDate: nil,
purchasePrice: nil,
isPrimary: false,
isActive: true,
overdueCount: 0,
createdAt: now,
updatedAt: now
)
}
}