aboutsummaryrefslogtreecommitdiff
path: root/sample/src/androidTest
diff options
context:
space:
mode:
authorAllan Wang <me@allanwang.ca>2018-02-23 20:52:21 -0500
committerGitHub <noreply@github.com>2018-02-23 20:52:21 -0500
commit3d7c85bd97261116a090a7202b0e0ed2625b5d73 (patch)
treef8d6409ef847a1ca0c0ba3640a27984703de470e /sample/src/androidTest
parent20f0d085d6940be30b076a8cff3de25fe4a6e21a (diff)
downloadkau-3d7c85bd97261116a090a7202b0e0ed2625b5d73.tar.gz
kau-3d7c85bd97261116a090a7202b0e0ed2625b5d73.tar.bz2
kau-3d7c85bd97261116a090a7202b0e0ed2625b5d73.zip
Misc (#140)
* Nullify task * Rewrite circle view * Add better encapsulation * Update annotations * Update kpref annotations * Begin writing tests for color picker * Add color selection tests * Update changelog * Cleanup
Diffstat (limited to 'sample/src/androidTest')
-rw-r--r--sample/src/androidTest/kotlin/ca/allanwang/kau/sample/ColorPickerTest.kt61
1 files changed, 61 insertions, 0 deletions
diff --git a/sample/src/androidTest/kotlin/ca/allanwang/kau/sample/ColorPickerTest.kt b/sample/src/androidTest/kotlin/ca/allanwang/kau/sample/ColorPickerTest.kt
new file mode 100644
index 0000000..39aee93
--- /dev/null
+++ b/sample/src/androidTest/kotlin/ca/allanwang/kau/sample/ColorPickerTest.kt
@@ -0,0 +1,61 @@
+package ca.allanwang.kau.sample
+
+import android.support.test.espresso.DataInteraction
+import android.support.test.espresso.Espresso.onData
+import android.support.test.espresso.Espresso.onView
+import android.support.test.espresso.ViewAssertion
+import android.support.test.espresso.action.ViewActions.click
+import android.support.test.espresso.matcher.ViewMatchers.withId
+import android.support.test.espresso.matcher.ViewMatchers.withText
+import android.support.test.filters.MediumTest
+import android.support.test.rule.ActivityTestRule
+import android.support.test.runner.AndroidJUnit4
+import android.view.View
+import ca.allanwang.kau.colorpicker.CircleView
+import org.hamcrest.Matchers.anything
+import org.junit.Rule
+import org.junit.Test
+import org.junit.runner.RunWith
+import kotlin.test.assertEquals
+import kotlin.test.fail
+
+
+/**
+ * Created by Allan Wang on 22/02/2018.
+ */
+@RunWith(AndroidJUnit4::class)
+@MediumTest
+class ColorPickerTest {
+
+ @get:Rule
+ val activity: ActivityTestRule<MainActivity> = ActivityTestRule(MainActivity::class.java)
+
+ private fun DataInteraction.click(position: Int) =
+ atPosition(position).perform(click())
+
+ private fun View.colorSelected(selected: Boolean) {
+ val circle = this as? CircleView ?: fail("View is not a CircleView")
+ assertEquals(selected, circle.colorSelected, "CircleView ${circle.tag} ${if (selected) "is not" else "is"} actually selected")
+ }
+
+ private val colorSelected = ViewAssertion { view, _ -> view.colorSelected(true) }
+
+ private val colorNotSelected = ViewAssertion { view, _ -> view.colorSelected(false) }
+
+ @Test
+ fun test() {
+ onView(withText(R.string.accent_color)).perform(click())
+ val colors = onData(anything()).inAdapterView(withId(R.id.md_grid))
+
+ colors.click(0).check(colorNotSelected) // enter sub grid
+ colors.click(0).check(colorSelected) // click first grid item
+ colors.atPosition(1).check(colorNotSelected)
+ colors.atPosition(2).check(colorNotSelected)
+ .perform(click()).check(colorSelected)
+ colors.atPosition(0).check(colorNotSelected)
+ .perform(click()).check(colorSelected)
+ // first item is now selected
+ }
+
+
+}