From e323d3a475a0a39115bd701f7a7226de2163c2e2 Mon Sep 17 00:00:00 2001 From: Cosmic Flamingo Date: Thu, 19 Dec 2024 10:40:13 -0600 Subject: [PATCH] Add test for explicitly dismissing view controller --- .../CaseStudiesTests/PresentationTests.swift | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/Examples/CaseStudiesTests/PresentationTests.swift b/Examples/CaseStudiesTests/PresentationTests.swift index 33b28506a..ba6101179 100644 --- a/Examples/CaseStudiesTests/PresentationTests.swift +++ b/Examples/CaseStudiesTests/PresentationTests.swift @@ -42,6 +42,27 @@ final class PresentationTests: XCTestCase { await assertEventuallyEqual(vc.isPresenting, false) } + @MainActor + func testPresents_Dismissal() 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) + + withUITransaction(\.uiKit.disablesAnimations, true) { + vc.presentedViewController?.dismiss(animated: false) + } + await assertEventuallyNil(vc.presentedViewController) + await assertEventuallyEqual(vc.model.isPresented, false) + await assertEventuallyEqual(vc.isPresenting, false) + } + @MainActor func testPresents_TraitDismissal() async throws { let vc = BasicViewController() @@ -53,12 +74,14 @@ final class PresentationTests: XCTestCase { vc.model.isPresented = true } await assertEventuallyNotNil(vc.presentedViewController) + await assertEventuallyEqual(vc.isPresenting, true) withUITransaction(\.uiKit.disablesAnimations, true) { vc.presentedViewController?.traitCollection.dismiss() } await assertEventuallyNil(vc.presentedViewController) await assertEventuallyEqual(vc.model.isPresented, false) + await assertEventuallyEqual(vc.isPresenting, false) } @MainActor