Skip to content
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

Add testMapViewPointForCoordinate. #3953

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
40 changes: 40 additions & 0 deletions Tests/MapboxNavigationTests/MapViewTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -284,4 +284,44 @@ class MapViewTests: TestCase {
XCTAssertNil(VectorSource.preferredMapboxStreetsLocale(for: Locale(identifier: "tlh")),
"Klingon not yet implemented. 🖖")
}

func testMapViewPointForCoordinate() {
let resourceOptions = ResourceOptions(accessToken: "")
let mapInitOptions = MapInitOptions(resourceOptions: resourceOptions)
let mapView = MapView(frame: UIScreen.main.bounds, mapInitOptions: mapInitOptions)

let styleJSONObject: [String: Any] = [
"version": 8,
"center": [
-122.38556, 37.76333
],
"zoom": 15,
"sources": [],
"layers": []
]

let styleJSON: String = ValueConverter.toJson(forValue: styleJSONObject)
XCTAssertFalse(styleJSON.isEmpty, "ValueConverter should create valid JSON string.")

let styleLoadedExpectation = expectation(description: "Map loading error expectation")
styleLoadedExpectation.assertForOverFulfill = false

mapView.mapboxMap.onNext(.styleLoaded, handler: { _ in
styleLoadedExpectation.fulfill()
})

mapView.mapboxMap.loadStyleJSON(styleJSON)

wait(for: [styleLoadedExpectation], timeout: 1.0)

var coordinate = CLLocationCoordinate2D(latitude: 37.76333, longitude: -122.38556)
var expectedPoint = CGPoint(x: 187.5, y: 333.4999999980936)
var actualPoint = mapView.mapboxMap.point(for: coordinate)
XCTAssertEqual(actualPoint, expectedPoint, "Points should be equal.")

coordinate = CLLocationCoordinate2D(latitude: 37.42859, longitude: -122.12780)
expectedPoint = CGPoint(x: 187.5, y: 333.5000000009532)
actualPoint = mapView.mapboxMap.point(for: coordinate)
XCTAssertEqual(actualPoint, expectedPoint, "Points should be equal.")
}
}