diff options
author | Allan Wang <me@allanwang.ca> | 2018-12-24 00:27:25 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-12-24 00:27:25 -0500 |
commit | a380adea1052d39f23c9c4d432a9380ce347d6c4 (patch) | |
tree | cdbb6835cdc3c04df24af2323341d765f64ab2e3 /sample/src | |
parent | 98a7f378399546086e23e25514b705e037068058 (diff) | |
download | kau-a380adea1052d39f23c9c4d432a9380ce347d6c4.tar.gz kau-a380adea1052d39f23c9c4d432a9380ce347d6c4.tar.bz2 kau-a380adea1052d39f23c9c4d432a9380ce347d6c4.zip |
Migrate to androidx (#178)
* Initial refactor
* Remove alpha version usages
* Update test code
* Add tests for checkbox
* Fix invalid card import
* Remove more old support content
* Update kotlin version
* Add back kotterknife with new imports
* Update docs
* Use bold notice
* Add changelog
* Remove deprecation for kotterknife
* Remove unused dependencies
* Update changelog
Diffstat (limited to 'sample/src')
8 files changed, 157 insertions, 18 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 index 39aee93..3b7f932 100644 --- a/sample/src/androidTest/kotlin/ca/allanwang/kau/sample/ColorPickerTest.kt +++ b/sample/src/androidTest/kotlin/ca/allanwang/kau/sample/ColorPickerTest.kt @@ -1,16 +1,16 @@ 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 androidx.test.espresso.DataInteraction +import androidx.test.espresso.Espresso.onData +import androidx.test.espresso.Espresso.onView +import androidx.test.espresso.ViewAssertion +import androidx.test.espresso.action.ViewActions.click +import androidx.test.espresso.matcher.ViewMatchers.withId +import androidx.test.espresso.matcher.ViewMatchers.withText +import androidx.test.filters.MediumTest +import androidx.test.rule.ActivityTestRule import android.view.View +import androidx.test.ext.junit.runners.AndroidJUnit4 import ca.allanwang.kau.colorpicker.CircleView import org.hamcrest.Matchers.anything import org.junit.Rule @@ -22,6 +22,8 @@ import kotlin.test.fail /** * Created by Allan Wang on 22/02/2018. + * + * Tests related to the :colorpicker module */ @RunWith(AndroidJUnit4::class) @MediumTest @@ -43,7 +45,7 @@ class ColorPickerTest { private val colorNotSelected = ViewAssertion { view, _ -> view.colorSelected(false) } @Test - fun test() { + fun colorClick() { onView(withText(R.string.accent_color)).perform(click()) val colors = onData(anything()).inAdapterView(withId(R.id.md_grid)) diff --git a/sample/src/androidTest/kotlin/ca/allanwang/kau/sample/KPrefViewTest.kt b/sample/src/androidTest/kotlin/ca/allanwang/kau/sample/KPrefViewTest.kt new file mode 100644 index 0000000..31dfcb3 --- /dev/null +++ b/sample/src/androidTest/kotlin/ca/allanwang/kau/sample/KPrefViewTest.kt @@ -0,0 +1,112 @@ +package ca.allanwang.kau.sample + +import android.view.View +import android.widget.CheckBox +import androidx.test.espresso.Espresso.onView +import androidx.test.espresso.ViewInteraction +import androidx.test.espresso.action.ViewActions.click +import androidx.test.espresso.assertion.ViewAssertions.matches +import androidx.test.espresso.matcher.BoundedMatcher +import androidx.test.espresso.matcher.ViewMatchers.withChild +import androidx.test.espresso.matcher.ViewMatchers.withText +import androidx.test.ext.junit.runners.AndroidJUnit4 +import androidx.test.filters.MediumTest +import androidx.test.rule.ActivityTestRule +import org.hamcrest.BaseMatcher +import org.hamcrest.Description +import org.hamcrest.Matcher +import org.hamcrest.Matchers.allOf +import org.hamcrest.Matchers.instanceOf +import org.junit.Rule +import org.junit.Test +import org.junit.runner.RunWith + + +/** + * Created by Allan Wang on 21/12/2018. + * + * Tests related to the :kpref-activity module + */ +@RunWith(AndroidJUnit4::class) +@MediumTest +class KPrefViewTest { + + @get:Rule + val activity: ActivityTestRule<MainActivity> = ActivityTestRule(MainActivity::class.java) + + fun verifyCheck(checked: Boolean): Matcher<View> { + return object : BoundedMatcher<View, View>(View::class.java) { + + + override fun describeTo(description: Description) { + description.appendText("Checkbox is ${if (checked) "checked" else "not checked"}") + } + + override fun matchesSafely(item: View): Boolean = item.findViewById<CheckBox>(R.id.kau_pref_inner_content).isChecked == checked + } + } + + inline fun <reified T : View> ViewInteraction.checkInnerContent(desc: String, crossinline matcher: (T) -> Boolean): ViewInteraction { + val viewMatcher = object : BaseMatcher<View>() { + override fun describeTo(description: Description) { + description.appendText(desc) + } + + override fun matches(item: Any?): Boolean { + val view = item as? View ?: return false + val inner = view.findViewById<View>(R.id.kau_pref_inner_content) as? T + ?: return false + return matcher(inner) + } + } + return check(matches(viewMatcher)) + } + + fun ViewInteraction.verifyCheck(tag: String, checked: Boolean, enabled: Boolean = true) = + checkInnerContent<CheckBox>("$tag should be ${if (checked) "checked" else "not checked"}") { + it.isChecked == checked + }.check { view, _ -> + ((view.alpha == 1f) == enabled) + } + + fun onCheckboxView(vararg matchers: Matcher<View>) = + onView(allOf(*matchers, withChild(withChild(instanceOf(CheckBox::class.java))))) + + @Test + fun basicCheckboxToggle() { + val checkbox1 = onCheckboxView(withChild(withText(R.string.checkbox_1))) + + val initiallyChecked = KPrefSample.check1 + + checkbox1.verifyCheck("checkbox1 init", initiallyChecked) + checkbox1.perform(click()) + checkbox1.verifyCheck("checkbox1 after click", !initiallyChecked) + } + + /** + * Note that checkbox3 depends on checkbox2 + */ + @Test + 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))) + + // normalize so that both are checked + if (!KPrefSample.check2) + checkbox2.perform(click()) + if (!KPrefSample.check3) + checkbox3.perform(click()) + + checkbox3.verifyCheck("checkbox3 init", true, true) + checkbox3.perform(click()) + checkbox3.verifyCheck("checkbox3 after click", false, true) + + checkbox2.perform(click()) + checkbox2.verifyCheck("checkbox2 after click", false, true) + checkbox3.verifyCheck("checkbox3 after checkbox2 click", false, false) + + checkbox3.perform(click()) + checkbox3.verifyCheck("checkbox3 after disabled click", false, false) + } + +} diff --git a/sample/src/androidTest/kotlin/ca/allanwang/kau/sample/utils/EspressoUtils.kt b/sample/src/androidTest/kotlin/ca/allanwang/kau/sample/utils/EspressoUtils.kt new file mode 100644 index 0000000..2acdc4d --- /dev/null +++ b/sample/src/androidTest/kotlin/ca/allanwang/kau/sample/utils/EspressoUtils.kt @@ -0,0 +1,22 @@ +package ca.allanwang.kau.sample.utils + +import org.hamcrest.BaseMatcher +import org.hamcrest.Description +import org.hamcrest.Matcher + +fun <T> index(index: Int, matcher: Matcher<T>): Matcher<T> = + object : BaseMatcher<T>() { + + var current = 0 + + override fun describeTo(description: Description) { + description.appendText("Should return item at index $index") + } + + override fun matches(item: Any?): Boolean { + println("AA") + return matcher.matches(item) && current++ == index + } + } + +fun <T> first(matcher: Matcher<T>): Matcher<T> = index(0, matcher) diff --git a/sample/src/main/AndroidManifest.xml b/sample/src/main/AndroidManifest.xml index d8bbe51..5846c6b 100644 --- a/sample/src/main/AndroidManifest.xml +++ b/sample/src/main/AndroidManifest.xml @@ -49,7 +49,7 @@ android:theme="@style/Kau.Translucent.SlideBottom" /> <provider - android:name="android.support.v4.content.FileProvider" + android:name="androidx.core.content.FileProvider" android:authorities="${applicationId}.provider" android:exported="false" android:grantUriPermissions="true"> diff --git a/sample/src/main/kotlin/ca/allanwang/kau/sample/MediaPicker.kt b/sample/src/main/kotlin/ca/allanwang/kau/sample/MediaPicker.kt index 42de62c..820d22f 100644 --- a/sample/src/main/kotlin/ca/allanwang/kau/sample/MediaPicker.kt +++ b/sample/src/main/kotlin/ca/allanwang/kau/sample/MediaPicker.kt @@ -2,7 +2,7 @@ package ca.allanwang.kau.sample import android.content.Context import android.net.Uri -import android.support.v4.content.FileProvider +import androidx.core.content.FileProvider import ca.allanwang.kau.mediapicker.* import java.io.File diff --git a/sample/src/main/kotlin/ca/allanwang/kau/sample/PermissionCheckbox.kt b/sample/src/main/kotlin/ca/allanwang/kau/sample/PermissionCheckbox.kt index beb1a29..09401cd 100644 --- a/sample/src/main/kotlin/ca/allanwang/kau/sample/PermissionCheckbox.kt +++ b/sample/src/main/kotlin/ca/allanwang/kau/sample/PermissionCheckbox.kt @@ -1,6 +1,6 @@ package ca.allanwang.kau.sample -import android.support.v7.widget.RecyclerView +import androidx.recyclerview.widget.RecyclerView import android.view.View import android.widget.CheckBox import android.widget.TextView diff --git a/sample/src/main/res/layout/activity_swipe.xml b/sample/src/main/res/layout/activity_swipe.xml index c65bebc..dd52325 100644 --- a/sample/src/main/res/layout/activity_swipe.xml +++ b/sample/src/main/res/layout/activity_swipe.xml @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="utf-8"?> -<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" +<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/swipe_container" @@ -8,7 +8,7 @@ tools:context=".SwipeActivity" tools:ignore="HardcodedText"> - <android.support.v7.widget.Toolbar + <androidx.appcompat.widget.Toolbar android:id="@+id/swipe_toolbar" android:layout_width="0dp" android:layout_height="?attr/actionBarSize" @@ -71,4 +71,4 @@ app:layout_constraintVertical_bias="0.75" /> -</android.support.constraint.ConstraintLayout>
\ No newline at end of file +</androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file diff --git a/sample/src/main/res/xml/kau_changelog.xml b/sample/src/main/res/xml/kau_changelog.xml index f6ec799..6c0fea1 100644 --- a/sample/src/main/res/xml/kau_changelog.xml +++ b/sample/src/main/res/xml/kau_changelog.xml @@ -6,6 +6,10 @@ <item text="" /> --> + <version title="v4.0.0-alpha01" /> + <item text="Migrate to androidx. See migration for external dependency changes." /> + <item text=":core: Remove deprecation warning for Kotterknife" /> + <version title="v3.8.0" /> <item text="Update everything to Android Studio 3.1" /> <item text="Fix new lint issues (see Migration for resource related methods)" /> @@ -13,7 +17,6 @@ <item text=":core: Deprecate Kotterknife; use kotlin_android_extensions" /> <item text=":kpref-activity: Fix seekbar increment" /> <item text=":core: Make KPref use Set<String> vs StringSet" /> - <item text="" /> <version title="v3.7.1" /> <item text="Update appcompat to 27.1.0" /> |