-
Notifications
You must be signed in to change notification settings - Fork 148
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6eeaa79
commit 07f68d0
Showing
2 changed files
with
112 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
import UIKit | ||
import MapboxMaps | ||
import MapKit | ||
|
||
@objc(FeatureStateExample) | ||
|
||
|
112 changes: 112 additions & 0 deletions
112
Tests/MapboxMapsTests/Foundation/Integration Tests/FeatureStateIntegrationTests.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
import Turf | ||
import XCTest | ||
@testable import MapboxMaps | ||
|
||
internal class FeatureStateIntegrationTests: MapViewIntegrationTestCase { | ||
|
||
internal func testSetFeatureState() { | ||
style?.uri = .streets | ||
let featureStateExpectation = XCTestExpectation(description: "Wait for feature state map to be updated.") | ||
|
||
didFinishLoadingStyle = { mapView in | ||
|
||
do { | ||
try mapView.mapboxMap.style.addSource( | ||
makeGeoJSONSource(), | ||
id: "test-source") | ||
try mapView.mapboxMap.style.addLayer( | ||
makeLayer()) | ||
|
||
} catch { | ||
XCTFail("Failed to add geojson source / layer due to error: \(error)") | ||
} | ||
} | ||
|
||
|
||
didBecomeIdle = { mapView in | ||
mapView.mapboxMap.setFeatureState(sourceId: "test-source", featureId: "0", state: ["testKey": true]) | ||
|
||
DispatchQueue.main.asyncAfter(deadline: .now() + 1) { [weak mapView] in | ||
mapView?.mapboxMap.getFeatureState(sourceId: "test-source", featureId: "0") { result in | ||
switch result { | ||
case .success(let map): | ||
XCTAssertEqual(map["testKey"] as? Bool, true) | ||
featureStateExpectation.fulfill() | ||
case .failure(let error): | ||
XCTFail("Could not retrieve feature state: \(error)") | ||
} | ||
} | ||
} | ||
} | ||
|
||
wait(for: [featureStateExpectation], timeout: 5.0) | ||
} | ||
|
||
internal func testRemoveFeatureState() { | ||
style?.uri = .streets | ||
let featureStateExpectation = XCTestExpectation(description: "Wait for feature state map to be updated.") | ||
|
||
didFinishLoadingStyle = { mapView in | ||
do { | ||
try mapView.mapboxMap.style.addSource( | ||
makeGeoJSONSource(), | ||
id: "test-source") | ||
try mapView.mapboxMap.style.addLayer( | ||
makeLayer()) | ||
} catch { | ||
XCTFail("Failed to add geojson source / layer due to error: \(error)") | ||
} | ||
} | ||
|
||
didBecomeIdle = { mapView in | ||
mapView.mapboxMap.setFeatureState(sourceId: "test-source", featureId: "0", state: ["testKey": true]) | ||
|
||
DispatchQueue.main.asyncAfter(deadline: .now() + 1) { [weak mapView] in | ||
|
||
|
||
mapView?.mapboxMap.removeFeatureState(sourceId: "test-source", featureId: "0") | ||
|
||
DispatchQueue.main.asyncAfter(deadline: .now() + 1) { [weak mapView] in | ||
mapView?.mapboxMap.getFeatureState( | ||
sourceId: "test-source", | ||
featureId: "0") { result in | ||
|
||
switch result { | ||
case .success(let map): | ||
XCTAssert(map.isEmpty) | ||
featureStateExpectation.fulfill() | ||
case .failure(let error): | ||
XCTFail("Could not retrieve feature state: \(error)") | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
wait(for: [featureStateExpectation], timeout: 5.0) | ||
} | ||
|
||
// MARK:- Helper | ||
|
||
fileprivate func makeGeoJSONSource() -> GeoJSONSource { | ||
|
||
let coord = CLLocationCoordinate2D(latitude: 14.765625, | ||
longitude: 26.194876675795218) | ||
let point = Turf.Point(coord) | ||
let feature = Turf.Feature(point) | ||
|
||
var geojsonSource = GeoJSONSource() | ||
geojsonSource.generateId = true | ||
geojsonSource.data = .feature(feature) | ||
|
||
return geojsonSource | ||
} | ||
|
||
fileprivate func makeLayer() -> SymbolLayer { | ||
var symbolLayer = SymbolLayer(id: "test-layer") | ||
symbolLayer.source = "test-source" | ||
symbolLayer.textField = .constant("test") | ||
|
||
return symbolLayer | ||
} | ||
} |