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 cc871d23c..5a8fe8a4d 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 @@ -178,6 +178,22 @@ object CommonSteps : BaseUserInterfaceTest() { EditHabitSteps.clickSave() } + fun changeFrequencyToDaily(habitName: String) { + clickText(habitName) + Espresso.onView(ViewMatchers.withId(R.id.action_edit_habit)).perform(ViewActions.click()) + EditHabitSteps.pickDailyFrequency() + EditHabitSteps.clickSave() + pressBack() + } + + fun changeFrequencyToMonthly(habitName: String) { + clickText(habitName) + Espresso.onView(ViewMatchers.withId(R.id.action_edit_habit)).perform(ViewActions.click()) + EditHabitSteps.pickMonthFrequency() + EditHabitSteps.clickSave() + pressBack() + } + enum class Screen { LIST_HABITS, SHOW_HABIT, EDIT_HABIT, SELECT_HABIT_TYPE } diff --git a/uhabits-android/src/androidTest/java/org/isoron/uhabits/acceptance/steps/EditHabitSteps.kt b/uhabits-android/src/androidTest/java/org/isoron/uhabits/acceptance/steps/EditHabitSteps.kt index 05dfc586e..11c8cadf8 100644 --- a/uhabits-android/src/androidTest/java/org/isoron/uhabits/acceptance/steps/EditHabitSteps.kt +++ b/uhabits-android/src/androidTest/java/org/isoron/uhabits/acceptance/steps/EditHabitSteps.kt @@ -36,6 +36,24 @@ object EditHabitSteps { Espresso.onView(ViewMatchers.withText("SAVE")).perform(ViewActions.click()) } + fun pickMonthFrequency() { + Espresso.onView(ViewMatchers.withId(R.id.boolean_frequency_picker)) + .perform(ViewActions.click()) + Espresso.onView(ViewMatchers.withId(R.id.xTimesPerMonthRadioButton)) + .perform(ViewActions.click()) + Espresso.onView(ViewMatchers.withId(R.id.xTimesPerMonthTextView)) + .perform(ViewActions.replaceText("1")) + Espresso.onView(ViewMatchers.withText("SAVE")).perform(ViewActions.click()) + } + + fun pickDailyFrequency() { + Espresso.onView(ViewMatchers.withId(R.id.boolean_frequency_picker)) + .perform(ViewActions.click()) + Espresso.onView(ViewMatchers.withId(R.id.everyDayRadioButton)) + .perform(ViewActions.click()) + Espresso.onView(ViewMatchers.withText("SAVE")).perform(ViewActions.click()) + } + fun pickColor(color: Int) { Espresso.onView(ViewMatchers.withId(R.id.colorButton)).perform(ViewActions.click()) BaseUserInterfaceTest.device.findObject(By.descStartsWith(String.format("Color %d", color))) diff --git a/uhabits-android/src/androidTest/java/org/isoron/uhabits/acceptance/steps/ListHabitsSteps.kt b/uhabits-android/src/androidTest/java/org/isoron/uhabits/acceptance/steps/ListHabitsSteps.kt index 6c83d2d07..217eaa6be 100644 --- a/uhabits-android/src/androidTest/java/org/isoron/uhabits/acceptance/steps/ListHabitsSteps.kt +++ b/uhabits-android/src/androidTest/java/org/isoron/uhabits/acceptance/steps/ListHabitsSteps.kt @@ -120,6 +120,12 @@ object ListHabitsSteps { BaseUserInterfaceTest.device.waitForIdle() } + fun changeSort(sortText: String) { + clickViewWithId(R.id.action_filter) + Espresso.onView(ViewMatchers.withText("Sort")).perform(ViewActions.click()) + Espresso.onView(ViewMatchers.withText(sortText)).perform(ViewActions.click()) + } + enum class MenuItem { ABOUT, HELP, SETTINGS, EDIT, DELETE, ARCHIVE, TOGGLE_ARCHIVED, UNARCHIVE, TOGGLE_COMPLETED, ADD } 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 e1fc6d5cc..551c76c17 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 @@ -21,9 +21,12 @@ package org.isoron.uhabits.regression import androidx.test.filters.LargeTest import org.isoron.uhabits.BaseUserInterfaceTest +import org.isoron.uhabits.acceptance.steps.CommonSteps 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.changeFrequencyToDaily +import org.isoron.uhabits.acceptance.steps.CommonSteps.changeFrequencyToMonthly import org.isoron.uhabits.acceptance.steps.CommonSteps.clickText import org.isoron.uhabits.acceptance.steps.CommonSteps.createHabit import org.isoron.uhabits.acceptance.steps.CommonSteps.launchApp @@ -37,9 +40,12 @@ import org.isoron.uhabits.acceptance.steps.EditHabitSteps.clickSave import org.isoron.uhabits.acceptance.steps.EditHabitSteps.typeName 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.changeSort import org.isoron.uhabits.acceptance.steps.ListHabitsSteps.clickMenu import org.isoron.uhabits.acceptance.steps.ListHabitsSteps.longPressCheckmarks +import org.isoron.uhabits.core.models.Entry.Companion.NO import org.isoron.uhabits.core.models.Entry.Companion.UNKNOWN +import org.isoron.uhabits.core.models.Entry.Companion.YES_AUTO import org.isoron.uhabits.core.models.Entry.Companion.YES_MANUAL import org.junit.Test @@ -83,4 +89,37 @@ class ListHabitsRegressionTest : BaseUserInterfaceTest() { offsetHeaders() verifyDisplaysCheckmarks("Wake up early", listOf(UNKNOWN, UNKNOWN, UNKNOWN, UNKNOWN)) } + + /** + * https://github.com/iSoron/uhabits/issues/1131 + */ + @Test + @Throws(Exception::class) + fun should_refresh_sort_after_habit_edit() { + launchApp() + verifyShowsScreen(LIST_HABITS) + changeSort("By score") + changeSort("By status") + longPressCheckmarks("Meditate", count = 1) + changeFrequencyToMonthly("Read books") + longPressCheckmarks("Read books", count = 2) + longPressCheckmarks("Read books", count = 1) + verifyDisplaysCheckmarks("Meditate", listOf(YES_AUTO, YES_MANUAL, YES_AUTO, YES_MANUAL)) + CommonSteps.verifyDisplaysTextInSequence( + "Wake up early", + "Read books", + "Meditate", + "Track time" + ) + + changeFrequencyToDaily("Meditate") + + verifyDisplaysCheckmarks("Meditate", listOf(NO, YES_MANUAL, UNKNOWN, YES_MANUAL)) + CommonSteps.verifyDisplaysTextInSequence( + "Wake up early", + "Meditate", + "Read books", + "Track time", + ) + } }