Skip to content

Add introspectMapView #125

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Feb 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions Introspect/ViewExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -257,3 +257,15 @@ extension View {
}
}
#endif

#if canImport(MapKit)
import MapKit

extension View {
/// Finds an `MKMapView` from a `SwiftUI.Map`
@available(iOS 14, tvOS 14, macOS 11, *)
public func introspectMapView(customize: @escaping (MKMapView) -> ()) -> some View {
introspect(selector: TargetViewSelector.siblingContaining, customize: customize)
}
}
#endif
23 changes: 23 additions & 0 deletions IntrospectTests/AppKitTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,20 @@ private struct ColorWellTestView: View {
}
}

import MapKit
@available(macOS 11, *)
private struct MapTestView: View {
@State private var coordinateRegion = MKCoordinateRegion(.world)
let spy: () -> Void

var body: some View {
Map(coordinateRegion: $coordinateRegion)
.introspectMapView { mapView in
self.spy()
}
}
}

class AppKitTests: XCTestCase {

func testList() {
Expand Down Expand Up @@ -403,5 +417,14 @@ class AppKitTests: XCTestCase {
TestUtils.present(view: view)
wait(for: [expectation], timeout: TestUtils.Constants.timeout)
}

func testMapView() {
let expectation = XCTestExpectation()
let view = MapTestView(spy: {
expectation.fulfill()
})
TestUtils.present(view: view)
wait(for: [expectation], timeout: TestUtils.Constants.timeout)
}
}
#endif
50 changes: 36 additions & 14 deletions IntrospectTests/UIKitTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,20 @@ private struct ColorWellTestView: View {
}
}

import MapKit
@available(iOS 14, tvOS 14, *)
private struct MapTestView: View {
@State private var coordinateRegion = MKCoordinateRegion(.world)
let spy: () -> Void

var body: some View {
Map(coordinateRegion: $coordinateRegion)
.introspectMapView { mapView in
self.spy()
}
}
}

class UIKitTests: XCTestCase {
func testNavigation() {

Expand Down Expand Up @@ -525,28 +539,28 @@ class UIKitTests: XCTestCase {
TestUtils.present(view: view)
wait(for: [expectation], timeout: TestUtils.Constants.timeout)
}

#if os(iOS)
func testSplitNavigation() {

func testRootNavigation() {

let expectation = XCTestExpectation()
let view = SplitNavigationTestView(spy: {
let view = NavigationRootTestView(spy: {
expectation.fulfill()
})
TestUtils.present(view: view)
wait(for: [expectation], timeout: TestUtils.Constants.timeout)
}

func testRootNavigation() {


#if !os(tvOS)
func testSplitNavigation() {

let expectation = XCTestExpectation()
let view = NavigationRootTestView(spy: {
let view = SplitNavigationTestView(spy: {
expectation.fulfill()
})
TestUtils.present(view: view)
wait(for: [expectation], timeout: TestUtils.Constants.timeout)
}

func testToggle() {

let expectation = XCTestExpectation()
Expand All @@ -556,7 +570,7 @@ class UIKitTests: XCTestCase {
TestUtils.present(view: view)
wait(for: [expectation], timeout: TestUtils.Constants.timeout)
}

func testSlider() {

let expectation = XCTestExpectation()
Expand All @@ -566,7 +580,7 @@ class UIKitTests: XCTestCase {
TestUtils.present(view: view)
wait(for: [expectation], timeout: TestUtils.Constants.timeout)
}

func testStepper() {

let expectation = XCTestExpectation()
Expand All @@ -576,7 +590,7 @@ class UIKitTests: XCTestCase {
TestUtils.present(view: view)
wait(for: [expectation], timeout: TestUtils.Constants.timeout)
}

func testDatePicker() {

let expectation = XCTestExpectation()
Expand All @@ -588,7 +602,6 @@ class UIKitTests: XCTestCase {
}

@available(iOS 14, *)
@available(tvOS, unavailable, message: "TextEditor is not available in tvOS.")
func testTextEditor() {

let expectation = XCTestExpectation()
Expand All @@ -600,7 +613,6 @@ class UIKitTests: XCTestCase {
}

@available(iOS 14, *)
@available(tvOS, unavailable, message: "ColorPicker is not available in tvOS.")
func testColorPicker() {

let expectation = XCTestExpectation()
Expand Down Expand Up @@ -636,5 +648,15 @@ class UIKitTests: XCTestCase {
}
}
#endif

@available(iOS 14, tvOS 14, *)
func testMapView() {
let expectation = XCTestExpectation()
let view = MapTestView(spy: {
expectation.fulfill()
})
TestUtils.present(view: view)
wait(for: [expectation], timeout: TestUtils.Constants.timeout)
}
}
#endif