Skip to content

Commit

Permalink
Add test for store invalidation. (pointfreeco#3038)
Browse files Browse the repository at this point in the history
  • Loading branch information
mbrandonw committed Apr 30, 2024
1 parent e6c0959 commit 2974c68
Showing 1 changed file with 59 additions and 0 deletions.
59 changes: 59 additions & 0 deletions Tests/ComposableArchitectureTests/StoreTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1055,6 +1055,65 @@
Feature.State(count: 0, isOn: false, subjectCount: 1)
)
}

@Reducer
struct InvalidatedStoreScopeParentFeature: Reducer {
@ObservableState
struct State {
@Presents var child: InvalidatedStoreScopeChildFeature.State?
}
enum Action {
case child(PresentationAction<InvalidatedStoreScopeChildFeature.Action>)
case tap
}
var body: some ReducerOf<Self> {
EmptyReducer()
.ifLet(\.$child, action: \.child) {
InvalidatedStoreScopeChildFeature()
}
}
}
@Reducer
struct InvalidatedStoreScopeChildFeature: Reducer {
@ObservableState
struct State {
@Presents var grandchild: InvalidatedStoreScopeGrandchildFeature.State?
}
enum Action {
case grandchild(PresentationAction<InvalidatedStoreScopeGrandchildFeature.Action>)
}
var body: some ReducerOf<Self> {
EmptyReducer()
.ifLet(\.$grandchild, action: \.grandchild) {
InvalidatedStoreScopeGrandchildFeature()
}
}
}
@Reducer
struct InvalidatedStoreScopeGrandchildFeature: Reducer {
struct State {}
enum Action {}
var body: some ReducerOf<Self> { EmptyReducer() }
}
@MainActor
func testInvalidatedStoreScope() async throws {
@Perception.Bindable var store = Store(
initialState: InvalidatedStoreScopeParentFeature.State(
child: InvalidatedStoreScopeChildFeature.State(
grandchild: InvalidatedStoreScopeGrandchildFeature.State()
)
)
) {
InvalidatedStoreScopeParentFeature()
}
store.send(.tap)

@Perception.Bindable var childStore = store.scope(state: \.child, action: \.child)!
let grandchildStoreBinding = $childStore.scope(state: \.grandchild, action: \.grandchild)

store.send(.child(.dismiss))
grandchildStoreBinding.wrappedValue = nil
}
}

private struct Count: TestDependencyKey {
Expand Down

0 comments on commit 2974c68

Please sign in to comment.