diff --git a/App/App/App.xctestplan b/App/App/App.xctestplan index 3db89c3..91bc0ce 100644 --- a/App/App/App.xctestplan +++ b/App/App/App.xctestplan @@ -23,6 +23,13 @@ "identifier" : "ScheduleFeatureTests", "name" : "ScheduleFeatureTests" } + }, + { + "target" : { + "containerPath" : "container:..\/MyLibrary", + "identifier" : "SponsorFeatureTests", + "name" : "SponsorFeatureTests" + } } ], "version" : 1 diff --git a/MyLibrary/Package.swift b/MyLibrary/Package.swift index 404847f..62fed8c 100644 --- a/MyLibrary/Package.swift +++ b/MyLibrary/Package.swift @@ -96,5 +96,13 @@ let package = Package( .product(name: "ComposableArchitecture", package: "swift-composable-architecture"), ] ), + .testTarget( + name: "SponsorFeatureTests", + dependencies: [ + "SponsorFeature", + "SharedModels", + .product(name: "ComposableArchitecture", package: "swift-composable-architecture"), + ] + ), ] ) diff --git a/MyLibrary/Sources/SharedModels/Sponsors.swift b/MyLibrary/Sources/SharedModels/Sponsors.swift index 5d07957..4187cfe 100644 --- a/MyLibrary/Sources/SharedModels/Sponsors.swift +++ b/MyLibrary/Sources/SharedModels/Sponsors.swift @@ -12,7 +12,6 @@ public enum Plan: String, Codable, Sendable, CaseIterable { } public struct Sponsors: Codable, Equatable, Hashable, Sendable { - public var id: UUID { .init() } let platinum: [Sponsor] let gold: [Sponsor] let silver: [Sponsor] @@ -35,7 +34,7 @@ public struct Sponsors: Codable, Equatable, Hashable, Sendable { ] } - init( + public init( platinum: [Sponsor], gold: [Sponsor], silver: [Sponsor], bronze: [Sponsor], diversity: [Sponsor], student: [Sponsor], community: [Sponsor], individual: [Sponsor] ) { diff --git a/MyLibrary/Sources/SponsorFeature/Sponsors.swift b/MyLibrary/Sources/SponsorFeature/Sponsors.swift index 568a89e..e18be89 100644 --- a/MyLibrary/Sources/SponsorFeature/Sponsors.swift +++ b/MyLibrary/Sources/SponsorFeature/Sponsors.swift @@ -23,6 +23,7 @@ public struct SponsorsList { case binding(BindingAction) case view(View) + @CasePathable public enum View { case onAppear case sponsorTapped(Sponsor) diff --git a/MyLibrary/Tests/SponsorFeatureTests/Mocks.swift b/MyLibrary/Tests/SponsorFeatureTests/Mocks.swift new file mode 100644 index 0000000..825462a --- /dev/null +++ b/MyLibrary/Tests/SponsorFeatureTests/Mocks.swift @@ -0,0 +1,31 @@ +import Foundation +import SharedModels + +extension Sponsors { + static let mock = Self( + platinum: [.platinumMock], + gold: [.goldMock], + silver: [], + bronze: [], + diversity: [], + student: [], + community: [], + individual: [] + ) +} + +extension Sponsor { + static let platinumMock = Self( + id: 1, + name: "platinaum sponsor", + imageName: "platinum_image", + link: URL(string: "https://example.com/platinum")! + ) + + static let goldMock = Self( + id: 2, + name: "gold sponsor", + imageName: "gold_image", + link: URL(string: "https://example.com/gold")! + ) +} diff --git a/MyLibrary/Tests/SponsorFeatureTests/SponsorsTests.swift b/MyLibrary/Tests/SponsorFeatureTests/SponsorsTests.swift new file mode 100644 index 0000000..2841e70 --- /dev/null +++ b/MyLibrary/Tests/SponsorFeatureTests/SponsorsTests.swift @@ -0,0 +1,45 @@ +import ComposableArchitecture +import DataClient +import SharedModels +import DependencyExtra +import XCTest + +@testable import SponsorFeature + +final class SponsorsTests: XCTestCase { + @MainActor + func testOnAppear() async { + let store = TestStore(initialState: SponsorsList.State()) { + SponsorsList() + } withDependencies: { + $0[DataClient.self].fetchSponsors = { @Sendable in .mock } + } + + await store.send(\.view.onAppear) { + $0.sponsors = .mock + } + } + + @MainActor + func testSponsorTapped() async { + let receivedUrl = ActorIsolated(nil) + + let store = TestStore(initialState: SponsorsList.State()) { + SponsorsList() + } withDependencies: { + $0.safari = { @Sendable in + SafariEffect { url in + await receivedUrl.withValue { + $0 = url + return true + } + } + }() + } + + await store.send(\.view.sponsorTapped, .platinumMock) + await receivedUrl.withValue { + XCTAssertEqual($0, Sponsor.platinumMock.link) + } + } +}