Last active
March 5, 2024 06:39
-
-
Save edudnyk/e37f6b6946562f9d89160638f100e196 to your computer and use it in GitHub Desktop.
Utils for _ViewTest
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import SwiftUI | |
import XCTest | |
extension UIHostingController: _Test where Content == AnyView {} | |
extension UIHostingController: _ViewTest where Content == AnyView { | |
public func initRootView() -> AnyView { | |
return rootView | |
} | |
public func initSize() -> CGSize { | |
sizeThatFits(in: UIScreen.main.bounds.size) | |
} | |
} | |
extension _IdentifiedViewsKey: PreferenceKey {} | |
extension _ContainedScrollViewKey: PreferenceKey {} | |
open class ViewTestCase: XCTestCase { | |
public var viewTest: UIHostingController<AnyView>? | |
open override func setUp() { | |
super.setUp() | |
let viewTest: UIHostingController<AnyView>? | |
if #available(iOS 15, *) { | |
viewTest = _makeUIHostingController(initRootView(), tracksContentSize: tracksContentSize) as? UIHostingController<AnyView> | |
} else { | |
viewTest = _makeUIHostingController(initRootView()) as? UIHostingController<AnyView> | |
} | |
viewTest?.setUpTest() | |
self.viewTest = viewTest | |
} | |
var window: UIWindow? { | |
(UIApplication.shared.connectedScenes.first as? UIWindowScene)? | |
.windows | |
.first | |
} | |
@ViewBuilder | |
open func initRootView() -> AnyView { AnyView(EmptyView()) } | |
@available(iOS 15, *) | |
open var tracksContentSize: Bool { true } | |
open override func tearDown() { | |
viewTest?.tearDownTest() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment