More tests
This commit is contained in:
parent
da1a90f5f5
commit
aa5353ffcc
|
@ -0,0 +1,90 @@
|
|||
# Xcode
|
||||
#
|
||||
# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore
|
||||
|
||||
## User settings
|
||||
xcuserdata/
|
||||
|
||||
## compatibility with Xcode 8 and earlier (ignoring not required starting Xcode 9)
|
||||
*.xcscmblueprint
|
||||
*.xccheckout
|
||||
|
||||
## compatibility with Xcode 3 and earlier (ignoring not required starting Xcode 4)
|
||||
build/
|
||||
DerivedData/
|
||||
*.moved-aside
|
||||
*.pbxuser
|
||||
!default.pbxuser
|
||||
*.mode1v3
|
||||
!default.mode1v3
|
||||
*.mode2v3
|
||||
!default.mode2v3
|
||||
*.perspectivev3
|
||||
!default.perspectivev3
|
||||
|
||||
## Obj-C/Swift specific
|
||||
*.hmap
|
||||
|
||||
## App packaging
|
||||
*.ipa
|
||||
*.dSYM.zip
|
||||
*.dSYM
|
||||
|
||||
## Playgrounds
|
||||
timeline.xctimeline
|
||||
playground.xcworkspace
|
||||
|
||||
# Swift Package Manager
|
||||
#
|
||||
# Add this line if you want to avoid checking in source code from Swift Package Manager dependencies.
|
||||
# Packages/
|
||||
# Package.pins
|
||||
# Package.resolved
|
||||
# *.xcodeproj
|
||||
#
|
||||
# Xcode automatically generates this directory with a .xcworkspacedata file and xcuserdata
|
||||
# hence it is not needed unless you have added a package configuration file to your project
|
||||
# .swiftpm
|
||||
|
||||
.build/
|
||||
|
||||
# CocoaPods
|
||||
#
|
||||
# We recommend against adding the Pods directory to your .gitignore. However
|
||||
# you should judge for yourself, the pros and cons are mentioned at:
|
||||
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
|
||||
#
|
||||
# Pods/
|
||||
#
|
||||
# Add this line if you want to avoid checking in source code from the Xcode workspace
|
||||
# *.xcworkspace
|
||||
|
||||
# Carthage
|
||||
#
|
||||
# Add this line if you want to avoid checking in source code from Carthage dependencies.
|
||||
# Carthage/Checkouts
|
||||
|
||||
Carthage/Build/
|
||||
|
||||
# Accio dependency management
|
||||
Dependencies/
|
||||
.accio/
|
||||
|
||||
# fastlane
|
||||
#
|
||||
# It is recommended to not store the screenshots in the git repo.
|
||||
# Instead, use fastlane to re-generate the screenshots whenever they are needed.
|
||||
# For more information about the recommended setup visit:
|
||||
# https://docs.fastlane.tools/best-practices/source-control/#source-control
|
||||
|
||||
fastlane/report.xml
|
||||
fastlane/Preview.html
|
||||
fastlane/screenshots/**/*.png
|
||||
fastlane/test_output
|
||||
|
||||
# Code Injection
|
||||
#
|
||||
# After new code Injection tools there's a generated folder /iOSInjectionProject
|
||||
# https://github.com/johnno1962/injectionforxcode
|
||||
|
||||
iOSInjectionProject/
|
|
@ -8,10 +8,11 @@
|
|||
|
||||
/* Begin PBXBuildFile section */
|
||||
C068701C238DE85D00DAFD3D /* Introspect.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C0687012238DE85D00DAFD3D /* Introspect.framework */; };
|
||||
C0687021238DE85D00DAFD3D /* IntrospectTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = C0687020238DE85D00DAFD3D /* IntrospectTests.swift */; };
|
||||
C0687021238DE85D00DAFD3D /* TableViewTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = C0687020238DE85D00DAFD3D /* TableViewTests.swift */; };
|
||||
C0687023238DE85D00DAFD3D /* Introspect.h in Headers */ = {isa = PBXBuildFile; fileRef = C0687015238DE85D00DAFD3D /* Introspect.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
||||
C068702D238DE8FD00DAFD3D /* Introspect.swift in Sources */ = {isa = PBXBuildFile; fileRef = C068702C238DE8FD00DAFD3D /* Introspect.swift */; };
|
||||
C068702F238DF01200DAFD3D /* TestUtils.swift in Sources */ = {isa = PBXBuildFile; fileRef = C068702E238DF01200DAFD3D /* TestUtils.swift */; };
|
||||
C0687031238DF3C900DAFD3D /* NavigationViewTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = C0687030238DF3C900DAFD3D /* NavigationViewTests.swift */; };
|
||||
/* End PBXBuildFile section */
|
||||
|
||||
/* Begin PBXContainerItemProxy section */
|
||||
|
@ -29,10 +30,11 @@
|
|||
C0687015238DE85D00DAFD3D /* Introspect.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Introspect.h; sourceTree = "<group>"; };
|
||||
C0687016238DE85D00DAFD3D /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
|
||||
C068701B238DE85D00DAFD3D /* IntrospectTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = IntrospectTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
C0687020238DE85D00DAFD3D /* IntrospectTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IntrospectTests.swift; sourceTree = "<group>"; };
|
||||
C0687020238DE85D00DAFD3D /* TableViewTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TableViewTests.swift; sourceTree = "<group>"; };
|
||||
C0687022238DE85D00DAFD3D /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
|
||||
C068702C238DE8FD00DAFD3D /* Introspect.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Introspect.swift; sourceTree = "<group>"; };
|
||||
C068702E238DF01200DAFD3D /* TestUtils.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TestUtils.swift; sourceTree = "<group>"; };
|
||||
C0687030238DF3C900DAFD3D /* NavigationViewTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NavigationViewTests.swift; sourceTree = "<group>"; };
|
||||
/* End PBXFileReference section */
|
||||
|
||||
/* Begin PBXFrameworksBuildPhase section */
|
||||
|
@ -85,8 +87,9 @@
|
|||
C068701F238DE85D00DAFD3D /* IntrospectTests */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
C0687020238DE85D00DAFD3D /* IntrospectTests.swift */,
|
||||
C0687022238DE85D00DAFD3D /* Info.plist */,
|
||||
C0687030238DF3C900DAFD3D /* NavigationViewTests.swift */,
|
||||
C0687020238DE85D00DAFD3D /* TableViewTests.swift */,
|
||||
C068702E238DF01200DAFD3D /* TestUtils.swift */,
|
||||
);
|
||||
path = IntrospectTests;
|
||||
|
@ -210,7 +213,8 @@
|
|||
isa = PBXSourcesBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
C0687021238DE85D00DAFD3D /* IntrospectTests.swift in Sources */,
|
||||
C0687031238DF3C900DAFD3D /* NavigationViewTests.swift in Sources */,
|
||||
C0687021238DE85D00DAFD3D /* TableViewTests.swift in Sources */,
|
||||
C068702F238DF01200DAFD3D /* TestUtils.swift in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
|
|
|
@ -55,6 +55,42 @@ public struct IntrospectionView<ViewType: UIView>: UIViewRepresentable {
|
|||
}
|
||||
}
|
||||
|
||||
public struct IntrospectionViewController<ViewControllerType: UIViewController>: UIViewControllerRepresentable {
|
||||
|
||||
|
||||
let selector: (UIViewController) -> ViewControllerType?
|
||||
let customize: (ViewControllerType) -> Void
|
||||
|
||||
public init(
|
||||
selector: @escaping (UIViewController) -> ViewControllerType?,
|
||||
customize: @escaping (ViewControllerType) -> Void
|
||||
) {
|
||||
self.selector = selector
|
||||
self.customize = customize
|
||||
}
|
||||
|
||||
public func makeUIViewController(
|
||||
context: UIViewControllerRepresentableContext<IntrospectionViewController>
|
||||
) -> UIViewController {
|
||||
return UIViewController(nibName: nil, bundle: nil)
|
||||
}
|
||||
|
||||
public func updateUIViewController(
|
||||
_ uiViewController: UIViewController,
|
||||
context: UIViewControllerRepresentableContext<IntrospectionViewController>
|
||||
) {
|
||||
DispatchQueue.main.asyncAfter(deadline: .now()) {
|
||||
guard let hostingViewController = uiViewController.parent else {
|
||||
return
|
||||
}
|
||||
guard let targetView = self.selector(hostingViewController) else {
|
||||
return
|
||||
}
|
||||
self.customize(targetView)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
extension View {
|
||||
public func introspectTableView(customize: @escaping (UITableView) -> ()) -> some View {
|
||||
|
@ -65,4 +101,11 @@ extension View {
|
|||
customize: customize
|
||||
))
|
||||
}
|
||||
|
||||
public func introspectNavigationController(customize: @escaping (UINavigationController) -> ()) -> some View {
|
||||
return background(IntrospectionViewController(
|
||||
selector: { $0.navigationController },
|
||||
customize: customize
|
||||
))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,29 @@
|
|||
import XCTest
|
||||
import SwiftUI
|
||||
|
||||
@testable import Introspect
|
||||
|
||||
private struct TestView: View {
|
||||
let spy: () -> Void
|
||||
var body: some View {
|
||||
NavigationView {
|
||||
VStack {
|
||||
EmptyView()
|
||||
}
|
||||
.introspectNavigationController { navigationController in
|
||||
self.spy()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class NavigationViewTests: XCTestCase {
|
||||
func testCallsCustomize() {
|
||||
let expectation = XCTestExpectation()
|
||||
let view = TestView(spy: {
|
||||
expectation.fulfill()
|
||||
})
|
||||
TestUtils.present(view: view)
|
||||
wait(for: [expectation], timeout: 1)
|
||||
}
|
||||
}
|
|
@ -3,7 +3,7 @@ import SwiftUI
|
|||
|
||||
@testable import Introspect
|
||||
|
||||
struct ListView: View {
|
||||
private struct TestView: View {
|
||||
let spy: () -> Void
|
||||
var body: some View {
|
||||
List {
|
||||
|
@ -16,10 +16,10 @@ struct ListView: View {
|
|||
}
|
||||
}
|
||||
|
||||
class IntrospectTests: XCTestCase {
|
||||
class TableViewTests: XCTestCase {
|
||||
func testCallsCustomize() {
|
||||
let expectation = XCTestExpectation()
|
||||
let view = ListView(spy: {
|
||||
let view = TestView(spy: {
|
||||
expectation.fulfill()
|
||||
})
|
||||
TestUtils.present(view: view)
|
Loading…
Reference in New Issue