From 6c3b4135c2dbc0113d48b3b49990fb17c5eb5deb Mon Sep 17 00:00:00 2001 From: Quentin Hibon Date: Fri, 29 Jan 2021 17:18:46 +0100 Subject: [PATCH] Implement test reproducing #713 --- .../uhabits/acceptance/steps/CommonSteps.kt | 4 ++ .../regression/HasButtonsViewAssertion.kt | 24 ++++++++ .../regression/ListHabitsRegressionTest.kt | 57 +++++++++++++++++++ .../habits/list/views/HabitCardView.kt | 2 +- 4 files changed, 86 insertions(+), 1 deletion(-) create mode 100644 uhabits-android/src/androidTest/java/org/isoron/uhabits/regression/HasButtonsViewAssertion.kt diff --git a/uhabits-android/src/androidTest/java/org/isoron/uhabits/acceptance/steps/CommonSteps.kt b/uhabits-android/src/androidTest/java/org/isoron/uhabits/acceptance/steps/CommonSteps.kt index 6ed7fa990..3726e2580 100644 --- a/uhabits-android/src/androidTest/java/org/isoron/uhabits/acceptance/steps/CommonSteps.kt +++ b/uhabits-android/src/androidTest/java/org/isoron/uhabits/acceptance/steps/CommonSteps.kt @@ -69,6 +69,10 @@ object CommonSteps : BaseUserInterfaceTest() { device.waitForIdle() } + fun offsetHeaders() { + device.swipe(750, 160, 600, 160, 20) + } + fun scrollToText(text: String?) { try { if (device diff --git a/uhabits-android/src/androidTest/java/org/isoron/uhabits/regression/HasButtonsViewAssertion.kt b/uhabits-android/src/androidTest/java/org/isoron/uhabits/regression/HasButtonsViewAssertion.kt new file mode 100644 index 000000000..9f5283b9c --- /dev/null +++ b/uhabits-android/src/androidTest/java/org/isoron/uhabits/regression/HasButtonsViewAssertion.kt @@ -0,0 +1,24 @@ +package org.isoron.uhabits.regression + +import android.view.View +import androidx.test.espresso.NoMatchingViewException +import androidx.test.espresso.ViewAssertion +import androidx.test.espresso.matcher.ViewMatchers.assertThat +import org.hamcrest.CoreMatchers.equalTo +import org.isoron.uhabits.activities.habits.list.views.HabitCardView + +class HasButtonsViewAssertion(private val buttons: List) : ViewAssertion { + override fun check(view: View?, noViewFoundException: NoMatchingViewException?) { + if (noViewFoundException != null) { + throw noViewFoundException + } + + if (view !is HabitCardView) { + throw IllegalStateException("Not an HabitCardView.") + } + + for (p in view.checkmarkPanel.buttons zip buttons) { + assertThat("", p.first.value, equalTo(p.second)) + } + } +} diff --git a/uhabits-android/src/androidTest/java/org/isoron/uhabits/regression/ListHabitsRegressionTest.kt b/uhabits-android/src/androidTest/java/org/isoron/uhabits/regression/ListHabitsRegressionTest.kt index 4e628e020..eeee3f8ba 100644 --- a/uhabits-android/src/androidTest/java/org/isoron/uhabits/regression/ListHabitsRegressionTest.kt +++ b/uhabits-android/src/androidTest/java/org/isoron/uhabits/regression/ListHabitsRegressionTest.kt @@ -19,7 +19,11 @@ package org.isoron.uhabits.regression +import androidx.test.espresso.Espresso +import androidx.test.espresso.matcher.ViewMatchers import androidx.test.filters.LargeTest +import org.hamcrest.CoreMatchers +import org.hamcrest.CoreMatchers.allOf import org.isoron.uhabits.BaseUserInterfaceTest import org.isoron.uhabits.acceptance.steps.CommonSteps.Screen.EDIT_HABIT import org.isoron.uhabits.acceptance.steps.CommonSteps.Screen.LIST_HABITS @@ -27,6 +31,8 @@ import org.isoron.uhabits.acceptance.steps.CommonSteps.Screen.SELECT_HABIT_TYPE import org.isoron.uhabits.acceptance.steps.CommonSteps.clickText import org.isoron.uhabits.acceptance.steps.CommonSteps.launchApp import org.isoron.uhabits.acceptance.steps.CommonSteps.longClickText +import org.isoron.uhabits.acceptance.steps.CommonSteps.offsetHeaders +import org.isoron.uhabits.acceptance.steps.CommonSteps.scrollToText import org.isoron.uhabits.acceptance.steps.CommonSteps.verifyDisplaysText import org.isoron.uhabits.acceptance.steps.CommonSteps.verifyShowsScreen import org.isoron.uhabits.acceptance.steps.EditHabitSteps.clickSave @@ -62,4 +68,55 @@ class ListHabitsRegressionTest : BaseUserInterfaceTest() { verifyDisplaysText("Hello world") longPressCheckmarks("Hello world", 3) } + + /** + * https://github.com/iSoron/uhabits/issues/713 + */ + @Test + @Throws(Exception::class) + fun should_update_out_of_screen_checkmarks_when_scrolling_horizontally() { + launchApp() + + verifyShowsScreen(LIST_HABITS) + longPressCheckmarks("Wake up early", 1) + + verifyShowsScreen(LIST_HABITS) + assertCorrectNumberCheckmarks(listOf(2, -1, -1, -1)) + + fun createHabit(habitName: String) { + clickMenu(ADD) + verifyShowsScreen(SELECT_HABIT_TYPE) + clickText("Yes or No") + + verifyShowsScreen(EDIT_HABIT) + typeName(habitName) + clickSave() + } + + createHabit("H") + createHabit("H") + createHabit("H") + createHabit("H") + createHabit("H") + createHabit("H") + createHabit("H") + createHabit("Last Habit") + + scrollToText("Last Habit") + offsetHeaders() + assertCorrectNumberCheckmarks(listOf(-1, -1, -1, -1)) + } + + private fun assertCorrectNumberCheckmarks(vals: List) { + val habit = "Wake up early" + + scrollToText(habit) + + Espresso.onView( + allOf( + ViewMatchers.hasDescendant(ViewMatchers.withText(habit)), + ViewMatchers.withClassName(CoreMatchers.endsWith("HabitCardView")) + ) + ).check(HasButtonsViewAssertion(vals)) + } } diff --git a/uhabits-android/src/main/java/org/isoron/uhabits/activities/habits/list/views/HabitCardView.kt b/uhabits-android/src/main/java/org/isoron/uhabits/activities/habits/list/views/HabitCardView.kt index 21d81faaf..23e2f11bf 100644 --- a/uhabits-android/src/main/java/org/isoron/uhabits/activities/habits/list/views/HabitCardView.kt +++ b/uhabits-android/src/main/java/org/isoron/uhabits/activities/habits/list/views/HabitCardView.kt @@ -114,7 +114,7 @@ class HabitCardView( numberPanel.threshold = value } - private var checkmarkPanel: CheckmarkPanelView + var checkmarkPanel: CheckmarkPanelView private var numberPanel: NumberPanelView private var innerFrame: LinearLayout private var label: TextView