diff --git a/MMMTestCase.podspec b/MMMTestCase.podspec index d36dc52..0527133 100644 --- a/MMMTestCase.podspec +++ b/MMMTestCase.podspec @@ -6,7 +6,7 @@ Pod::Spec.new do |s| s.name = "MMMTestCase" - s.version = "1.13.0" + s.version = "1.13.1" s.summary = "Our helpers for FBTestCase and XCTestCase" s.description = s.summary s.homepage = "https://github.com/mediamonks/#{s.name}" diff --git a/Sources/MMMTestCase/MMMTestCase.swift b/Sources/MMMTestCase/MMMTestCase.swift index 6689937..4c08fdd 100644 --- a/Sources/MMMTestCase/MMMTestCase.swift +++ b/Sources/MMMTestCase/MMMTestCase.swift @@ -36,14 +36,14 @@ public enum MMMTestCaseSize { fileprivate func asValue() -> NSValue { switch self { - case .natural: - return NSNumber(value: MMMTestCaseFit.natural.rawValue) - case .screenWidth: - return NSNumber(value: MMMTestCaseFit.screenWidth.rawValue) - case .screenWidthTableHeight: - return NSNumber(value: MMMTestCaseFit.screenWidthTableHeight.rawValue) - case let .size(width, height): - return NSValue(cgSize: CGSize(width: width, height: height)) + case .natural: + return NSNumber(value: MMMTestCaseFit.natural.rawValue) + case .screenWidth: + return NSNumber(value: MMMTestCaseFit.screenWidth.rawValue) + case .screenWidthTableHeight: + return NSNumber(value: MMMTestCaseFit.screenWidthTableHeight.rawValue) + case let .size(width, height): + return NSValue(cgSize: CGSize(width: width, height: height)) } } } @@ -99,12 +99,10 @@ extension MMMTestCase { } @available(iOS 16, *) - public func verify( - view: T, - fit: MMMTestCaseSize = .screenWidthTableHeight, - identifier: String = "", - backgroundColor: UIColor? = nil - ) { + public func testableView( + from view: T, + fit: MMMTestCaseSize = .screenWidthTableHeight + ) -> UIView { let controller = UIHostingController(rootView: view) controller.sizingOptions = .intrinsicContentSize @@ -141,8 +139,21 @@ extension MMMTestCase { // We need the layout to happen naturally now. pumpRunLoopABit() + return controller.view + } + + @available(iOS 16, *) + public func verify( + view: T, + fit: MMMTestCaseSize = .screenWidthTableHeight, + identifier: String = "", + backgroundColor: UIColor? = nil + ) { + + let fitSize = sizeForFit(fit) + verify( - view: controller.view, + view: testableView(from: view, fit: fit), fit: fit, identifier: [ identifier, @@ -175,9 +186,9 @@ extension MMMTestCase { /// Helps generating parameter dictionaries suitable for `varyParameters` from enums supporting `CaseIterable`. public func allTestCases(_ type: T.Type) -> [String: T] { .init(uniqueKeysWithValues: - T.allCases - .map { (String(MMMTypeName($0).split(separator: ".").last!), $0) } - .sorted { a, b in a.0 < b.0 } + T.allCases + .map { (String(MMMTypeName($0).split(separator: ".").last!), $0) } + .sorted { a, b in a.0 < b.0 } ) } }