Skip to content

Commit 49dae77

Browse files
committed
Added a test for nested dismissal.
1 parent 0c22607 commit 49dae77

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

Tests/ComposableArchitectureTests/Reducers/PresentationReducerTests.swift

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2639,4 +2639,51 @@ final class PresentationReducerTests: BaseTCATestCase {
26392639
XCTAssertEqual($state, $state)
26402640
XCTAssertLessThan(Date().timeIntervalSince(start), 0.1)
26412641
}
2642+
2643+
@MainActor
2644+
func testNestedDismiss() async {
2645+
let store = TestStore(initialState: NestedDismissFeature.State()) {
2646+
NestedDismissFeature()
2647+
}
2648+
2649+
await store.send(\.presentButtonTapped) {
2650+
$0.child = NestedDismissFeature.State()
2651+
}
2652+
await store.send(\.child.presentButtonTapped) {
2653+
$0.child?.child = NestedDismissFeature.State()
2654+
}
2655+
await store.send(\.child.child.dismissButtonTapped)
2656+
await store.receive(\.child.child.dismiss) {
2657+
$0.child?.child = nil
2658+
}
2659+
}
2660+
}
2661+
2662+
@Reducer
2663+
private struct NestedDismissFeature {
2664+
struct State: Equatable {
2665+
@PresentationState var child: NestedDismissFeature.State?
2666+
}
2667+
enum Action {
2668+
case child(PresentationAction<NestedDismissFeature.Action>)
2669+
case dismissButtonTapped
2670+
case presentButtonTapped
2671+
}
2672+
@Dependency(\.dismiss) var dismiss
2673+
var body: some ReducerOf<Self> {
2674+
Reduce { state, action in
2675+
switch action {
2676+
case .child:
2677+
return .none
2678+
case .dismissButtonTapped:
2679+
return .run { _ in await dismiss() }
2680+
case .presentButtonTapped:
2681+
state.child = State()
2682+
return .none
2683+
}
2684+
}
2685+
.ifLet(\.$child, action: \.child) {
2686+
Self()
2687+
}
2688+
}
26422689
}

0 commit comments

Comments
 (0)