summaryrefslogtreecommitdiff
path: root/platform/ios/Integration Tests/MGLSourceTests.swift
blob: 69fa0182b5dd6e6b21565e78b6fe81e2a982d4b1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import XCTest

class MGLSourceTests: MGLMapViewIntegrationTest {

    // See testForRaisingExceptionsOnStaleStyleObjects for Obj-C sibling.
    func testForRaisingExceptionsOnStaleStyleObjectsOnRemoveFromMapView() {
        
        guard
            let configURL = URL(string: "mapbox://examples.2uf7qges") else {
                XCTFail()
                return
        }
        
        let source = MGLVectorTileSource(identifier: "trees", configurationURL: configURL)
        mapView.style?.addSource(source)
        
        let bundle = Bundle(for: type(of: self))
        
        guard let styleURL = bundle.url(forResource: "one-liner", withExtension: "json") else {
            XCTFail()
            return
        }
        
        styleLoadingExpectation = nil;

        mapView.centerCoordinate = CLLocationCoordinate2D(latitude : 38.897, longitude : -77.039)
        mapView.zoomLevel        = 10.5
        mapView.styleURL         = styleURL
        
        waitForMapViewToFinishLoadingStyle(withTimeout: 10.0)
        
        let expect = expectation(description: "Remove source should error")
        
        do {
            try mapView.style?.removeSource(source, error: ())
        }
        catch let error as NSError {
            XCTAssertEqual(error.domain, MGLErrorDomain)
            XCTAssertEqual(error.code, MGLErrorCode.sourceCannotBeRemovedFromStyle.rawValue)
            expect.fulfill()
        }
        
        wait(for: [expect], timeout: 0.1)
    }
}