mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-06 09:08:52 -06:00
Regression tests: minor code cleanup
This commit is contained in:
@@ -177,7 +177,7 @@ class HabitsTest : BaseUserInterfaceTest() {
|
|||||||
fun shouldToggleCheckmarksAndUpdateScore() {
|
fun shouldToggleCheckmarksAndUpdateScore() {
|
||||||
launchApp()
|
launchApp()
|
||||||
verifyShowsScreen(LIST_HABITS)
|
verifyShowsScreen(LIST_HABITS)
|
||||||
longPressCheckmarks("Wake up early", 2)
|
longPressCheckmarks("Wake up early", count = 2)
|
||||||
clickText("Wake up early")
|
clickText("Wake up early")
|
||||||
verifyShowsScreen(SHOW_HABIT)
|
verifyShowsScreen(SHOW_HABIT)
|
||||||
verifyDisplaysText("10%")
|
verifyDisplaysText("10%")
|
||||||
@@ -193,7 +193,7 @@ class HabitsTest : BaseUserInterfaceTest() {
|
|||||||
clickMenu(TOGGLE_COMPLETED)
|
clickMenu(TOGGLE_COMPLETED)
|
||||||
verifyDoesNotDisplayText("Track time")
|
verifyDoesNotDisplayText("Track time")
|
||||||
verifyDisplaysText("Wake up early")
|
verifyDisplaysText("Wake up early")
|
||||||
longPressCheckmarks("Wake up early", 1)
|
longPressCheckmarks("Wake up early", count = 1)
|
||||||
verifyDoesNotDisplayText("Wake up early")
|
verifyDoesNotDisplayText("Wake up early")
|
||||||
clickMenu(TOGGLE_COMPLETED)
|
clickMenu(TOGGLE_COMPLETED)
|
||||||
verifyDisplaysText("Track time")
|
verifyDisplaysText("Track time")
|
||||||
|
|||||||
@@ -155,6 +155,25 @@ object CommonSteps : BaseUserInterfaceTest() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun verifyDisplaysCheckmarks(habitName: String, vals: List<Int>) {
|
||||||
|
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 {
|
enum class Screen {
|
||||||
LIST_HABITS, SHOW_HABIT, EDIT_HABIT, SELECT_HABIT_TYPE
|
LIST_HABITS, SHOW_HABIT, EDIT_HABIT, SELECT_HABIT_TYPE
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
package org.isoron.uhabits.regression
|
package org.isoron.uhabits.acceptance.steps
|
||||||
|
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import androidx.test.espresso.NoMatchingViewException
|
import androidx.test.espresso.NoMatchingViewException
|
||||||
@@ -19,20 +19,18 @@
|
|||||||
|
|
||||||
package org.isoron.uhabits.regression
|
package org.isoron.uhabits.regression
|
||||||
|
|
||||||
import androidx.test.espresso.Espresso
|
|
||||||
import androidx.test.espresso.matcher.ViewMatchers
|
|
||||||
import androidx.test.filters.LargeTest
|
import androidx.test.filters.LargeTest
|
||||||
import org.hamcrest.CoreMatchers
|
|
||||||
import org.hamcrest.CoreMatchers.allOf
|
|
||||||
import org.isoron.uhabits.BaseUserInterfaceTest
|
import org.isoron.uhabits.BaseUserInterfaceTest
|
||||||
import org.isoron.uhabits.acceptance.steps.CommonSteps.Screen.EDIT_HABIT
|
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.LIST_HABITS
|
||||||
import org.isoron.uhabits.acceptance.steps.CommonSteps.Screen.SELECT_HABIT_TYPE
|
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.clickText
|
||||||
|
import org.isoron.uhabits.acceptance.steps.CommonSteps.createHabit
|
||||||
import org.isoron.uhabits.acceptance.steps.CommonSteps.launchApp
|
import org.isoron.uhabits.acceptance.steps.CommonSteps.launchApp
|
||||||
import org.isoron.uhabits.acceptance.steps.CommonSteps.longClickText
|
import org.isoron.uhabits.acceptance.steps.CommonSteps.longClickText
|
||||||
import org.isoron.uhabits.acceptance.steps.CommonSteps.offsetHeaders
|
import org.isoron.uhabits.acceptance.steps.CommonSteps.offsetHeaders
|
||||||
import org.isoron.uhabits.acceptance.steps.CommonSteps.scrollToText
|
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.verifyDisplaysText
|
||||||
import org.isoron.uhabits.acceptance.steps.CommonSteps.verifyShowsScreen
|
import org.isoron.uhabits.acceptance.steps.CommonSteps.verifyShowsScreen
|
||||||
import org.isoron.uhabits.acceptance.steps.EditHabitSteps.clickSave
|
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.MenuItem.DELETE
|
||||||
import org.isoron.uhabits.acceptance.steps.ListHabitsSteps.clickMenu
|
import org.isoron.uhabits.acceptance.steps.ListHabitsSteps.clickMenu
|
||||||
import org.isoron.uhabits.acceptance.steps.ListHabitsSteps.longPressCheckmarks
|
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
|
import org.junit.Test
|
||||||
|
|
||||||
@LargeTest
|
@LargeTest
|
||||||
@@ -56,17 +56,14 @@ class ListHabitsRegressionTest : BaseUserInterfaceTest() {
|
|||||||
longClickText("Track time")
|
longClickText("Track time")
|
||||||
clickMenu(DELETE)
|
clickMenu(DELETE)
|
||||||
clickText("Yes")
|
clickText("Yes")
|
||||||
|
|
||||||
clickMenu(ADD)
|
clickMenu(ADD)
|
||||||
verifyShowsScreen(SELECT_HABIT_TYPE)
|
verifyShowsScreen(SELECT_HABIT_TYPE)
|
||||||
clickText("Yes or No")
|
clickText("Yes or No")
|
||||||
|
|
||||||
verifyShowsScreen(EDIT_HABIT)
|
verifyShowsScreen(EDIT_HABIT)
|
||||||
typeName("Hello world")
|
typeName("Hello world")
|
||||||
clickSave()
|
clickSave()
|
||||||
|
|
||||||
verifyDisplaysText("Hello world")
|
verifyDisplaysText("Hello world")
|
||||||
longPressCheckmarks("Hello world", 3)
|
longPressCheckmarks("Hello world", count = 3)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -76,47 +73,14 @@ class ListHabitsRegressionTest : BaseUserInterfaceTest() {
|
|||||||
@Throws(Exception::class)
|
@Throws(Exception::class)
|
||||||
fun should_update_out_of_screen_checkmarks_when_scrolling_horizontally() {
|
fun should_update_out_of_screen_checkmarks_when_scrolling_horizontally() {
|
||||||
launchApp()
|
launchApp()
|
||||||
|
|
||||||
verifyShowsScreen(LIST_HABITS)
|
verifyShowsScreen(LIST_HABITS)
|
||||||
longPressCheckmarks("Wake up early", 1)
|
longPressCheckmarks("Wake up early", count = 1)
|
||||||
|
|
||||||
verifyShowsScreen(LIST_HABITS)
|
verifyShowsScreen(LIST_HABITS)
|
||||||
assertCorrectNumberCheckmarks(listOf(2, -1, -1, -1))
|
verifyDisplaysCheckmarks("Wake up early", listOf(YES_MANUAL, UNKNOWN, UNKNOWN, UNKNOWN))
|
||||||
|
for (i in 1..10) createHabit("Habit $i")
|
||||||
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")
|
createHabit("Last Habit")
|
||||||
|
|
||||||
scrollToText("Last Habit")
|
scrollToText("Last Habit")
|
||||||
offsetHeaders()
|
offsetHeaders()
|
||||||
assertCorrectNumberCheckmarks(listOf(-1, -1, -1, -1))
|
verifyDisplaysCheckmarks("Wake up early", listOf(UNKNOWN, UNKNOWN, UNKNOWN, UNKNOWN))
|
||||||
}
|
|
||||||
|
|
||||||
private fun assertCorrectNumberCheckmarks(vals: List<Int>) {
|
|
||||||
val habit = "Wake up early"
|
|
||||||
|
|
||||||
scrollToText(habit)
|
|
||||||
|
|
||||||
Espresso.onView(
|
|
||||||
allOf(
|
|
||||||
ViewMatchers.hasDescendant(ViewMatchers.withText(habit)),
|
|
||||||
ViewMatchers.withClassName(CoreMatchers.endsWith("HabitCardView"))
|
|
||||||
)
|
|
||||||
).check(HasButtonsViewAssertion(vals))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user