Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions Examples/CaseStudiesTests/Internal/AssertEventually.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,23 @@
import CustomDump
import XCTest

@MainActor
func assertEventually(
_ expression: @autoclosure @escaping @MainActor () -> Bool,
timeout: TimeInterval = 1,
file: StaticString = #file,
line: UInt = #line
) async {
await _assertEventually(
expression(),
condition: { $0 },
assert: XCTAssertTrue,
timeout: timeout,
file: file,
line: line
)
}

@MainActor
func assertEventuallyEqual<T: Equatable>(
_ expression1: @autoclosure () -> T,
Expand Down
67 changes: 66 additions & 1 deletion Examples/CaseStudiesTests/PresentationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,71 @@ final class PresentationTests: XCTestCase {
)
await assertEventuallyNotNil(vc.presentedChild)
}

@MainActor func testOnDismissCalledForInteractiveDismissal() async throws {
let vc = BasicViewController()
try await setUp(controller: vc)

await assertEventuallyNil(vc.presentedViewController)

withUITransaction(\.uiKit.disablesAnimations, true) {
vc.model.isPresented = true
}
await assertEventuallyNotNil(vc.presentedViewController)
await assertEventuallyEqual(vc.isPresenting, true)

vc.presentedViewController!.dismiss(animated: false)
await assertEventuallyNil(vc.presentedViewController)
await assertEventuallyEqual(vc.isPresenting, false)
}

@Observable
fileprivate final class Destinations: Identifiable {
@CasePathable
enum Destination {
case presentedA
case presentedB
}
var destination: Destination?
}
@MainActor func testOnDismissNotCalledForUnrelatedDismissal() async throws {
class A: ViewController {}
class B: ViewController {}
class VC: ViewController {
@UIBindable var model = Destinations()
var onDismissA: (() -> Void)?
var onDismissB: (() -> Void)?
override func viewDidLoad() {
super.viewDidLoad()
present(isPresented: UIBinding($model.destination.presentedA)) { [weak self] in
self?.onDismissA?()
} content: {
A()
}
present(isPresented: UIBinding($model.destination.presentedB)) { [weak self] in
self?.onDismissB?()
} content: {
B()
}
}
}
let vc = VC()
vc.onDismissB = { XCTFail() }
try await setUp(controller: vc)

await assertEventuallyNil(vc.presentedViewController)

withUITransaction(\.uiKit.disablesAnimations, true) {
vc.model.destination = .presentedA
}
await assertEventually(vc.presentedViewController is A)

withUITransaction(\.uiKit.disablesAnimations, true) {
vc.model.destination = .presentedB
}
await assertEventually(vc.presentedViewController is B)
vc.onDismissB = nil
}
}

@Observable
Expand Down Expand Up @@ -522,7 +587,7 @@ private class ViewController: UIViewController {

private class BasicViewController: UIViewController {
@UIBindable var model: Model
var isPresenting = false
private(set) var isPresenting = false
init(model: Model = Model()) {
self.model = model
super.init(nibName: nil, bundle: nil)
Expand Down
Loading