summaryrefslogtreecommitdiff
path: root/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/integration/FragmentBackStackTest.kt
blob: b0f6436bdd84ceb782119c55608ecc13d413193a (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
package com.mapbox.mapboxsdk.integration

import android.support.test.filters.LargeTest
import android.support.test.rule.ActivityTestRule
import android.support.test.runner.AndroidJUnit4
import android.support.test.uiautomator.By
import android.support.test.uiautomator.SearchCondition
import android.support.test.uiautomator.UiSelector
import android.support.test.uiautomator.Until
import com.mapbox.mapboxsdk.testapp.R
import com.mapbox.mapboxsdk.testapp.activity.fragment.FragmentBackStackActivity
import com.mapbox.mapboxsdk.testapp.activity.maplayout.SimpleMapActivity
import kotlinx.android.synthetic.main.activity_backstack_fragment.view.*
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith

/**
 * Regression test that validates MapFragment integration on the backstack
 */
@RunWith(AndroidJUnit4::class)
class FragmentBackStackTest : BaseIntegrationTest() {

  @get:Rule
  var activityRule: ActivityTestRule<FragmentBackStackActivity> = ActivityTestRule(FragmentBackStackActivity::class.java)

  @Test
  @LargeTest
  fun backPressedOnBackStackResumed() {
    device.waitForIdle()
    clickReplaceFragmentButton()
    device.pressHome()
    device.waitForIdle()
    device.launchActivity(activityRule.activity.applicationContext, FragmentBackStackActivity::class.java)
    backPressBackStack()
    device.waitForIdle()
  }

  private fun clickReplaceFragmentButton() {
    device.findObject(UiSelector().description(textDescription)).click()
  }

  private fun backPressBackStack() {
    device.pressBack() // pops fragment, showing map
    device.pressBack() // finish activity
  }

  private companion object {
    const val textDescription = "btn_change_fragment"
  }
}