Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
mbrandonw committed Mar 7, 2023
1 parent f22eca1 commit 79c64d2
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 16 deletions.
13 changes: 12 additions & 1 deletion Examples/Integration/Integration/PresentationTestCase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,11 @@ private struct PresentationTestCase: ReducerProtocol {
case .destination(.presented(.alert(.showSheet))):
state.destination = .sheet(ChildFeature.State())
return .none
case .destination(.presented(.dialog(.showAlert))),
case
.destination(.presented(.dialog(.showAlert))),
.destination(.presented(.fullScreenCover(.dismissAndAlert))),
.destination(.presented(.popover(.dismissAndAlert))),
.destination(.presented(.navigationDestination(.dismissAndAlert))),
.destination(.presented(.sheet(.dismissAndAlert))):
state.destination = .alert(
AlertState {
Expand Down Expand Up @@ -172,6 +176,7 @@ private struct ChildFeature: ReducerProtocol {
struct State: Equatable, Identifiable {
var id = UUID()
var count = 0
var isDismissed = false
@BindingState var text = ""
}
enum Action: BindableAction, Equatable {
Expand All @@ -192,13 +197,15 @@ private struct ChildFeature: ReducerProtocol {
case .binding:
return .none
case .childDismissButtonTapped:
state.isDismissed = true
return .fireAndForget { await self.dismiss() }
case .dismissAndAlert:
return .none
case .incrementButtonTapped:
state.count += 1
return .none
case .parentSendDismissActionButtonTapped:
state.isDismissed = true
return .none
case .resetIdentity:
state.id = UUID()
Expand Down Expand Up @@ -326,6 +333,7 @@ struct PresentationTestCaseView: View {
}

private struct ChildView: View {
@Environment(\.dismiss) var dismiss
let store: StoreOf<ChildFeature>

var body: some View {
Expand All @@ -352,6 +360,9 @@ private struct ChildView: View {
viewStore.send(.resetIdentity)
}
}
.onChange(of: viewStore.isDismissed) { _ in
self.dismiss()
}
}
}
}
Expand Down
22 changes: 22 additions & 0 deletions Examples/Integration/IntegrationUITests/PresentationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -251,4 +251,26 @@ final class PresentationTests: XCTestCase {
self.app.buttons["Parent dismiss"].tap()
XCTAssertEqual(self.app.staticTexts["Action sent while state nil."].exists, false)
}


func testNavigationDestination_ChildDismiss() {
self.app.buttons["Open navigation destination"].tap()
XCTAssertEqual(true, self.app.staticTexts["Count: 0"].exists)

self.app.buttons["Increment"].tap()
XCTAssertEqual(true, self.app.staticTexts["Count: 1"].exists)
self.app.buttons["Increment"].tap()
XCTAssertEqual(true, self.app.staticTexts["Count: 2"].exists)

self.app.buttons["Child dismiss"].tap()
XCTAssertEqual(false, self.app.staticTexts["Count: 2"].exists)
}

func testNavigationDestination_ParentDismiss() {
self.app.buttons["Open navigation destination"].tap()
XCTAssertEqual(true, self.app.staticTexts["Count: 0"].exists)

self.app.buttons["Parent dismiss"].tap()
XCTAssertEqual(false, self.app.staticTexts["Count: 0"].exists)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,10 @@ import SwiftUI
}

func body(content: Content) -> some View {
content.navigationDestination(isPresented: self.viewStore.binding(send: .dismiss)) {
content.navigationDestination(
// TODO: do binding with ID check
isPresented: self.viewStore.binding(send: .dismiss)
) {
IfLetStore(
self.store.scope(
state: returningLastNonNilValue { $0.wrappedValue.flatMap(self.toDestinationState) },
Expand Down
30 changes: 16 additions & 14 deletions Tests/ComposableArchitectureTests/PresentationReducerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1049,21 +1049,23 @@ import XCTest
}
}

let store = TestStore(
initialState: Parent.State(),
reducer: Parent()
)
let childPresentationTask = await store.send(.presentChild) {
$0.child = Child.State()
}
let grandchildPresentationTask = await store.send(.child(.presented(.presentGrandchild))) {
$0.child?.grandchild = Grandchild.State()
await _withMainSerialExecutor {
let store = TestStore(
initialState: Parent.State(),
reducer: Parent()
)
let childPresentationTask = await store.send(.presentChild) {
$0.child = Child.State()
}
let grandchildPresentationTask = await store.send(.child(.presented(.presentGrandchild))) {
$0.child?.grandchild = Grandchild.State()
}
await store.send(.child(.presented(.startButtonTapped)))
await store.send(.child(.presented(.grandchild(.presented(.startButtonTapped)))))
await store.send(.stopButtonTapped)
await grandchildPresentationTask.cancel()
await childPresentationTask.cancel()
}
await store.send(.child(.presented(.startButtonTapped)))
await store.send(.child(.presented(.grandchild(.presented(.startButtonTapped)))))
await store.send(.stopButtonTapped)
await grandchildPresentationTask.cancel()
await childPresentationTask.cancel()
}

func testNavigation_cancelID_parentCancelTwoChildren() async {
Expand Down

0 comments on commit 79c64d2

Please sign in to comment.