Skip to content

Commit

Permalink
Separate testableView method (1.13.1)
Browse files Browse the repository at this point in the history
  • Loading branch information
terwanerik committed Dec 18, 2024
1 parent c8c090e commit 7211678
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 19 deletions.
2 changes: 1 addition & 1 deletion MMMTestCase.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down
47 changes: 29 additions & 18 deletions Sources/MMMTestCase/MMMTestCase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}
}
Expand Down Expand Up @@ -99,12 +99,10 @@ extension MMMTestCase {
}

@available(iOS 16, *)
public func verify<T: SwiftUI.View>(
view: T,
fit: MMMTestCaseSize = .screenWidthTableHeight,
identifier: String = "",
backgroundColor: UIColor? = nil
) {
public func testableView<T: SwiftUI.View>(
from view: T,
fit: MMMTestCaseSize = .screenWidthTableHeight
) -> UIView {

let controller = UIHostingController(rootView: view)
controller.sizingOptions = .intrinsicContentSize
Expand Down Expand Up @@ -141,8 +139,21 @@ extension MMMTestCase {
// We need the layout to happen naturally now.
pumpRunLoopABit()

return controller.view
}

@available(iOS 16, *)
public func verify<T: SwiftUI.View>(
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,
Expand Down Expand Up @@ -175,9 +186,9 @@ extension MMMTestCase {
/// Helps generating parameter dictionaries suitable for `varyParameters` from enums supporting `CaseIterable`.
public func allTestCases<T: CaseIterable>(_ 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 }
)
}
}

0 comments on commit 7211678

Please sign in to comment.