-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add SponsorFeatureTests * move Sponsors mocks to test module
- Loading branch information
Showing
6 changed files
with
93 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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")! | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<URL?>(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) | ||
} | ||
} | ||
} |