This commit is contained in:
David Roman 2023-06-03 18:45:46 +01:00
parent 23be8b5783
commit 56fa10f9b4
No known key found for this signature in database
GPG Key ID: 7058646EEFCB70A7
1 changed files with 3 additions and 23 deletions

View File

@ -3,36 +3,16 @@ import XCTest
#if canImport(UIKit) #if canImport(UIKit)
enum TestUtils { enum TestUtils {
enum Constants { private static let window = UIWindow(frame: UIScreen.main.bounds)
static let timeout: TimeInterval = 3
}
static func present(view: some View) { static func present(view: some View) {
let hostingController = UIHostingController(rootView: view) window.rootViewController = UIHostingController(rootView: view)
for window in UIApplication.shared.windows {
if let presentedViewController = window.rootViewController?.presentedViewController {
presentedViewController.dismiss(animated: false, completion: nil)
}
window.isHidden = true
}
let window = UIWindow(frame: UIScreen.main.bounds)
window.layer.speed = 10
hostingController.beginAppearanceTransition(true, animated: false)
window.rootViewController = hostingController
window.makeKeyAndVisible() window.makeKeyAndVisible()
window.layoutIfNeeded() window.layoutIfNeeded()
hostingController.endAppearanceTransition()
} }
} }
#elseif canImport(AppKit) #elseif canImport(AppKit)
enum TestUtils { enum TestUtils {
enum Constants {
static let timeout: TimeInterval = 5
}
static func present(view: some View) { static func present(view: some View) {
let window = NSWindow( let window = NSWindow(
contentRect: NSRect(x: 0, y: 0, width: 480, height: 300), contentRect: NSRect(x: 0, y: 0, width: 480, height: 300),
@ -60,7 +40,7 @@ func XCTAssertViewIntrospection<V: View, PV: AnyObject>(
let spies = Spies<PV>() let spies = Spies<PV>()
let view = view(spies) let view = view(spies)
TestUtils.present(view: view) TestUtils.present(view: view)
XCTWaiter(delegate: spies).wait(for: spies.expectations.values.map(\.0), timeout: TestUtils.Constants.timeout) XCTWaiter(delegate: spies).wait(for: spies.expectations.values.map(\.0), timeout: 3)
extraAssertions(spies.objects.sorted(by: { $0.key < $1.key }).map(\.value)) extraAssertions(spies.objects.sorted(by: { $0.key < $1.key }).map(\.value))
} }