From 5be2c51d7942758e33e168ecaf2786b502eac76a Mon Sep 17 00:00:00 2001 From: "Alinson S. Xavier" Date: Sat, 30 Jan 2021 19:22:32 -0600 Subject: [PATCH] Regression tests: minor code cleanup --- .../isoron/uhabits/acceptance/HabitsTest.kt | 4 +- .../uhabits/acceptance/steps/CommonSteps.kt | 19 +++++++ .../steps}/HasButtonsViewAssertion.kt | 2 +- .../regression/ListHabitsRegressionTest.kt | 54 ++++--------------- 4 files changed, 31 insertions(+), 48 deletions(-) rename uhabits-android/src/androidTest/java/org/isoron/uhabits/{regression => acceptance/steps}/HasButtonsViewAssertion.kt (94%) diff --git a/uhabits-android/src/androidTest/java/org/isoron/uhabits/acceptance/HabitsTest.kt b/uhabits-android/src/androidTest/java/org/isoron/uhabits/acceptance/HabitsTest.kt index c870d71ba..ed04edcea 100644 --- a/uhabits-android/src/androidTest/java/org/isoron/uhabits/acceptance/HabitsTest.kt +++ b/uhabits-android/src/androidTest/java/org/isoron/uhabits/acceptance/HabitsTest.kt @@ -177,7 +177,7 @@ class HabitsTest : BaseUserInterfaceTest() { fun shouldToggleCheckmarksAndUpdateScore() { launchApp() verifyShowsScreen(LIST_HABITS) - longPressCheckmarks("Wake up early", 2) + longPressCheckmarks("Wake up early", count = 2) clickText("Wake up early") verifyShowsScreen(SHOW_HABIT) verifyDisplaysText("10%") @@ -193,7 +193,7 @@ class HabitsTest : BaseUserInterfaceTest() { clickMenu(TOGGLE_COMPLETED) verifyDoesNotDisplayText("Track time") verifyDisplaysText("Wake up early") - longPressCheckmarks("Wake up early", 1) + longPressCheckmarks("Wake up early", count = 1) verifyDoesNotDisplayText("Wake up early") clickMenu(TOGGLE_COMPLETED) verifyDisplaysText("Track time") 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 3726e2580..0d2326337 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 @@ -155,6 +155,25 @@ object CommonSteps : BaseUserInterfaceTest() { } } + fun verifyDisplaysCheckmarks(habitName: String, vals: List) { + scrollToText(habitName) + Espresso.onView( + CoreMatchers.allOf( + ViewMatchers.hasDescendant(ViewMatchers.withText(habitName)), + ViewMatchers.withClassName(CoreMatchers.endsWith("HabitCardView")) + ) + ).check(HasButtonsViewAssertion(vals)) + } + + fun createHabit(habitName: String) { + ListHabitsSteps.clickMenu(ListHabitsSteps.MenuItem.ADD) + verifyShowsScreen(Screen.SELECT_HABIT_TYPE) + clickText("Yes or No") + verifyShowsScreen(Screen.EDIT_HABIT) + EditHabitSteps.typeName(habitName) + EditHabitSteps.clickSave() + } + enum class Screen { LIST_HABITS, SHOW_HABIT, EDIT_HABIT, SELECT_HABIT_TYPE } diff --git a/uhabits-android/src/androidTest/java/org/isoron/uhabits/regression/HasButtonsViewAssertion.kt b/uhabits-android/src/androidTest/java/org/isoron/uhabits/acceptance/steps/HasButtonsViewAssertion.kt similarity index 94% rename from uhabits-android/src/androidTest/java/org/isoron/uhabits/regression/HasButtonsViewAssertion.kt rename to uhabits-android/src/androidTest/java/org/isoron/uhabits/acceptance/steps/HasButtonsViewAssertion.kt index 9f5283b9c..c77960c7f 100644 --- a/uhabits-android/src/androidTest/java/org/isoron/uhabits/regression/HasButtonsViewAssertion.kt +++ b/uhabits-android/src/androidTest/java/org/isoron/uhabits/acceptance/steps/HasButtonsViewAssertion.kt @@ -1,4 +1,4 @@ -package org.isoron.uhabits.regression +package org.isoron.uhabits.acceptance.steps import android.view.View import androidx.test.espresso.NoMatchingViewException 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 eeee3f8ba..e1fc6d5cc 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,20 +19,18 @@ 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 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.createHabit 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.verifyDisplaysCheckmarks import org.isoron.uhabits.acceptance.steps.CommonSteps.verifyDisplaysText import org.isoron.uhabits.acceptance.steps.CommonSteps.verifyShowsScreen import org.isoron.uhabits.acceptance.steps.EditHabitSteps.clickSave @@ -41,6 +39,8 @@ import org.isoron.uhabits.acceptance.steps.ListHabitsSteps.MenuItem.ADD import org.isoron.uhabits.acceptance.steps.ListHabitsSteps.MenuItem.DELETE import org.isoron.uhabits.acceptance.steps.ListHabitsSteps.clickMenu import org.isoron.uhabits.acceptance.steps.ListHabitsSteps.longPressCheckmarks +import org.isoron.uhabits.core.models.Entry.Companion.UNKNOWN +import org.isoron.uhabits.core.models.Entry.Companion.YES_MANUAL import org.junit.Test @LargeTest @@ -56,17 +56,14 @@ class ListHabitsRegressionTest : BaseUserInterfaceTest() { longClickText("Track time") clickMenu(DELETE) clickText("Yes") - clickMenu(ADD) verifyShowsScreen(SELECT_HABIT_TYPE) clickText("Yes or No") - verifyShowsScreen(EDIT_HABIT) typeName("Hello world") clickSave() - verifyDisplaysText("Hello world") - longPressCheckmarks("Hello world", 3) + longPressCheckmarks("Hello world", count = 3) } /** @@ -76,47 +73,14 @@ class ListHabitsRegressionTest : BaseUserInterfaceTest() { @Throws(Exception::class) fun should_update_out_of_screen_checkmarks_when_scrolling_horizontally() { launchApp() - verifyShowsScreen(LIST_HABITS) - longPressCheckmarks("Wake up early", 1) - + longPressCheckmarks("Wake up early", count = 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") + verifyDisplaysCheckmarks("Wake up early", listOf(YES_MANUAL, UNKNOWN, UNKNOWN, UNKNOWN)) + for (i in 1..10) createHabit("Habit $i") 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)) + verifyDisplaysCheckmarks("Wake up early", listOf(UNKNOWN, UNKNOWN, UNKNOWN, UNKNOWN)) } }