summaryrefslogtreecommitdiff
path: root/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/maps/StyleLoadTest.kt
blob: 10be2f36ecbefad65983390460f4499e174441be (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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package com.mapbox.mapboxsdk.testapp.maps

import android.support.test.espresso.UiController
import android.support.test.runner.AndroidJUnit4
import com.mapbox.mapboxsdk.maps.MapView
import com.mapbox.mapboxsdk.maps.MapboxMap
import com.mapbox.mapboxsdk.maps.Style
import com.mapbox.mapboxsdk.style.layers.SymbolLayer
import com.mapbox.mapboxsdk.style.sources.GeoJsonSource
import com.mapbox.mapboxsdk.testapp.action.MapboxMapAction.invoke
import com.mapbox.mapboxsdk.testapp.activity.EspressoTest
import com.mapbox.mapboxsdk.testapp.activity.espresso.EspressoTestActivity
import com.mapbox.mapboxsdk.testapp.utils.TestingAsyncUtils
import junit.framework.Assert
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith

@RunWith(AndroidJUnit4::class)
class StyleLoadTest : EspressoTest() {

    private lateinit var mapView: MapView

    @Before
    override fun beforeTest() {
        super.beforeTest()
        mapView = (rule.activity as EspressoTestActivity).mapView
    }

    @Test
    fun updateSourceAfterStyleLoad() {
        validateTestSetup()
        invoke(mapboxMap) { uiController: UiController, mapboxMap: MapboxMap ->
            val source = GeoJsonSource("id")
            val layer = SymbolLayer("id", "id")
            mapboxMap.setStyle(Style.Builder().withSource(source).withLayer(layer))
            TestingAsyncUtils.waitForLayer(uiController, mapView)
            mapboxMap.setStyle(Style.Builder().fromUrl(Style.MAPBOX_STREETS))
            TestingAsyncUtils.waitForLayer(uiController, mapView)
            source.setGeoJson("{}")
        }
    }

    @Test
    fun loadingNewStyle_sourcesDetached() {
        invoke(mapboxMap) { _: UiController, mapboxMap: MapboxMap ->
            val sources = mapboxMap.style!!.sources
            mapboxMap.setStyle(Style.DARK)
            for (source in sources) {
                Assert.assertTrue(source.nativeIsDetached())
            }
        }
    }

    @Test
    fun loadingNewStyle_layersDetached() {
        invoke(mapboxMap) { _: UiController, mapboxMap: MapboxMap ->
            val layers = mapboxMap.style!!.layers
            mapboxMap.setStyle(Style.DARK)
            for (layer in layers) {
                Assert.assertTrue(layer.nativeIsDetached())
            }
        }
    }
}