Skip to content

Commit

Permalink
Add ContributorFeatureTests
Browse files Browse the repository at this point in the history
  • Loading branch information
shin-usu committed Jul 26, 2024
1 parent 5d2c4f7 commit e0d5b69
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 7 deletions.
10 changes: 7 additions & 3 deletions app-ios/Sources/ContributorFeature/ContributorReducer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,13 @@ public struct ContributorReducer: Sendable {
switch action {
case .onAppear:
return .run { send in
try await contributorClient.refresh()
for try await contributors in try contributorClient.streamContributors() {
await send(.response(.success(contributors)))
do {
try await contributorClient.refresh()
for try await contributors in try contributorClient.streamContributors() {
await send(.response(.success(contributors)))
}
} catch {
await send(.response(.failure(error)))
}
}
.cancellable(id: CancelID.request)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,66 @@
import XCTest
import ComposableArchitecture
import Model
@preconcurrency import shared
@testable import ContributorFeature

final class ContributorFeatureTests: XCTestCase {

@MainActor
func testExample() async throws {
let store = TestStore(initialState: ContributorReducer.State(text: "HOGE")) {
func testOnAppear() async throws {
let contributors = Contributor.companion.fakes()
let store = TestStore(initialState: ContributorReducer.State()) {
ContributorReducer()
} withDependencies: {
$0.contributorClient.refresh = {}
$0.contributorClient.streamContributors = {
AsyncThrowingStream {
$0.yield(contributors)
$0.finish()
}
}
}
await store.send(.onAppear) {
$0.text = "Contributor Feature"

await store.send(.onAppear)
await store.receive(\.response) {
$0.contributors = contributors
}
}

@MainActor
func testOnAppearFail() async throws {
let contributors = Contributor.companion.fakes()
let store = TestStore(initialState: ContributorReducer.State()) {
ContributorReducer()
} withDependencies: {
$0.contributorClient.refresh = {
throw ContributorTestError.fail
}
$0.contributorClient.streamContributors = {
AsyncThrowingStream {
$0.yield(contributors)
$0.finish()
}
}
}

await store.send(.onAppear)
await store.receive(\.response)
}

@MainActor
func testContributorButtonTapped() async throws {
let url = URL(string: "https://github.com/DroidKaigi/conference-app-2023")!
let store = TestStore(initialState: ContributorReducer.State()) {
ContributorReducer()
}

await store.send(.view(.contributorButtonTapped(url))) {
$0.url = IdentifiableURL(url)
}
}
}

enum ContributorTestError: Error {
case fail
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import XCTest
import ComposableArchitecture
import shared
import Model
@testable import TimetableDetailFeature

final class TimetableDetail_iosTests: XCTestCase {
Expand Down

0 comments on commit e0d5b69

Please sign in to comment.