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>
This commit is contained in:
212
PlantGuideTests/TestFixtures/Plant+TestFixtures.swift
Normal file
212
PlantGuideTests/TestFixtures/Plant+TestFixtures.swift
Normal file
@@ -0,0 +1,212 @@
|
||||
//
|
||||
// Plant+TestFixtures.swift
|
||||
// PlantGuideTests
|
||||
//
|
||||
// Test fixtures for Plant entity - provides factory methods for creating
|
||||
// test instances with sensible defaults.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
@testable import PlantGuide
|
||||
|
||||
// MARK: - Plant Test Fixtures
|
||||
|
||||
extension Plant {
|
||||
|
||||
// MARK: - Factory Methods
|
||||
|
||||
/// Creates a mock plant with default values for testing
|
||||
/// - Parameters:
|
||||
/// - id: The plant's unique identifier. Defaults to a new UUID.
|
||||
/// - scientificName: Scientific name. Defaults to "Monstera deliciosa".
|
||||
/// - commonNames: Array of common names. Defaults to ["Swiss Cheese Plant"].
|
||||
/// - family: Botanical family. Defaults to "Araceae".
|
||||
/// - genus: Botanical genus. Defaults to "Monstera".
|
||||
/// - imageURLs: Remote image URLs. Defaults to empty.
|
||||
/// - dateIdentified: When plant was identified. Defaults to current date.
|
||||
/// - identificationSource: Source of identification. Defaults to .onDeviceML.
|
||||
/// - localImagePaths: Local storage paths. Defaults to empty.
|
||||
/// - dateAdded: When added to collection. Defaults to nil.
|
||||
/// - confidenceScore: Identification confidence. Defaults to 0.95.
|
||||
/// - notes: User notes. Defaults to nil.
|
||||
/// - isFavorite: Favorite status. Defaults to false.
|
||||
/// - customName: User-assigned name. Defaults to nil.
|
||||
/// - location: Plant location. Defaults to nil.
|
||||
/// - Returns: A configured Plant instance for testing
|
||||
static func mock(
|
||||
id: UUID = UUID(),
|
||||
scientificName: String = "Monstera deliciosa",
|
||||
commonNames: [String] = ["Swiss Cheese Plant"],
|
||||
family: String = "Araceae",
|
||||
genus: String = "Monstera",
|
||||
imageURLs: [URL] = [],
|
||||
dateIdentified: Date = Date(),
|
||||
identificationSource: IdentificationSource = .onDeviceML,
|
||||
localImagePaths: [String] = [],
|
||||
dateAdded: Date? = nil,
|
||||
confidenceScore: Double? = 0.95,
|
||||
notes: String? = nil,
|
||||
isFavorite: Bool = false,
|
||||
customName: String? = nil,
|
||||
location: String? = nil
|
||||
) -> Plant {
|
||||
Plant(
|
||||
id: id,
|
||||
scientificName: scientificName,
|
||||
commonNames: commonNames,
|
||||
family: family,
|
||||
genus: genus,
|
||||
imageURLs: imageURLs,
|
||||
dateIdentified: dateIdentified,
|
||||
identificationSource: identificationSource,
|
||||
localImagePaths: localImagePaths,
|
||||
dateAdded: dateAdded,
|
||||
confidenceScore: confidenceScore,
|
||||
notes: notes,
|
||||
isFavorite: isFavorite,
|
||||
customName: customName,
|
||||
location: location
|
||||
)
|
||||
}
|
||||
|
||||
/// Creates a mock Monstera plant
|
||||
static func mockMonstera(
|
||||
id: UUID = UUID(),
|
||||
isFavorite: Bool = false
|
||||
) -> Plant {
|
||||
mock(
|
||||
id: id,
|
||||
scientificName: "Monstera deliciosa",
|
||||
commonNames: ["Swiss Cheese Plant", "Monstera"],
|
||||
family: "Araceae",
|
||||
genus: "Monstera",
|
||||
isFavorite: isFavorite
|
||||
)
|
||||
}
|
||||
|
||||
/// Creates a mock Pothos plant
|
||||
static func mockPothos(
|
||||
id: UUID = UUID(),
|
||||
isFavorite: Bool = false
|
||||
) -> Plant {
|
||||
mock(
|
||||
id: id,
|
||||
scientificName: "Epipremnum aureum",
|
||||
commonNames: ["Pothos", "Devil's Ivy", "Golden Pothos"],
|
||||
family: "Araceae",
|
||||
genus: "Epipremnum",
|
||||
isFavorite: isFavorite
|
||||
)
|
||||
}
|
||||
|
||||
/// Creates a mock Snake Plant
|
||||
static func mockSnakePlant(
|
||||
id: UUID = UUID(),
|
||||
isFavorite: Bool = false
|
||||
) -> Plant {
|
||||
mock(
|
||||
id: id,
|
||||
scientificName: "Sansevieria trifasciata",
|
||||
commonNames: ["Snake Plant", "Mother-in-law's Tongue"],
|
||||
family: "Asparagaceae",
|
||||
genus: "Sansevieria",
|
||||
isFavorite: isFavorite
|
||||
)
|
||||
}
|
||||
|
||||
/// Creates a mock Peace Lily plant
|
||||
static func mockPeaceLily(
|
||||
id: UUID = UUID(),
|
||||
isFavorite: Bool = false
|
||||
) -> Plant {
|
||||
mock(
|
||||
id: id,
|
||||
scientificName: "Spathiphyllum wallisii",
|
||||
commonNames: ["Peace Lily", "Spathe Flower"],
|
||||
family: "Araceae",
|
||||
genus: "Spathiphyllum",
|
||||
isFavorite: isFavorite
|
||||
)
|
||||
}
|
||||
|
||||
/// Creates a mock Fiddle Leaf Fig plant
|
||||
static func mockFiddleLeafFig(
|
||||
id: UUID = UUID(),
|
||||
isFavorite: Bool = false
|
||||
) -> Plant {
|
||||
mock(
|
||||
id: id,
|
||||
scientificName: "Ficus lyrata",
|
||||
commonNames: ["Fiddle Leaf Fig", "Fiddle-leaf Fig"],
|
||||
family: "Moraceae",
|
||||
genus: "Ficus",
|
||||
isFavorite: isFavorite
|
||||
)
|
||||
}
|
||||
|
||||
/// Creates an array of mock plants for collection testing
|
||||
static func mockCollection(count: Int = 5) -> [Plant] {
|
||||
var plants: [Plant] = []
|
||||
let generators: [() -> Plant] = [
|
||||
{ .mockMonstera() },
|
||||
{ .mockPothos() },
|
||||
{ .mockSnakePlant() },
|
||||
{ .mockPeaceLily() },
|
||||
{ .mockFiddleLeafFig() }
|
||||
]
|
||||
|
||||
for i in 0..<count {
|
||||
plants.append(generators[i % generators.count]())
|
||||
}
|
||||
return plants
|
||||
}
|
||||
|
||||
/// Creates a plant with an image URL for caching tests
|
||||
static func mockWithImages(
|
||||
id: UUID = UUID(),
|
||||
imageCount: Int = 3
|
||||
) -> Plant {
|
||||
let imageURLs = (0..<imageCount).map { index in
|
||||
URL(string: "https://example.com/images/plant_\(id.uuidString)_\(index).jpg")!
|
||||
}
|
||||
return mock(
|
||||
id: id,
|
||||
imageURLs: imageURLs
|
||||
)
|
||||
}
|
||||
|
||||
/// Creates a plant with local image paths for storage tests
|
||||
static func mockWithLocalImages(
|
||||
id: UUID = UUID(),
|
||||
imageCount: Int = 2
|
||||
) -> Plant {
|
||||
let localPaths = (0..<imageCount).map { index in
|
||||
"\(id.uuidString)/image_\(index).jpg"
|
||||
}
|
||||
return mock(
|
||||
id: id,
|
||||
localImagePaths: localPaths
|
||||
)
|
||||
}
|
||||
|
||||
/// Creates a fully populated plant with all optional fields
|
||||
static func mockComplete(id: UUID = UUID()) -> Plant {
|
||||
mock(
|
||||
id: id,
|
||||
scientificName: "Monstera deliciosa",
|
||||
commonNames: ["Swiss Cheese Plant", "Monstera", "Split-leaf Philodendron"],
|
||||
family: "Araceae",
|
||||
genus: "Monstera",
|
||||
imageURLs: [URL(string: "https://example.com/monstera.jpg")!],
|
||||
dateIdentified: Date(),
|
||||
identificationSource: .plantNetAPI,
|
||||
localImagePaths: ["\(id.uuidString)/captured.jpg"],
|
||||
dateAdded: Date(),
|
||||
confidenceScore: 0.98,
|
||||
notes: "Needs regular watering and indirect light",
|
||||
isFavorite: true,
|
||||
customName: "My Beautiful Monstera",
|
||||
location: "Living room by the window"
|
||||
)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user