aboutsummaryrefslogtreecommitdiff
path: root/sample/src/androidTest/kotlin/ca/allanwang/kau/sample/KPrefViewTest.kt
diff options
context:
space:
mode:
Diffstat (limited to 'sample/src/androidTest/kotlin/ca/allanwang/kau/sample/KPrefViewTest.kt')
-rw-r--r--sample/src/androidTest/kotlin/ca/allanwang/kau/sample/KPrefViewTest.kt49
1 files changed, 33 insertions, 16 deletions
diff --git a/sample/src/androidTest/kotlin/ca/allanwang/kau/sample/KPrefViewTest.kt b/sample/src/androidTest/kotlin/ca/allanwang/kau/sample/KPrefViewTest.kt
index 72199cf..156b66f 100644
--- a/sample/src/androidTest/kotlin/ca/allanwang/kau/sample/KPrefViewTest.kt
+++ b/sample/src/androidTest/kotlin/ca/allanwang/kau/sample/KPrefViewTest.kt
@@ -34,7 +34,14 @@ import org.hamcrest.Matchers.allOf
import org.hamcrest.Matchers.instanceOf
import org.junit.Rule
import org.junit.Test
+import org.junit.rules.RuleChain
+import org.junit.rules.TestRule
import org.junit.runner.RunWith
+import org.koin.test.KoinTest
+import org.koin.test.inject
+import kotlin.test.BeforeTest
+import kotlin.test.assertFalse
+import kotlin.test.assertTrue
/**
* Created by Allan Wang on 21/12/2018.
@@ -43,11 +50,20 @@ import org.junit.runner.RunWith
*/
@RunWith(AndroidJUnit4::class)
@MediumTest
-class KPrefViewTest {
+class KPrefViewTest : KoinTest {
- @get:Rule
val activity: ActivityTestRule<MainActivity> = ActivityTestRule(MainActivity::class.java)
+ @get:Rule
+ val rule: TestRule = RuleChain.outerRule(SampleTestRule()).around(activity)
+
+ private val pref: KPrefSample by inject()
+
+ @BeforeTest
+ fun before() {
+ pref.reset()
+ }
+
fun verifyCheck(checked: Boolean): Matcher<View> {
return object : BoundedMatcher<View, View>(View::class.java) {
@@ -93,11 +109,11 @@ class KPrefViewTest {
fun basicCheckboxToggle() {
val checkbox1 = onCheckboxView(withChild(withText(R.string.checkbox_1)))
- val initiallyChecked = KPrefSample.check1
+ assertTrue(pref.check1, "check1 not normalized")
- checkbox1.verifyCheck("checkbox1 init", initiallyChecked)
+ checkbox1.verifyCheck("checkbox1 init", true)
checkbox1.perform(click())
- checkbox1.verifyCheck("checkbox1 after click", !initiallyChecked)
+ checkbox1.verifyCheck("checkbox1 after click", false)
}
/**
@@ -107,23 +123,24 @@ class KPrefViewTest {
fun dependentCheckboxToggle() {
val checkbox2 = onCheckboxView(withChild(withText(R.string.checkbox_2)))
val checkbox3 =
- onCheckboxView(withChild(withText(R.string.checkbox_3)), withChild(withText(R.string.desc_dependent)))
+ onCheckboxView(
+ withChild(withText(R.string.checkbox_3)),
+ withChild(withText(R.string.desc_dependent))
+ )
- // normalize so that both are checked
- if (!KPrefSample.check2)
- checkbox2.perform(click())
- if (!KPrefSample.check3)
- checkbox3.perform(click())
+ assertFalse(pref.check2, "check2 not normalized")
+ assertFalse(pref.check3, "check3 not normalized")
- checkbox3.verifyCheck("checkbox3 init", true, true)
+ checkbox2.verifyCheck("checkbox2 init", checked = false, enabled = true)
+ checkbox3.verifyCheck("checkbox3 init", checked = false, enabled = false)
checkbox3.perform(click())
- checkbox3.verifyCheck("checkbox3 after click", false, true)
+ checkbox3.verifyCheck("checkbox3 after disabled click", checked = false, enabled = false)
checkbox2.perform(click())
- checkbox2.verifyCheck("checkbox2 after click", false, true)
- checkbox3.verifyCheck("checkbox3 after checkbox2 click", false, false)
+ checkbox2.verifyCheck("checkbox2 after click", checked = true, enabled = true)
+ checkbox3.verifyCheck("checkbox3 after checkbox2 click", checked = false, enabled = true)
checkbox3.perform(click())
- checkbox3.verifyCheck("checkbox3 after disabled click", false, false)
+ checkbox3.verifyCheck("checkbox3 after enabled click", checked = true, enabled = true)
}
}