diff options
author | Allan Wang <me@allanwang.ca> | 2018-02-23 20:52:21 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-02-23 20:52:21 -0500 |
commit | 3d7c85bd97261116a090a7202b0e0ed2625b5d73 (patch) | |
tree | f8d6409ef847a1ca0c0ba3640a27984703de470e /sample/src | |
parent | 20f0d085d6940be30b076a8cff3de25fe4a6e21a (diff) | |
download | kau-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')
-rw-r--r-- | sample/src/androidTest/kotlin/ca/allanwang/kau/sample/ColorPickerTest.kt | 61 | ||||
-rw-r--r-- | sample/src/main/res/xml/kau_changelog.xml | 6 |
2 files changed, 65 insertions, 2 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 + } + + +} diff --git a/sample/src/main/res/xml/kau_changelog.xml b/sample/src/main/res/xml/kau_changelog.xml index 146042c..40ca6a0 100644 --- a/sample/src/main/res/xml/kau_changelog.xml +++ b/sample/src/main/res/xml/kau_changelog.xml @@ -9,7 +9,9 @@ <version title="v3.6.4" /> <item text=":core: Fix potential NPE in restart()" /> <item text=":core: Create restartApplication()" /> - <item text="" /> + <item text=":colorpicker: Rewrote implementation to be null and parse safe" /> + <item text=":colorpicker: Added more encapsulation to CircleView (selected -> colorSelected; all others are private)" /> + <item text=":colorpicker:" /> <item text="Update documentation" /> <item text="" /> @@ -224,6 +226,6 @@ <version title="v1.0" /> <item text="Initial Changelog" /> <item text="Create many extension functions" /> - <item text="Port changelog builer" /> + <item text="Port changelog builder" /> <item text="Port ripple canvas" /> </resources>
\ No newline at end of file |