Skip to content

Commit

Permalink
Added a test for nested dismissal.
Browse files Browse the repository at this point in the history
  • Loading branch information
mbrandonw committed Mar 20, 2024
1 parent 0c22607 commit 49dae77
Showing 1 changed file with 47 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2639,4 +2639,51 @@ final class PresentationReducerTests: BaseTCATestCase {
XCTAssertEqual($state, $state)
XCTAssertLessThan(Date().timeIntervalSince(start), 0.1)
}

@MainActor
func testNestedDismiss() async {
let store = TestStore(initialState: NestedDismissFeature.State()) {
NestedDismissFeature()
}

await store.send(\.presentButtonTapped) {
$0.child = NestedDismissFeature.State()
}
await store.send(\.child.presentButtonTapped) {
$0.child?.child = NestedDismissFeature.State()
}
await store.send(\.child.child.dismissButtonTapped)
await store.receive(\.child.child.dismiss) {
$0.child?.child = nil
}
}
}

@Reducer
private struct NestedDismissFeature {
struct State: Equatable {
@PresentationState var child: NestedDismissFeature.State?
}
enum Action {
case child(PresentationAction<NestedDismissFeature.Action>)
case dismissButtonTapped
case presentButtonTapped
}
@Dependency(\.dismiss) var dismiss
var body: some ReducerOf<Self> {
Reduce { state, action in
switch action {
case .child:
return .none
case .dismissButtonTapped:
return .run { _ in await dismiss() }
case .presentButtonTapped:
state.child = State()
return .none
}
}
.ifLet(\.$child, action: \.child) {
Self()
}
}
}

0 comments on commit 49dae77

Please sign in to comment.