@@ -2,7 +2,7 @@ import XCTest
22import MapboxDirections
33import TestHelper
44import Turf
5- import MapboxMaps
5+ @ testable import MapboxMaps
66@testable import MapboxNavigation
77@testable import MapboxCoreNavigation
88
@@ -13,6 +13,7 @@ class NavigationMapViewTests: TestCase {
1313 ] ) )
1414 var navigationMapView : NavigationMapView !
1515 var navigator : CoreNavigator !
16+ var pointAnnotationManager : PointAnnotationManager !
1617
1718 let options : NavigationRouteOptions = . init( coordinates: [
1819 CLLocationCoordinate2D ( latitude: 40.311012 , longitude: - 112.47926 ) ,
@@ -22,11 +23,34 @@ class NavigationMapViewTests: TestCase {
2223 let route = response. routes!. first!
2324 return route
2425 } ( )
26+
27+ private let coordinate1 = CLLocationCoordinate2D ( latitude: 40.311012 , longitude: - 112.47926 )
28+ private let coordinate2 = CLLocationCoordinate2D ( latitude: 30.176322 , longitude: - 102.806108 )
29+ private let finalDestinationAnnotationTestPrefix = " MapboxNavigation-MapboxNavigation-resources_finalDestinationAnnotation "
30+
31+ private final class DisplayLinkCoordinatorSpy : DisplayLinkCoordinator {
32+ func add( _ participant: DisplayLinkParticipant ) { }
33+ func remove( _ participant: DisplayLinkParticipant ) { }
34+ }
35+
36+ private final class AnnotationImagesManagerSpy : AnnotationImagesManagerProtocol {
37+ func addImage( _ image: UIImage , id: String , sdf: Bool , contentInsets: UIEdgeInsets ) { }
38+ func removeImage( _ imageName: String ) { }
39+ func register( imagesConsumer: MapboxMaps . AnnotationImagesConsumer ) { }
40+ func unregister( imagesConsumer: MapboxMaps . AnnotationImagesConsumer ) { }
41+ }
2542
2643 override func setUp( ) {
2744 navigator = Navigator . shared
2845 super. setUp ( )
2946 navigationMapView = NavigationMapView ( frame: CGRect ( origin: . zero, size: . iPhone6Plus) )
47+ let mapboxMap = navigationMapView. mapView. mapboxMap!
48+ pointAnnotationManager = PointAnnotationManager ( id: " " ,
49+ style: mapboxMap. style,
50+ layerPosition: nil ,
51+ displayLinkCoordinator: DisplayLinkCoordinatorSpy ( ) ,
52+ imagesManager: AnnotationImagesManagerSpy ( ) ,
53+ offsetPointCalculator: OffsetPointCalculator ( mapboxMap: mapboxMap) )
3054 }
3155
3256 override func tearDown( ) {
@@ -587,6 +611,82 @@ class NavigationMapViewTests: TestCase {
587611 XCTAssertFalse ( style. layerExists ( withId: NavigationMapView . LayerIdentifier. intersectionAnnotationsLayer) )
588612 }
589613
614+ func testAddFinalDestinationWithDefaultIdentifierIfStyleNotLoaded( ) {
615+ XCTAssertTrue ( navigationMapView. finalDestinationAnnotations. isEmpty)
616+ XCTAssertTrue ( pointAnnotationManager. annotations. isEmpty)
617+
618+ navigationMapView. addDestinationAnnotation ( coordinate1)
619+ XCTAssertEqual ( navigationMapView. finalDestinationAnnotations. count, 1 )
620+ XCTAssertEqual ( navigationMapView. finalDestinationAnnotations [ 0 ] . id, " \( finalDestinationAnnotationTestPrefix) _0 " )
621+ XCTAssertTrue ( pointAnnotationManager. annotations. isEmpty)
622+
623+ navigationMapView. addDestinationAnnotation ( coordinate2)
624+ XCTAssertEqual ( navigationMapView. finalDestinationAnnotations. count, 2 )
625+ XCTAssertEqual ( navigationMapView. finalDestinationAnnotations [ 1 ] . id, " \( finalDestinationAnnotationTestPrefix) _1 " )
626+ XCTAssertTrue ( pointAnnotationManager. annotations. isEmpty)
627+ }
628+
629+ func testAddFinalDestinationWithCustomIdentifierIfStyleNotLoaded( ) {
630+ navigationMapView. addDestinationAnnotation ( coordinate1, identifier: " custom " )
631+ XCTAssertEqual ( navigationMapView. finalDestinationAnnotations. count, 1 )
632+ XCTAssertEqual ( navigationMapView. finalDestinationAnnotations [ 0 ] . id, " custom " )
633+ }
634+
635+ func testRemovesFinalDestinationIfStyleNotLoaded( ) {
636+ navigationMapView. addDestinationAnnotation ( coordinate1)
637+ navigationMapView. addDestinationAnnotation ( coordinate2)
638+
639+ navigationMapView. removeDestinationAnnotation ( identifier: " custom " )
640+ XCTAssertEqual ( navigationMapView. finalDestinationAnnotations. count, 2 )
641+
642+ navigationMapView. addDestinationAnnotation ( coordinate2, identifier: " custom " )
643+ XCTAssertEqual ( navigationMapView. finalDestinationAnnotations. count, 3 )
644+ navigationMapView. removeDestinationAnnotation ( identifier: " custom " )
645+ XCTAssertEqual ( navigationMapView. finalDestinationAnnotations. count, 2 )
646+
647+ navigationMapView. removeDestinationAnnotation ( )
648+ XCTAssertEqual ( navigationMapView. finalDestinationAnnotations. count, 0 )
649+ }
650+
651+ func testAddFinalDestinationWithDefaultIdentifierIfStyleLoaded( ) {
652+ navigationMapView. pointAnnotationManager = pointAnnotationManager
653+
654+ navigationMapView. addDestinationAnnotation ( coordinate1)
655+ XCTAssertTrue ( navigationMapView. finalDestinationAnnotations. isEmpty)
656+ XCTAssertEqual ( pointAnnotationManager. annotations. count, 1 )
657+ XCTAssertEqual ( pointAnnotationManager. annotations [ 0 ] . id, " \( finalDestinationAnnotationTestPrefix) _0 " )
658+
659+ navigationMapView. addDestinationAnnotation ( coordinate2)
660+ XCTAssertTrue ( navigationMapView. finalDestinationAnnotations. isEmpty)
661+ XCTAssertEqual ( pointAnnotationManager. annotations. count, 2 )
662+ XCTAssertEqual ( pointAnnotationManager. annotations [ 1 ] . id, " \( finalDestinationAnnotationTestPrefix) _1 " )
663+ }
664+
665+ func testAddFinalDestinationWithCustomIdentifierIfStyleLoaded( ) {
666+ navigationMapView. pointAnnotationManager = pointAnnotationManager
667+
668+ navigationMapView. addDestinationAnnotation ( coordinate1, identifier: " custom " )
669+ XCTAssertEqual ( pointAnnotationManager. annotations. count, 1 )
670+ XCTAssertEqual ( pointAnnotationManager. annotations [ 0 ] . id, " custom " )
671+ }
672+
673+ func testRemovesFinalDestinationIfStyleLoaded( ) {
674+ navigationMapView. pointAnnotationManager = pointAnnotationManager
675+ navigationMapView. addDestinationAnnotation ( coordinate1)
676+ navigationMapView. addDestinationAnnotation ( coordinate2)
677+
678+ navigationMapView. removeDestinationAnnotation ( identifier: " custom " )
679+ XCTAssertEqual ( pointAnnotationManager. annotations. count, 2 )
680+
681+ navigationMapView. addDestinationAnnotation ( coordinate2, identifier: " custom " )
682+ XCTAssertEqual ( pointAnnotationManager. annotations. count, 3 )
683+ navigationMapView. removeDestinationAnnotation ( identifier: " custom " )
684+ XCTAssertEqual ( pointAnnotationManager. annotations. count, 2 )
685+
686+ navigationMapView. removeDestinationAnnotation ( )
687+ XCTAssertEqual ( pointAnnotationManager. annotations. count, 0 )
688+ }
689+
590690 private func configureIntersections( ) {
591691 let style = navigationMapView. mapView. mapboxMap. style
592692 var source = GeoJSONSource ( )
0 commit comments