package net.catzie.samplecalculatorapp
import android.support.test.uiautomator.UiDevice
import androidx.test.espresso.Espresso
import androidx.test.espresso.ViewInteraction
import androidx.test.espresso.action.ViewActions
import androidx.test.espresso.matcher.ViewMatchers
import androidx.test.ext.junit.rules.ActivityScenarioRule
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.platform.app.InstrumentationRegistry.getInstrumentation
import org.junit.Assert.*
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
/**
* Instrumented test, which will execute on an Android device.
*
* See [testing documentation](http://d.android.com/tools/testing).
*/
@RunWith(AndroidJUnit4::class)
class ValueRetainedInstrumentedTest {
@get:Rule
var activityRule: ActivityScenarioRule<MainActivity>
= ActivityScenarioRule(MainActivity::class.java)
@Test
fun test_ui_value_after_screen_rotation() {
Espresso.onView(ViewMatchers.withId(R.id.num_1)).perform(ViewActions.click())
Espresso.onView(ViewMatchers.withId(R.id.num_period)).perform(ViewActions.click())
Espresso.onView(ViewMatchers.withId(R.id.num_5)).perform(ViewActions.click())
val device = UiDevice.getInstance(getInstrumentation())
device.setOrientationLeft()
val displayPanel: ViewInteraction = Espresso.onView(ViewMatchers.withId(R.id.display_panel))
val displayPanelText = InstrumentedTestHelper.getText(displayPanel)
assertEquals("1.5", displayPanelText)
}
}