Files
PlantGuide/PlantGuideTests/TestFixtures/CareTask+TestFixtures.swift
Trey t 136dfbae33 Add PlantGuide iOS app with plant identification and care management
- Implement camera capture and plant identification workflow
- Add Core Data persistence for plants, care schedules, and cached API data
- Create collection view with grid/list layouts and filtering
- Build plant detail views with care information display
- Integrate Trefle botanical API for plant care data
- Add local image storage for captured plant photos
- Implement dependency injection container for testability
- Include accessibility support throughout the app

Bug fixes in this commit:
- Fix Trefle API decoding by removing duplicate CodingKeys
- Fix LocalCachedImage to load from correct PlantImages directory
- Set dateAdded when saving plants for proper collection sorting

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-23 12:18:01 -06:00

212 lines
6.8 KiB
Swift

//
// CareTask+TestFixtures.swift
// PlantGuideTests
//
// Test fixtures for CareTask entity - provides factory methods for
// creating test instances with sensible defaults.
//
import Foundation
@testable import PlantGuide
// MARK: - CareTask Test Fixtures
extension CareTask {
// MARK: - Factory Methods
/// Creates a mock care task with default values for testing
/// - Parameters:
/// - id: The task's unique identifier. Defaults to a new UUID.
/// - plantID: ID of the plant this task belongs to. Defaults to a new UUID.
/// - type: Type of care task. Defaults to .watering.
/// - scheduledDate: When the task is scheduled. Defaults to tomorrow.
/// - completedDate: When the task was completed. Defaults to nil (not completed).
/// - notes: Additional notes. Defaults to empty string.
/// - Returns: A configured CareTask instance for testing
static func mock(
id: UUID = UUID(),
plantID: UUID = UUID(),
type: CareTaskType = .watering,
scheduledDate: Date = Calendar.current.date(byAdding: .day, value: 1, to: Date())!,
completedDate: Date? = nil,
notes: String = ""
) -> CareTask {
CareTask(
id: id,
plantID: plantID,
type: type,
scheduledDate: scheduledDate,
completedDate: completedDate,
notes: notes
)
}
/// Creates a mock watering task
/// - Parameters:
/// - plantID: ID of the plant this task belongs to
/// - scheduledDate: When the task is scheduled. Defaults to tomorrow.
/// - completedDate: When the task was completed. Defaults to nil.
/// - Returns: A watering task
static func mockWatering(
id: UUID = UUID(),
plantID: UUID = UUID(),
scheduledDate: Date = Calendar.current.date(byAdding: .day, value: 1, to: Date())!,
completedDate: Date? = nil
) -> CareTask {
mock(
id: id,
plantID: plantID,
type: .watering,
scheduledDate: scheduledDate,
completedDate: completedDate,
notes: "Water with moderate amount"
)
}
/// Creates a mock fertilizing task
/// - Parameters:
/// - plantID: ID of the plant this task belongs to
/// - scheduledDate: When the task is scheduled. Defaults to next week.
/// - completedDate: When the task was completed. Defaults to nil.
/// - Returns: A fertilizing task
static func mockFertilizing(
id: UUID = UUID(),
plantID: UUID = UUID(),
scheduledDate: Date = Calendar.current.date(byAdding: .day, value: 7, to: Date())!,
completedDate: Date? = nil
) -> CareTask {
mock(
id: id,
plantID: plantID,
type: .fertilizing,
scheduledDate: scheduledDate,
completedDate: completedDate,
notes: "Apply balanced fertilizer"
)
}
/// Creates a mock repotting task
/// - Parameters:
/// - plantID: ID of the plant this task belongs to
/// - scheduledDate: When the task is scheduled. Defaults to next month.
/// - Returns: A repotting task
static func mockRepotting(
id: UUID = UUID(),
plantID: UUID = UUID(),
scheduledDate: Date = Calendar.current.date(byAdding: .month, value: 1, to: Date())!
) -> CareTask {
mock(
id: id,
plantID: plantID,
type: .repotting,
scheduledDate: scheduledDate,
notes: "Move to larger pot with fresh soil"
)
}
/// Creates a mock pruning task
/// - Parameters:
/// - plantID: ID of the plant this task belongs to
/// - scheduledDate: When the task is scheduled. Defaults to next week.
/// - Returns: A pruning task
static func mockPruning(
id: UUID = UUID(),
plantID: UUID = UUID(),
scheduledDate: Date = Calendar.current.date(byAdding: .day, value: 14, to: Date())!
) -> CareTask {
mock(
id: id,
plantID: plantID,
type: .pruning,
scheduledDate: scheduledDate,
notes: "Remove dead leaves and shape plant"
)
}
/// Creates a mock pest control task
/// - Parameters:
/// - plantID: ID of the plant this task belongs to
/// - scheduledDate: When the task is scheduled. Defaults to tomorrow.
/// - Returns: A pest control task
static func mockPestControl(
id: UUID = UUID(),
plantID: UUID = UUID(),
scheduledDate: Date = Calendar.current.date(byAdding: .day, value: 1, to: Date())!
) -> CareTask {
mock(
id: id,
plantID: plantID,
type: .pestControl,
scheduledDate: scheduledDate,
notes: "Apply neem oil treatment"
)
}
/// Creates an overdue task (scheduled in the past, not completed)
static func mockOverdue(
plantID: UUID = UUID(),
daysOverdue: Int = 3
) -> CareTask {
mock(
plantID: plantID,
type: .watering,
scheduledDate: Calendar.current.date(byAdding: .day, value: -daysOverdue, to: Date())!,
completedDate: nil,
notes: "Overdue watering task"
)
}
/// Creates a completed task
static func mockCompleted(
plantID: UUID = UUID(),
type: CareTaskType = .watering
) -> CareTask {
let scheduledDate = Calendar.current.date(byAdding: .day, value: -1, to: Date())!
return mock(
plantID: plantID,
type: type,
scheduledDate: scheduledDate,
completedDate: Date(),
notes: "Completed task"
)
}
/// Creates a future task scheduled for a specific number of days ahead
static func mockFuture(
plantID: UUID = UUID(),
type: CareTaskType = .watering,
daysAhead: Int = 7
) -> CareTask {
mock(
plantID: plantID,
type: type,
scheduledDate: Calendar.current.date(byAdding: .day, value: daysAhead, to: Date())!
)
}
/// Creates an array of watering tasks for the next several weeks
static func mockWeeklyWateringTasks(
plantID: UUID = UUID(),
weeks: Int = 4
) -> [CareTask] {
(0..<weeks).map { weekIndex in
let scheduledDate = Calendar.current.date(
byAdding: .day,
value: (weekIndex + 1) * 7,
to: Date()
)!
return mockWatering(plantID: plantID, scheduledDate: scheduledDate)
}
}
/// Creates a set of mixed tasks for a single plant
static func mockMixedTasks(plantID: UUID = UUID()) -> [CareTask] {
[
mockWatering(plantID: plantID),
mockFertilizing(plantID: plantID),
mockPruning(plantID: plantID)
]
}
}