From 50f754d7493e4ee07d39926617b219073a815f8f Mon Sep 17 00:00:00 2001 From: razeeman Date: Sun, 7 Jan 2024 10:41:54 +0300 Subject: [PATCH] add days of week goal tests --- .../util/simpletimetracker/GoalsDaysOfWeek.kt | 305 ++++++++++++++++++ .../simpletimetracker/GoalsOnCardsTest.kt | 56 +--- .../simpletimetracker/GoalsRunningTest.kt | 79 ++--- .../simpletimetracker/GoalsStatisticsTest.kt | 220 +++++++------ .../util/simpletimetracker/GoalsTabTest.kt | 68 ++-- .../util/simpletimetracker/GoalsTestUtils.kt | 71 +++- 6 files changed, 560 insertions(+), 239 deletions(-) create mode 100644 app/src/androidTest/java/com/example/util/simpletimetracker/GoalsDaysOfWeek.kt diff --git a/app/src/androidTest/java/com/example/util/simpletimetracker/GoalsDaysOfWeek.kt b/app/src/androidTest/java/com/example/util/simpletimetracker/GoalsDaysOfWeek.kt new file mode 100644 index 000000000..d27489f47 --- /dev/null +++ b/app/src/androidTest/java/com/example/util/simpletimetracker/GoalsDaysOfWeek.kt @@ -0,0 +1,305 @@ +package com.example.util.simpletimetracker + +import android.view.View +import androidx.test.espresso.Espresso.pressBack +import androidx.test.espresso.ViewInteraction +import androidx.test.espresso.matcher.ViewMatchers.hasDescendant +import androidx.test.espresso.matcher.ViewMatchers.isDescendantOfA +import androidx.test.espresso.matcher.ViewMatchers.withId +import androidx.test.espresso.matcher.ViewMatchers.withText +import androidx.test.ext.junit.runners.AndroidJUnit4 +import com.example.util.simpletimetracker.GoalsTestUtils.checkNoRunningGoal +import com.example.util.simpletimetracker.GoalsTestUtils.checkNoStatisticsGoal +import com.example.util.simpletimetracker.GoalsTestUtils.checkNoTypeMark +import com.example.util.simpletimetracker.GoalsTestUtils.checkRunningGoal +import com.example.util.simpletimetracker.GoalsTestUtils.checkStatisticsGoal +import com.example.util.simpletimetracker.GoalsTestUtils.checkTypeMark +import com.example.util.simpletimetracker.core.R +import com.example.util.simpletimetracker.data_local.utils.removeIf +import com.example.util.simpletimetracker.utils.BaseUiTest +import com.example.util.simpletimetracker.utils.NavUtils +import com.example.util.simpletimetracker.utils.checkViewDoesNotExist +import com.example.util.simpletimetracker.utils.checkViewIsDisplayed +import com.example.util.simpletimetracker.utils.clickOnView +import com.example.util.simpletimetracker.utils.clickOnViewWithId +import com.example.util.simpletimetracker.utils.clickOnViewWithText +import com.example.util.simpletimetracker.utils.longClickOnView +import com.example.util.simpletimetracker.utils.scrollRecyclerInPagerToView +import com.example.util.simpletimetracker.utils.tryAction +import com.example.util.simpletimetracker.utils.withCardColor +import dagger.hilt.android.testing.HiltAndroidTest +import org.hamcrest.CoreMatchers.allOf +import org.hamcrest.Matcher +import org.junit.Test +import org.junit.runner.RunWith +import java.util.Calendar +import java.util.concurrent.TimeUnit +import com.example.util.simpletimetracker.feature_change_record_type.R as changeRecordTypeR +import com.example.util.simpletimetracker.feature_dialogs.R as dialogsR +import com.example.util.simpletimetracker.feature_statistics.R as statisticsR + +@HiltAndroidTest +@RunWith(AndroidJUnit4::class) +class GoalsDaysOfWeek : BaseUiTest() { + + @Test + fun daysVisibility() { + fun checkString( + layoutId: Int, + textMatcher: Matcher, + visibilityMatcher: (Matcher) -> ViewInteraction, + ) { + visibilityMatcher(allOf(textMatcher, isDescendantOfA(withId(layoutId)))) + } + + val name = "Test" + + // Add data + testUtils.addActivity( + name = name, + goals = listOf( + GoalsTestUtils.getSessionDurationGoal(1), + GoalsTestUtils.getDailyDurationGoal(1), + GoalsTestUtils.getWeeklyDurationGoal(1), + GoalsTestUtils.getMonthlyDurationGoal(1), + ), + ) + Thread.sleep(1000) + + // Check + tryAction { longClickOnView(withText(name)) } + clickOnViewWithText(R.string.change_record_type_goal_time_hint) + + checkString( + changeRecordTypeR.id.layoutChangeRecordTypeGoalSession, + withText("1$secondString"), + ::checkViewIsDisplayed, + ) + checkString( + changeRecordTypeR.id.layoutChangeRecordTypeGoalSession, + withText(R.string.day_of_week_sunday), + ::checkViewDoesNotExist, + ) + + checkString( + changeRecordTypeR.id.layoutChangeRecordTypeGoalDaily, + withText("1$secondString"), + ::checkViewIsDisplayed, + ) + checkString( + changeRecordTypeR.id.layoutChangeRecordTypeGoalDaily, + withText(R.string.day_of_week_sunday), + ::checkViewIsDisplayed, + ) + + checkString( + changeRecordTypeR.id.layoutChangeRecordTypeGoalWeekly, + withText("1$secondString"), + ::checkViewIsDisplayed, + ) + checkString( + changeRecordTypeR.id.layoutChangeRecordTypeGoalWeekly, + withText(R.string.day_of_week_sunday), + ::checkViewDoesNotExist, + ) + + checkString( + changeRecordTypeR.id.layoutChangeRecordTypeGoalMonthly, + withText("1$secondString"), + ::checkViewIsDisplayed, + ) + checkString( + changeRecordTypeR.id.layoutChangeRecordTypeGoalMonthly, + withText(R.string.day_of_week_sunday), + ::checkViewDoesNotExist, + ) + } + + @Test + fun changeDays() { + val name = "Test" + + // Add data + testUtils.addActivity(name) + Thread.sleep(1000) + tryAction { longClickOnView(withText(name)) } + + // No days by default + clickOnViewWithText(R.string.change_record_type_goal_time_hint) + checkViewDoesNotExist(withText(R.string.day_of_week_sunday)) + + // Set goal + clickOnView( + allOf( + isDescendantOfA(withId(changeRecordTypeR.id.layoutChangeRecordTypeGoalDaily)), + withId(changeRecordTypeR.id.fieldChangeRecordTypeGoalDuration), + ), + ) + clickOnViewWithId(dialogsR.id.tvNumberKeyboard1) + clickOnViewWithText(R.string.duration_dialog_save) + + checkViewIsDisplayed(withText("1$secondString")) + daysResIdList.forEach { checkTypeDay(stringResId = it, colorResId = R.color.colorActive) } + + // Disable goal + clickOnView( + allOf( + isDescendantOfA(withId(changeRecordTypeR.id.layoutChangeRecordTypeGoalDaily)), + withId(changeRecordTypeR.id.fieldChangeRecordTypeGoalDuration), + ), + ) + clickOnViewWithText(R.string.duration_dialog_disable) + checkViewDoesNotExist(withText(R.string.day_of_week_sunday)) + + // Change days + clickOnView( + allOf( + isDescendantOfA(withId(changeRecordTypeR.id.layoutChangeRecordTypeGoalDaily)), + withId(changeRecordTypeR.id.fieldChangeRecordTypeGoalDuration), + ), + ) + clickOnViewWithId(dialogsR.id.tvNumberKeyboard1) + clickOnViewWithText(R.string.duration_dialog_save) + + daysResIdList.forEach { + clickOnView(withText(it)) + checkTypeDay(stringResId = it, colorResId = R.color.colorInactive) + clickOnView(withText(it)) + checkTypeDay(stringResId = it, colorResId = R.color.colorActive) + } + + clickOnView(withText(R.string.day_of_week_monday)) + clickOnView(withText(R.string.day_of_week_wednesday)) + clickOnView(withText(R.string.day_of_week_friday)) + checkTypeDay(stringResId = R.string.day_of_week_sunday, colorResId = R.color.colorActive) + checkTypeDay(stringResId = R.string.day_of_week_monday, colorResId = R.color.colorInactive) + checkTypeDay(stringResId = R.string.day_of_week_tuesday, colorResId = R.color.colorActive) + checkTypeDay(stringResId = R.string.day_of_week_wednesday, colorResId = R.color.colorInactive) + checkTypeDay(stringResId = R.string.day_of_week_thursday, colorResId = R.color.colorActive) + checkTypeDay(stringResId = R.string.day_of_week_friday, colorResId = R.color.colorInactive) + checkTypeDay(stringResId = R.string.day_of_week_saturday, colorResId = R.color.colorActive) + } + + @Test + fun daysAreSaved() { + val name1 = "Test1" + val name2 = "Test2" + + // Add data + testUtils.addActivity( + name = name1, + goals = listOf(GoalsTestUtils.getDailyDurationGoal(1)), + ) + testUtils.addActivity( + name = name2, + goals = listOf(GoalsTestUtils.getDailyDurationGoal(1)), + ) + Thread.sleep(1000) + + // Change days + tryAction { longClickOnView(withText(name1)) } + clickOnViewWithText(R.string.change_record_type_goal_time_hint) + clickOnView(withText(R.string.day_of_week_monday)) + clickOnView(withText(R.string.day_of_week_wednesday)) + clickOnView(withText(R.string.day_of_week_friday)) + clickOnViewWithText(R.string.change_record_type_save) + + // Days are saved + tryAction { longClickOnView(withText(name1)) } + clickOnViewWithText(R.string.change_record_type_goal_time_hint) + checkTypeDay(stringResId = R.string.day_of_week_sunday, colorResId = R.color.colorActive) + checkTypeDay(stringResId = R.string.day_of_week_monday, colorResId = R.color.colorInactive) + checkTypeDay(stringResId = R.string.day_of_week_tuesday, colorResId = R.color.colorActive) + checkTypeDay(stringResId = R.string.day_of_week_wednesday, colorResId = R.color.colorInactive) + checkTypeDay(stringResId = R.string.day_of_week_thursday, colorResId = R.color.colorActive) + checkTypeDay(stringResId = R.string.day_of_week_friday, colorResId = R.color.colorInactive) + checkTypeDay(stringResId = R.string.day_of_week_saturday, colorResId = R.color.colorActive) + pressBack() + + tryAction { longClickOnView(withText(name2)) } + clickOnViewWithText(R.string.change_record_type_goal_time_hint) + daysResIdList.forEach { checkTypeDay(stringResId = it, colorResId = R.color.colorActive) } + } + + @Test + fun daysAreWorking() { + val dailyGoalHint = getString(R.string.change_record_type_daily_goal_time).lowercase() + val goalHint = getString(R.string.change_record_type_goal_time_hint).lowercase() + val currentDay = Calendar.getInstance() + .get(Calendar.DAY_OF_WEEK) + .let(timeMapper::toDayOfWeek) + + val name1 = "name1" + val name2 = "name2" + + // Add data + val goal = GoalsTestUtils.getDailyDurationGoal(TimeUnit.HOURS.toSeconds(1)) + testUtils.addActivity( + name = name1, + goals = listOf( + goal.copy(daysOfWeek = goal.daysOfWeek.removeIf { it == currentDay }), + ), + ) + testUtils.addActivity( + name = name2, + goals = listOf(goal), + ) + testUtils.addRunningRecord(name1) + testUtils.addRunningRecord(name2) + Thread.sleep(1000) + + // Checkmark on type + tryAction { checkNoTypeMark(name1) } + checkTypeMark(name2, isVisible = false) + + // Running record + checkNoRunningGoal(name1) + checkRunningGoal(name2, "$dailyGoalHint 59$minuteString") + + // Statistics + NavUtils.openStatisticsScreen() + checkNoStatisticsGoal(name1) + scrollTo(name2) + checkStatisticsGoal(name2, secondString, "$goalHint - 1$hourString 0$minuteString") + + clickOnViewWithId(statisticsR.id.btnStatisticsContainerPrevious) + scrollTo(name1) + checkStatisticsGoal(name1, "0$secondString", "$goalHint - 1$hourString 0$minuteString") + scrollTo(name2) + checkStatisticsGoal(name2, "0$secondString", "$goalHint - 1$hourString 0$minuteString") + } + + private fun checkTypeDay( + stringResId: Int, + colorResId: Int, + ) { + checkViewIsDisplayed( + allOf( + withId(R.id.containerDayOfWeekItem), + withCardColor(colorResId), + hasDescendant(withText(stringResId)), + ), + ) + } + + private fun scrollTo(typeName: String) { + tryAction { + scrollRecyclerInPagerToView( + statisticsR.id.rvStatisticsList, + allOf(withId(R.id.viewStatisticsGoalItem), hasDescendant(withText(typeName))), + ) + } + } + + companion object { + private val daysResIdList = listOf( + R.string.day_of_week_sunday, + R.string.day_of_week_monday, + R.string.day_of_week_tuesday, + R.string.day_of_week_wednesday, + R.string.day_of_week_thursday, + R.string.day_of_week_friday, + R.string.day_of_week_saturday, + ) + } +} diff --git a/app/src/androidTest/java/com/example/util/simpletimetracker/GoalsOnCardsTest.kt b/app/src/androidTest/java/com/example/util/simpletimetracker/GoalsOnCardsTest.kt index 4b7ac4ce7..c48083081 100644 --- a/app/src/androidTest/java/com/example/util/simpletimetracker/GoalsOnCardsTest.kt +++ b/app/src/androidTest/java/com/example/util/simpletimetracker/GoalsOnCardsTest.kt @@ -1,20 +1,11 @@ package com.example.util.simpletimetracker -import android.view.View -import androidx.test.espresso.matcher.ViewMatchers.hasDescendant -import androidx.test.espresso.matcher.ViewMatchers.isCompletelyDisplayed -import androidx.test.espresso.matcher.ViewMatchers.isDescendantOfA -import androidx.test.espresso.matcher.ViewMatchers.withId -import androidx.test.espresso.matcher.ViewMatchers.withText import androidx.test.ext.junit.runners.AndroidJUnit4 -import com.example.util.simpletimetracker.feature_change_record.R +import com.example.util.simpletimetracker.GoalsTestUtils.checkTypeMark +import com.example.util.simpletimetracker.GoalsTestUtils.checkNoTypeMark import com.example.util.simpletimetracker.utils.BaseUiTest import com.example.util.simpletimetracker.utils.NavUtils -import com.example.util.simpletimetracker.utils.checkViewIsDisplayed -import com.example.util.simpletimetracker.utils.checkViewIsNotDisplayed import dagger.hilt.android.testing.HiltAndroidTest -import org.hamcrest.CoreMatchers.allOf -import org.hamcrest.Matcher import org.junit.Test import org.junit.runner.RunWith import java.util.concurrent.TimeUnit @@ -43,8 +34,8 @@ class GoalsOnCardsTest : BaseUiTest() { Thread.sleep(1000) // Check - checkNoGoal(noGoals) - checkNoGoal(otherGoals) + checkNoTypeMark(noGoals) + checkNoTypeMark(otherGoals) } @Test @@ -64,8 +55,8 @@ class GoalsOnCardsTest : BaseUiTest() { Thread.sleep(1000) // Not reached - checkCheckmark(durationGoal, isVisible = false) - checkCheckmark(countGoal, isVisible = false) + checkTypeMark(durationGoal, isVisible = false) + checkTypeMark(countGoal, isVisible = false) // Add records NavUtils.openRecordsScreen() @@ -81,8 +72,8 @@ class GoalsOnCardsTest : BaseUiTest() { // Not reached NavUtils.openRunningRecordsScreen() - checkCheckmark(durationGoal, isVisible = false) - checkCheckmark(countGoal, isVisible = false) + checkTypeMark(durationGoal, isVisible = false) + checkTypeMark(countGoal, isVisible = false) // Add more records NavUtils.openRecordsScreen() @@ -97,34 +88,7 @@ class GoalsOnCardsTest : BaseUiTest() { // Reached NavUtils.openRunningRecordsScreen() - checkCheckmark(durationGoal, isVisible = true) - checkCheckmark(countGoal, isVisible = true) - } - - private fun checkNoGoal(typeName: String) { - allOf(withId(R.id.viewRecordTypeItem), hasDescendant(withText(typeName)), isCompletelyDisplayed()) - .let(::checkViewIsDisplayed) - allOf(getTypeMatcher(typeName), withId(R.id.ivGoalCheckmarkItemCheckOutline)) - .let(::checkViewIsNotDisplayed) - allOf(getTypeMatcher(typeName), withId(R.id.ivGoalCheckmarkItemCheck)) - .let(::checkViewIsNotDisplayed) - } - - private fun checkCheckmark(typeName: String, isVisible: Boolean) { - allOf(withId(R.id.viewRecordTypeItem), hasDescendant(withText(typeName)), isCompletelyDisplayed()) - .let(::checkViewIsDisplayed) - allOf(getTypeMatcher(typeName), withId(R.id.ivGoalCheckmarkItemCheckOutline)) - .let(::checkViewIsDisplayed) - allOf(getTypeMatcher(typeName), withId(R.id.ivGoalCheckmarkItemCheck)) - .let { if (isVisible) checkViewIsDisplayed(it) else checkViewIsNotDisplayed(it) } - } - - private fun getTypeMatcher(typeName: String): Matcher { - return isDescendantOfA( - allOf( - withId(R.id.viewRecordTypeItem), - hasDescendant(withText(typeName)), - ), - ) + checkTypeMark(durationGoal, isVisible = true) + checkTypeMark(countGoal, isVisible = true) } } diff --git a/app/src/androidTest/java/com/example/util/simpletimetracker/GoalsRunningTest.kt b/app/src/androidTest/java/com/example/util/simpletimetracker/GoalsRunningTest.kt index 9d0a43c00..6fc3cda41 100644 --- a/app/src/androidTest/java/com/example/util/simpletimetracker/GoalsRunningTest.kt +++ b/app/src/androidTest/java/com/example/util/simpletimetracker/GoalsRunningTest.kt @@ -1,17 +1,15 @@ package com.example.util.simpletimetracker import androidx.test.espresso.matcher.ViewMatchers.hasDescendant -import androidx.test.espresso.matcher.ViewMatchers.hasSibling -import androidx.test.espresso.matcher.ViewMatchers.isDescendantOfA import androidx.test.espresso.matcher.ViewMatchers.withId -import androidx.test.espresso.matcher.ViewMatchers.withSubstring import androidx.test.espresso.matcher.ViewMatchers.withText import androidx.test.ext.junit.runners.AndroidJUnit4 +import com.example.util.simpletimetracker.GoalsTestUtils.checkRunningGoal +import com.example.util.simpletimetracker.GoalsTestUtils.checkRunningMark +import com.example.util.simpletimetracker.GoalsTestUtils.checkNoRunningGoal import com.example.util.simpletimetracker.GoalsTestUtils.durationInSeconds import com.example.util.simpletimetracker.feature_change_record.R import com.example.util.simpletimetracker.utils.BaseUiTest -import com.example.util.simpletimetracker.utils.checkViewIsDisplayed -import com.example.util.simpletimetracker.utils.checkViewIsNotDisplayed import com.example.util.simpletimetracker.utils.scrollRecyclerToView import com.example.util.simpletimetracker.utils.tryAction import dagger.hilt.android.testing.HiltAndroidTest @@ -37,8 +35,8 @@ class GoalsRunningTest : BaseUiTest() { // No goals scrollTo(noGoals) - checkNoGoal(noGoals) - checkGoalMark(noGoals, isVisible = false) + checkNoRunningGoal(noGoals) + checkRunningMark(noGoals, isVisible = false) } @Test @@ -68,13 +66,13 @@ class GoalsRunningTest : BaseUiTest() { // Session goal not finished scrollTo(sessionGoalNotFinished) - checkGoal(sessionGoalNotFinished, "$sessionGoal 9$minuteString") - checkGoalMark(sessionGoalNotFinished, isVisible = false) + checkRunningGoal(sessionGoalNotFinished, "$sessionGoal 9$minuteString") + checkRunningMark(sessionGoalNotFinished, isVisible = false) // Session goal finished scrollTo(sessionGoalFinished) - checkGoal(sessionGoalFinished, sessionGoal) - checkGoalMark(sessionGoalFinished, isVisible = true) + checkRunningGoal(sessionGoalFinished, sessionGoal) + checkRunningMark(sessionGoalFinished, isVisible = true) } @Test @@ -127,23 +125,23 @@ class GoalsRunningTest : BaseUiTest() { // Goal time not finished scrollTo(goalTimeNotFinished) - checkGoal(goalTimeNotFinished, "$dailyGoal 4$minuteString") - checkGoalMark(goalTimeNotFinished, isVisible = false) + checkRunningGoal(goalTimeNotFinished, "$dailyGoal 4$minuteString") + checkRunningMark(goalTimeNotFinished, isVisible = false) // Goal time finished scrollTo(goalTimeFinished) - checkGoal(goalTimeFinished, dailyGoal) - checkGoalMark(goalTimeFinished, isVisible = true) + checkRunningGoal(goalTimeFinished, dailyGoal) + checkRunningMark(goalTimeFinished, isVisible = true) // Goal count not finished scrollTo(goalCountNotFinished) - checkGoal(goalCountNotFinished, "$dailyGoal 3") - checkGoalMark(goalCountNotFinished, isVisible = false) + checkRunningGoal(goalCountNotFinished, "$dailyGoal 3") + checkRunningMark(goalCountNotFinished, isVisible = false) // Goal count finished scrollTo(goalCountFinished) - checkGoal(goalCountFinished, dailyGoal) - checkGoalMark(goalCountFinished, isVisible = true) + checkRunningGoal(goalCountFinished, dailyGoal) + checkRunningMark(goalCountFinished, isVisible = true) } @Test @@ -185,13 +183,13 @@ class GoalsRunningTest : BaseUiTest() { // All goal times scrollTo(allGoalTimesPresent) - checkGoal(allGoalTimesPresent, "$dailyGoal 14$minuteString") - checkGoalMark(allGoalTimesPresent, isVisible = false) + checkRunningGoal(allGoalTimesPresent, "$dailyGoal 14$minuteString") + checkRunningMark(allGoalTimesPresent, isVisible = false) // All goal counts scrollTo(allGoalCountsPresent) - checkGoal(allGoalCountsPresent, "$dailyGoal 7") - checkGoalMark(allGoalCountsPresent, isVisible = false) + checkRunningGoal(allGoalCountsPresent, "$dailyGoal 7") + checkRunningMark(allGoalCountsPresent, isVisible = false) } @Test @@ -220,39 +218,12 @@ class GoalsRunningTest : BaseUiTest() { // Weekly and monthly goals are not present scrollTo(goalTime) - checkNoGoal(goalTime) - checkGoalMark(goalTime, isVisible = false) + checkNoRunningGoal(goalTime) + checkRunningMark(goalTime, isVisible = false) scrollTo(goalCount) - checkNoGoal(goalCount) - checkGoalMark(goalCount, isVisible = false) - } - - private fun checkGoal(typeName: String, goal: String) { - allOf( - isDescendantOfA(withId(R.id.viewRunningRecordItem)), - hasSibling(withText(typeName)), - withId(R.id.tvRunningRecordItemGoalTime), - withSubstring(goal), - ).let(::checkViewIsDisplayed) - } - - private fun checkNoGoal(typeName: String) { - allOf( - isDescendantOfA(withId(R.id.viewRunningRecordItem)), - hasSibling(withText(typeName)), - withId(R.id.tvRunningRecordItemGoalTime), - ).let(::checkViewIsNotDisplayed) - } - - private fun checkGoalMark(typeName: String, isVisible: Boolean) { - allOf( - isDescendantOfA(withId(R.id.viewRunningRecordItem)), - hasSibling(withText(typeName)), - withId(R.id.ivRunningRecordItemGoalTimeCheck), - ).let { - if (isVisible) checkViewIsDisplayed(it) else checkViewIsNotDisplayed(it) - } + checkNoRunningGoal(goalCount) + checkRunningMark(goalCount, isVisible = false) } private fun scrollTo(typeName: String) { diff --git a/app/src/androidTest/java/com/example/util/simpletimetracker/GoalsStatisticsTest.kt b/app/src/androidTest/java/com/example/util/simpletimetracker/GoalsStatisticsTest.kt index 9beccaafb..98c1389d4 100644 --- a/app/src/androidTest/java/com/example/util/simpletimetracker/GoalsStatisticsTest.kt +++ b/app/src/androidTest/java/com/example/util/simpletimetracker/GoalsStatisticsTest.kt @@ -8,7 +8,23 @@ import androidx.test.espresso.matcher.ViewMatchers.withId import androidx.test.espresso.matcher.ViewMatchers.withText import androidx.test.ext.junit.runners.AndroidJUnit4 import com.example.util.simpletimetracker.GoalsTestUtils.addRecords +import com.example.util.simpletimetracker.GoalsTestUtils.checkNoStatisticsGoal +import com.example.util.simpletimetracker.GoalsTestUtils.checkStatisticsGoal +import com.example.util.simpletimetracker.GoalsTestUtils.checkStatisticsMark +import com.example.util.simpletimetracker.GoalsTestUtils.checkStatisticsPercent import com.example.util.simpletimetracker.GoalsTestUtils.durationInSeconds +import com.example.util.simpletimetracker.GoalsTestUtils.getDailyCountGoal +import com.example.util.simpletimetracker.GoalsTestUtils.getDailyCountGoalCategory +import com.example.util.simpletimetracker.GoalsTestUtils.getDailyDurationGoal +import com.example.util.simpletimetracker.GoalsTestUtils.getDailyDurationGoalCategory +import com.example.util.simpletimetracker.GoalsTestUtils.getMonthlyCountGoal +import com.example.util.simpletimetracker.GoalsTestUtils.getMonthlyCountGoalCategory +import com.example.util.simpletimetracker.GoalsTestUtils.getMonthlyDurationGoal +import com.example.util.simpletimetracker.GoalsTestUtils.getMonthlyDurationGoalCategory +import com.example.util.simpletimetracker.GoalsTestUtils.getWeeklyCountGoal +import com.example.util.simpletimetracker.GoalsTestUtils.getWeeklyCountGoalCategory +import com.example.util.simpletimetracker.GoalsTestUtils.getWeeklyDurationGoal +import com.example.util.simpletimetracker.GoalsTestUtils.getWeeklyDurationGoalCategory import com.example.util.simpletimetracker.utils.BaseUiTest import com.example.util.simpletimetracker.utils.NavUtils import com.example.util.simpletimetracker.utils.clickOnViewWithId @@ -42,25 +58,25 @@ class GoalsStatisticsTest : BaseUiTest() { // Add data testUtils.addActivity( goalTimeNotFinished, - goals = listOf(GoalsTestUtils.getDailyDurationGoal(4 * durationInSeconds)), + goals = listOf(getDailyDurationGoal(4 * durationInSeconds)), ) addRecords(testUtils, goalTimeNotFinished) testUtils.addActivity( goalTimeFinished, - goals = listOf(GoalsTestUtils.getDailyDurationGoal(durationInSeconds)), + goals = listOf(getDailyDurationGoal(durationInSeconds)), ) addRecords(testUtils, goalTimeFinished) testUtils.addActivity( goalCountNotFinished, - goals = listOf(GoalsTestUtils.getDailyCountGoal(4)), + goals = listOf(getDailyCountGoal(4)), ) addRecords(testUtils, goalCountNotFinished) testUtils.addActivity( goalCountFinished, - goals = listOf(GoalsTestUtils.getDailyCountGoal(3)), + goals = listOf(getDailyCountGoal(3)), ) testUtils.addRecord(goalCountFinished) testUtils.addRecord(goalCountFinished) @@ -69,8 +85,8 @@ class GoalsStatisticsTest : BaseUiTest() { testUtils.addActivity( otherGoals, goals = listOf( - GoalsTestUtils.getWeeklyDurationGoal(durationInSeconds), - GoalsTestUtils.getMonthlyCountGoal(1), + getWeeklyDurationGoal(durationInSeconds), + getMonthlyCountGoal(1), ), ) addRecords(testUtils, otherGoals) @@ -79,29 +95,29 @@ class GoalsStatisticsTest : BaseUiTest() { // Goal time not finished scrollTo(goalTimeNotFinished) - GoalsTestUtils.checkGoal(goalTimeNotFinished, "10$minuteString", "$goal - 40$minuteString") - GoalsTestUtils.checkGoalPercent(goalTimeNotFinished, "25%") - GoalsTestUtils.checkGoalMark(goalTimeNotFinished, isVisible = false) + checkStatisticsGoal(goalTimeNotFinished, "10$minuteString", "$goal - 40$minuteString") + checkStatisticsPercent(goalTimeNotFinished, "25%") + checkStatisticsMark(goalTimeNotFinished, isVisible = false) // Goal time finished scrollTo(goalTimeFinished) - GoalsTestUtils.checkGoal(goalTimeFinished, "10$minuteString", "$goal - 10$minuteString") - GoalsTestUtils.checkGoalMark(goalTimeFinished, isVisible = true) + checkStatisticsGoal(goalTimeFinished, "10$minuteString", "$goal - 10$minuteString") + checkStatisticsMark(goalTimeFinished, isVisible = true) // Goal count not finished scrollTo(goalCountNotFinished) - GoalsTestUtils.checkGoal(goalCountNotFinished, "1 Record", "$goal - 4 Records") - GoalsTestUtils.checkGoalPercent(goalCountNotFinished, "25%") - GoalsTestUtils.checkGoalMark(goalCountNotFinished, isVisible = false) + checkStatisticsGoal(goalCountNotFinished, "1 Record", "$goal - 4 Records") + checkStatisticsPercent(goalCountNotFinished, "25%") + checkStatisticsMark(goalCountNotFinished, isVisible = false) // Goal count finished scrollTo(goalCountFinished) - GoalsTestUtils.checkGoal(goalCountFinished, "3 Records", "$goal - 3 Records") - GoalsTestUtils.checkGoalMark(goalCountFinished, isVisible = true) + checkStatisticsGoal(goalCountFinished, "3 Records", "$goal - 3 Records") + checkStatisticsMark(goalCountFinished, isVisible = true) // Other goals scrollBottom() - GoalsTestUtils.checkNoGoal(otherGoals) + checkNoStatisticsGoal(otherGoals) } @Test @@ -117,25 +133,25 @@ class GoalsStatisticsTest : BaseUiTest() { // Add data testUtils.addActivity( goalTimeNotFinished, - goals = listOf(GoalsTestUtils.getWeeklyDurationGoal(4 * durationInSeconds)), + goals = listOf(getWeeklyDurationGoal(4 * durationInSeconds)), ) addRecords(testUtils, goalTimeNotFinished) testUtils.addActivity( goalTimeFinished, - goals = listOf(GoalsTestUtils.getWeeklyDurationGoal(durationInSeconds)), + goals = listOf(getWeeklyDurationGoal(durationInSeconds)), ) addRecords(testUtils, goalTimeFinished) testUtils.addActivity( goalCountNotFinished, - goals = listOf(GoalsTestUtils.getWeeklyCountGoal(4)), + goals = listOf(getWeeklyCountGoal(4)), ) addRecords(testUtils, goalCountNotFinished) testUtils.addActivity( goalCountFinished, - goals = listOf(GoalsTestUtils.getWeeklyCountGoal(3)), + goals = listOf(getWeeklyCountGoal(3)), ) testUtils.addRecord(goalCountFinished) testUtils.addRecord(goalCountFinished) @@ -144,8 +160,8 @@ class GoalsStatisticsTest : BaseUiTest() { testUtils.addActivity( otherGoals, goals = listOf( - GoalsTestUtils.getDailyDurationGoal(durationInSeconds), - GoalsTestUtils.getMonthlyCountGoal(1), + getDailyDurationGoal(durationInSeconds), + getMonthlyCountGoal(1), ), ) addRecords(testUtils, otherGoals) @@ -156,29 +172,29 @@ class GoalsStatisticsTest : BaseUiTest() { // Goal time not finished scrollTo(goalTimeNotFinished) - GoalsTestUtils.checkGoal(goalTimeNotFinished, "20$minuteString", "$goal - 40$minuteString") - GoalsTestUtils.checkGoalPercent(goalTimeNotFinished, "50%") - GoalsTestUtils.checkGoalMark(goalTimeNotFinished, isVisible = false) + checkStatisticsGoal(goalTimeNotFinished, "20$minuteString", "$goal - 40$minuteString") + checkStatisticsPercent(goalTimeNotFinished, "50%") + checkStatisticsMark(goalTimeNotFinished, isVisible = false) // Goal time finished scrollTo(goalTimeFinished) - GoalsTestUtils.checkGoal(goalTimeFinished, "20$minuteString", "$goal - 10$minuteString") - GoalsTestUtils.checkGoalMark(goalTimeFinished, isVisible = true) + checkStatisticsGoal(goalTimeFinished, "20$minuteString", "$goal - 10$minuteString") + checkStatisticsMark(goalTimeFinished, isVisible = true) // Goal count not finished scrollTo(goalCountNotFinished) - GoalsTestUtils.checkGoal(goalCountNotFinished, "2 Records", "$goal - 4 Records") - GoalsTestUtils.checkGoalPercent(goalCountNotFinished, "50%") - GoalsTestUtils.checkGoalMark(goalCountNotFinished, isVisible = false) + checkStatisticsGoal(goalCountNotFinished, "2 Records", "$goal - 4 Records") + checkStatisticsPercent(goalCountNotFinished, "50%") + checkStatisticsMark(goalCountNotFinished, isVisible = false) // Goal count finished scrollTo(goalCountFinished) - GoalsTestUtils.checkGoal(goalCountFinished, "4 Records", "$goal - 3 Records") - GoalsTestUtils.checkGoalMark(goalCountFinished, isVisible = true) + checkStatisticsGoal(goalCountFinished, "4 Records", "$goal - 3 Records") + checkStatisticsMark(goalCountFinished, isVisible = true) // Other goals scrollBottom() - GoalsTestUtils.checkNoGoal(otherGoals) + checkNoStatisticsGoal(otherGoals) } @Test @@ -194,25 +210,25 @@ class GoalsStatisticsTest : BaseUiTest() { // Add data testUtils.addActivity( goalTimeNotFinished, - goals = listOf(GoalsTestUtils.getMonthlyDurationGoal(4 * durationInSeconds)), + goals = listOf(getMonthlyDurationGoal(4 * durationInSeconds)), ) addRecords(testUtils, goalTimeNotFinished) testUtils.addActivity( goalTimeFinished, - goals = listOf(GoalsTestUtils.getMonthlyDurationGoal(durationInSeconds)), + goals = listOf(getMonthlyDurationGoal(durationInSeconds)), ) addRecords(testUtils, goalTimeFinished) testUtils.addActivity( goalCountNotFinished, - goals = listOf(GoalsTestUtils.getMonthlyCountGoal(4)), + goals = listOf(getMonthlyCountGoal(4)), ) addRecords(testUtils, goalCountNotFinished) testUtils.addActivity( goalCountFinished, - goals = listOf(GoalsTestUtils.getMonthlyCountGoal(3)), + goals = listOf(getMonthlyCountGoal(3)), ) testUtils.addRecord(goalCountFinished) testUtils.addRecord(goalCountFinished) @@ -221,8 +237,8 @@ class GoalsStatisticsTest : BaseUiTest() { testUtils.addActivity( otherGoals, goals = listOf( - GoalsTestUtils.getDailyDurationGoal(durationInSeconds), - GoalsTestUtils.getWeeklyCountGoal(1), + getDailyDurationGoal(durationInSeconds), + getWeeklyCountGoal(1), ), ) addRecords(testUtils, otherGoals) @@ -233,29 +249,29 @@ class GoalsStatisticsTest : BaseUiTest() { // Goal time not finished scrollTo(goalTimeNotFinished) - GoalsTestUtils.checkGoal(goalTimeNotFinished, "30$minuteString", "$goal - 40$minuteString") - GoalsTestUtils.checkGoalPercent(goalTimeNotFinished, "75%") - GoalsTestUtils.checkGoalMark(goalTimeNotFinished, isVisible = false) + checkStatisticsGoal(goalTimeNotFinished, "30$minuteString", "$goal - 40$minuteString") + checkStatisticsPercent(goalTimeNotFinished, "75%") + checkStatisticsMark(goalTimeNotFinished, isVisible = false) // Goal time finished scrollTo(goalTimeFinished) - GoalsTestUtils.checkGoal(goalTimeFinished, "30$minuteString", "$goal - 10$minuteString") - GoalsTestUtils.checkGoalMark(goalTimeFinished, isVisible = true) + checkStatisticsGoal(goalTimeFinished, "30$minuteString", "$goal - 10$minuteString") + checkStatisticsMark(goalTimeFinished, isVisible = true) // Goal count not finished scrollTo(goalCountNotFinished) - GoalsTestUtils.checkGoal(goalCountNotFinished, "3 Records", "$goal - 4 Records") - GoalsTestUtils.checkGoalPercent(goalCountNotFinished, "75%") - GoalsTestUtils.checkGoalMark(goalCountNotFinished, isVisible = false) + checkStatisticsGoal(goalCountNotFinished, "3 Records", "$goal - 4 Records") + checkStatisticsPercent(goalCountNotFinished, "75%") + checkStatisticsMark(goalCountNotFinished, isVisible = false) // Goal count finished scrollTo(goalCountFinished) - GoalsTestUtils.checkGoal(goalCountFinished, "5 Records", "$goal - 3 Records") - GoalsTestUtils.checkGoalMark(goalCountFinished, isVisible = true) + checkStatisticsGoal(goalCountFinished, "5 Records", "$goal - 3 Records") + checkStatisticsMark(goalCountFinished, isVisible = true) // Other goals scrollBottom() - GoalsTestUtils.checkNoGoal(otherGoals) + checkNoStatisticsGoal(otherGoals) } @Test @@ -271,7 +287,7 @@ class GoalsStatisticsTest : BaseUiTest() { // Add data testUtils.addCategory( goalTimeNotFinished, - goals = listOf(GoalsTestUtils.getDailyDurationGoalCategory(8 * durationInSeconds)), + goals = listOf(getDailyDurationGoalCategory(8 * durationInSeconds)), ) testUtils.addActivity( goalTimeNotFinished.first(), @@ -286,7 +302,7 @@ class GoalsStatisticsTest : BaseUiTest() { testUtils.addCategory( goalTimeFinished, - goals = listOf(GoalsTestUtils.getDailyDurationGoalCategory(2 * durationInSeconds)), + goals = listOf(getDailyDurationGoalCategory(2 * durationInSeconds)), ) testUtils.addActivity( goalTimeFinished.first(), @@ -301,7 +317,7 @@ class GoalsStatisticsTest : BaseUiTest() { testUtils.addCategory( goalCountNotFinished, - goals = listOf(GoalsTestUtils.getDailyCountGoalCategory(8)), + goals = listOf(getDailyCountGoalCategory(8)), ) testUtils.addActivity( goalCountNotFinished.first(), @@ -316,7 +332,7 @@ class GoalsStatisticsTest : BaseUiTest() { testUtils.addCategory( goalCountFinished, - goals = listOf(GoalsTestUtils.getDailyCountGoalCategory(3)), + goals = listOf(getDailyCountGoalCategory(3)), ) testUtils.addActivity( goalCountFinished.first(), @@ -333,8 +349,8 @@ class GoalsStatisticsTest : BaseUiTest() { testUtils.addCategory( otherGoals, goals = listOf( - GoalsTestUtils.getWeeklyDurationGoalCategory(durationInSeconds), - GoalsTestUtils.getMonthlyCountGoalCategory(1), + getWeeklyDurationGoalCategory(durationInSeconds), + getMonthlyCountGoalCategory(1), ), ) testUtils.addActivity( @@ -355,29 +371,29 @@ class GoalsStatisticsTest : BaseUiTest() { // Goal time not finished scrollTo(goalTimeNotFinished) - GoalsTestUtils.checkGoal(goalTimeNotFinished, "20$minuteString", "$goal - 1$hourString 20$minuteString") - GoalsTestUtils.checkGoalPercent(goalTimeNotFinished, "25%") - GoalsTestUtils.checkGoalMark(goalTimeNotFinished, isVisible = false) + checkStatisticsGoal(goalTimeNotFinished, "20$minuteString", "$goal - 1$hourString 20$minuteString") + checkStatisticsPercent(goalTimeNotFinished, "25%") + checkStatisticsMark(goalTimeNotFinished, isVisible = false) // Goal time finished scrollTo(goalTimeFinished) - GoalsTestUtils.checkGoal(goalTimeFinished, "20$minuteString", "$goal - 20$minuteString") - GoalsTestUtils.checkGoalMark(goalTimeFinished, isVisible = true) + checkStatisticsGoal(goalTimeFinished, "20$minuteString", "$goal - 20$minuteString") + checkStatisticsMark(goalTimeFinished, isVisible = true) // Goal count not finished scrollTo(goalCountNotFinished) - GoalsTestUtils.checkGoal(goalCountNotFinished, "2 Records", "$goal - 8 Records") - GoalsTestUtils.checkGoalPercent(goalCountNotFinished, "25%") - GoalsTestUtils.checkGoalMark(goalCountNotFinished, isVisible = false) + checkStatisticsGoal(goalCountNotFinished, "2 Records", "$goal - 8 Records") + checkStatisticsPercent(goalCountNotFinished, "25%") + checkStatisticsMark(goalCountNotFinished, isVisible = false) // Goal count finished scrollTo(goalCountFinished) - GoalsTestUtils.checkGoal(goalCountFinished, "3 Records", "$goal - 3 Records") - GoalsTestUtils.checkGoalMark(goalCountFinished, isVisible = true) + checkStatisticsGoal(goalCountFinished, "3 Records", "$goal - 3 Records") + checkStatisticsMark(goalCountFinished, isVisible = true) // Other goals scrollBottom() - GoalsTestUtils.checkNoGoal(otherGoals) + checkNoStatisticsGoal(otherGoals) } @Test @@ -393,7 +409,7 @@ class GoalsStatisticsTest : BaseUiTest() { // Add data testUtils.addCategory( goalTimeNotFinished, - goals = listOf(GoalsTestUtils.getWeeklyDurationGoalCategory(8 * durationInSeconds)), + goals = listOf(getWeeklyDurationGoalCategory(8 * durationInSeconds)), ) testUtils.addActivity( goalTimeNotFinished.first(), @@ -408,7 +424,7 @@ class GoalsStatisticsTest : BaseUiTest() { testUtils.addCategory( goalTimeFinished, - goals = listOf(GoalsTestUtils.getWeeklyDurationGoalCategory(2 * durationInSeconds)), + goals = listOf(getWeeklyDurationGoalCategory(2 * durationInSeconds)), ) testUtils.addActivity( goalTimeFinished.first(), @@ -423,7 +439,7 @@ class GoalsStatisticsTest : BaseUiTest() { testUtils.addCategory( goalCountNotFinished, - goals = listOf(GoalsTestUtils.getWeeklyCountGoalCategory(8)), + goals = listOf(getWeeklyCountGoalCategory(8)), ) testUtils.addActivity( goalCountNotFinished.first(), @@ -438,7 +454,7 @@ class GoalsStatisticsTest : BaseUiTest() { testUtils.addCategory( goalCountFinished, - goals = listOf(GoalsTestUtils.getWeeklyCountGoalCategory(3)), + goals = listOf(getWeeklyCountGoalCategory(3)), ) testUtils.addActivity( goalCountFinished.first(), @@ -455,8 +471,8 @@ class GoalsStatisticsTest : BaseUiTest() { testUtils.addCategory( otherGoals, goals = listOf( - GoalsTestUtils.getDailyDurationGoalCategory(durationInSeconds), - GoalsTestUtils.getMonthlyCountGoalCategory(1), + getDailyDurationGoalCategory(durationInSeconds), + getMonthlyCountGoalCategory(1), ), ) testUtils.addActivity( @@ -479,29 +495,29 @@ class GoalsStatisticsTest : BaseUiTest() { // Goal time not finished scrollTo(goalTimeNotFinished) - GoalsTestUtils.checkGoal(goalTimeNotFinished, "40$minuteString", "$goal - 1$hourString 20$minuteString") - GoalsTestUtils.checkGoalPercent(goalTimeNotFinished, "50%") - GoalsTestUtils.checkGoalMark(goalTimeNotFinished, isVisible = false) + checkStatisticsGoal(goalTimeNotFinished, "40$minuteString", "$goal - 1$hourString 20$minuteString") + checkStatisticsPercent(goalTimeNotFinished, "50%") + checkStatisticsMark(goalTimeNotFinished, isVisible = false) // Goal time finished scrollTo(goalTimeFinished) - GoalsTestUtils.checkGoal(goalTimeFinished, "40$minuteString", "$goal - 20$minuteString") - GoalsTestUtils.checkGoalMark(goalTimeFinished, isVisible = true) + checkStatisticsGoal(goalTimeFinished, "40$minuteString", "$goal - 20$minuteString") + checkStatisticsMark(goalTimeFinished, isVisible = true) // Goal count not finished scrollTo(goalCountNotFinished) - GoalsTestUtils.checkGoal(goalCountNotFinished, "4 Records", "$goal - 8 Records") - GoalsTestUtils.checkGoalPercent(goalCountNotFinished, "50%") - GoalsTestUtils.checkGoalMark(goalCountNotFinished, isVisible = false) + checkStatisticsGoal(goalCountNotFinished, "4 Records", "$goal - 8 Records") + checkStatisticsPercent(goalCountNotFinished, "50%") + checkStatisticsMark(goalCountNotFinished, isVisible = false) // Goal count finished scrollTo(goalCountFinished) - GoalsTestUtils.checkGoal(goalCountFinished, "4 Records", "$goal - 3 Records") - GoalsTestUtils.checkGoalMark(goalCountFinished, isVisible = true) + checkStatisticsGoal(goalCountFinished, "4 Records", "$goal - 3 Records") + checkStatisticsMark(goalCountFinished, isVisible = true) // Other goals scrollBottom() - GoalsTestUtils.checkNoGoal(otherGoals) + checkNoStatisticsGoal(otherGoals) } @Test @@ -517,7 +533,7 @@ class GoalsStatisticsTest : BaseUiTest() { // Add data testUtils.addCategory( goalTimeNotFinished, - goals = listOf(GoalsTestUtils.getMonthlyDurationGoalCategory(8 * durationInSeconds)), + goals = listOf(getMonthlyDurationGoalCategory(8 * durationInSeconds)), ) testUtils.addActivity( goalTimeNotFinished.first(), @@ -532,7 +548,7 @@ class GoalsStatisticsTest : BaseUiTest() { testUtils.addCategory( goalTimeFinished, - goals = listOf(GoalsTestUtils.getMonthlyDurationGoalCategory(2 * durationInSeconds)), + goals = listOf(getMonthlyDurationGoalCategory(2 * durationInSeconds)), ) testUtils.addActivity( goalTimeFinished.first(), @@ -547,7 +563,7 @@ class GoalsStatisticsTest : BaseUiTest() { testUtils.addCategory( goalCountNotFinished, - goals = listOf(GoalsTestUtils.getMonthlyCountGoalCategory(8)), + goals = listOf(getMonthlyCountGoalCategory(8)), ) testUtils.addActivity( goalCountNotFinished.first(), @@ -562,7 +578,7 @@ class GoalsStatisticsTest : BaseUiTest() { testUtils.addCategory( goalCountFinished, - goals = listOf(GoalsTestUtils.getMonthlyCountGoalCategory(3)), + goals = listOf(getMonthlyCountGoalCategory(3)), ) testUtils.addActivity( goalCountFinished.first(), @@ -579,8 +595,8 @@ class GoalsStatisticsTest : BaseUiTest() { testUtils.addCategory( otherGoals, goals = listOf( - GoalsTestUtils.getDailyDurationGoalCategory(durationInSeconds), - GoalsTestUtils.getWeeklyCountGoalCategory(1), + getDailyDurationGoalCategory(durationInSeconds), + getWeeklyCountGoalCategory(1), ), ) testUtils.addActivity( @@ -603,29 +619,29 @@ class GoalsStatisticsTest : BaseUiTest() { // Goal time not finished scrollTo(goalTimeNotFinished) - GoalsTestUtils.checkGoal(goalTimeNotFinished, "1$hourString 0$minuteString", "$goal - 1$hourString 20$minuteString") - GoalsTestUtils.checkGoalPercent(goalTimeNotFinished, "75%") - GoalsTestUtils.checkGoalMark(goalTimeNotFinished, isVisible = false) + checkStatisticsGoal(goalTimeNotFinished, "1$hourString 0$minuteString", "$goal - 1$hourString 20$minuteString") + checkStatisticsPercent(goalTimeNotFinished, "75%") + checkStatisticsMark(goalTimeNotFinished, isVisible = false) // Goal time finished scrollTo(goalTimeFinished) - GoalsTestUtils.checkGoal(goalTimeFinished, "1$hourString 0$minuteString", "$goal - 20$minuteString") - GoalsTestUtils.checkGoalMark(goalTimeFinished, isVisible = true) + checkStatisticsGoal(goalTimeFinished, "1$hourString 0$minuteString", "$goal - 20$minuteString") + checkStatisticsMark(goalTimeFinished, isVisible = true) // Goal count not finished scrollTo(goalCountNotFinished) - GoalsTestUtils.checkGoal(goalCountNotFinished, "6 Records", "$goal - 8 Records") - GoalsTestUtils.checkGoalPercent(goalCountNotFinished, "75%") - GoalsTestUtils.checkGoalMark(goalCountNotFinished, isVisible = false) + checkStatisticsGoal(goalCountNotFinished, "6 Records", "$goal - 8 Records") + checkStatisticsPercent(goalCountNotFinished, "75%") + checkStatisticsMark(goalCountNotFinished, isVisible = false) // Goal count finished scrollTo(goalCountFinished) - GoalsTestUtils.checkGoal(goalCountFinished, "5 Records", "$goal - 3 Records") - GoalsTestUtils.checkGoalMark(goalCountFinished, isVisible = true) + checkStatisticsGoal(goalCountFinished, "5 Records", "$goal - 3 Records") + checkStatisticsMark(goalCountFinished, isVisible = true) // Other goals scrollBottom() - GoalsTestUtils.checkNoGoal(otherGoals) + checkNoStatisticsGoal(otherGoals) } private fun scrollTo(typeName: String) { diff --git a/app/src/androidTest/java/com/example/util/simpletimetracker/GoalsTabTest.kt b/app/src/androidTest/java/com/example/util/simpletimetracker/GoalsTabTest.kt index 078d7f6cf..9ddc0e20f 100644 --- a/app/src/androidTest/java/com/example/util/simpletimetracker/GoalsTabTest.kt +++ b/app/src/androidTest/java/com/example/util/simpletimetracker/GoalsTabTest.kt @@ -9,6 +9,10 @@ import androidx.test.espresso.matcher.ViewMatchers.withId import androidx.test.espresso.matcher.ViewMatchers.withText import androidx.test.ext.junit.runners.AndroidJUnit4 import com.example.util.simpletimetracker.GoalsTestUtils.addRecords +import com.example.util.simpletimetracker.GoalsTestUtils.checkNoStatisticsGoal +import com.example.util.simpletimetracker.GoalsTestUtils.checkStatisticsGoal +import com.example.util.simpletimetracker.GoalsTestUtils.checkStatisticsMark +import com.example.util.simpletimetracker.GoalsTestUtils.checkStatisticsPercent import com.example.util.simpletimetracker.GoalsTestUtils.durationInSeconds import com.example.util.simpletimetracker.GoalsTestUtils.getDailyCountGoal import com.example.util.simpletimetracker.GoalsTestUtils.getDailyDurationGoal @@ -147,12 +151,12 @@ class GoalsTabTest : BaseUiTest() { // Goals on separate tab NavUtils.openGoalsScreen() - GoalsTestUtils.checkGoal(someGoals, "0$secondString", "$goal - 10$minuteString") + checkStatisticsGoal(someGoals, "0$secondString", "$goal - 10$minuteString") // No goals in statistics onView(withId(mainR.id.mainTabs)).perform(selectTabAtPosition(3)) Thread.sleep(1000) - GoalsTestUtils.checkNoGoal(someGoals) + checkNoStatisticsGoal(someGoals) } @Test @@ -260,71 +264,71 @@ class GoalsTabTest : BaseUiTest() { // Daily // Goal time not finished scrollTo(goalDailyTimeNotFinished) - GoalsTestUtils.checkGoal(goalDailyTimeNotFinished, "10$minuteString", "$goal - 40$minuteString") - GoalsTestUtils.checkGoalPercent(goalDailyTimeNotFinished, "25%") - GoalsTestUtils.checkGoalMark(goalDailyTimeNotFinished, isVisible = false) + checkStatisticsGoal(goalDailyTimeNotFinished, "10$minuteString", "$goal - 40$minuteString") + checkStatisticsPercent(goalDailyTimeNotFinished, "25%") + checkStatisticsMark(goalDailyTimeNotFinished, isVisible = false) // Goal time finished scrollTo(goalDailyTimeFinished) - GoalsTestUtils.checkGoal(goalDailyTimeFinished, "10$minuteString", "$goal - 10$minuteString") - GoalsTestUtils.checkGoalMark(goalDailyTimeFinished, isVisible = true) + checkStatisticsGoal(goalDailyTimeFinished, "10$minuteString", "$goal - 10$minuteString") + checkStatisticsMark(goalDailyTimeFinished, isVisible = true) // Goal count not finished scrollTo(goalDailyCountNotFinished) - GoalsTestUtils.checkGoal(goalDailyCountNotFinished, "1 Record", "$goal - 4 Records") - GoalsTestUtils.checkGoalPercent(goalDailyCountNotFinished, "25%") - GoalsTestUtils.checkGoalMark(goalDailyCountNotFinished, isVisible = false) + checkStatisticsGoal(goalDailyCountNotFinished, "1 Record", "$goal - 4 Records") + checkStatisticsPercent(goalDailyCountNotFinished, "25%") + checkStatisticsMark(goalDailyCountNotFinished, isVisible = false) // Goal count finished scrollTo(goalDailyCountFinished) - GoalsTestUtils.checkGoal(goalDailyCountFinished, "3 Records", "$goal - 3 Records") - GoalsTestUtils.checkGoalMark(goalDailyCountFinished, isVisible = true) + checkStatisticsGoal(goalDailyCountFinished, "3 Records", "$goal - 3 Records") + checkStatisticsMark(goalDailyCountFinished, isVisible = true) // Weekly // Goal time not finished scrollTo(goalWeeklyTimeNotFinished) - GoalsTestUtils.checkGoal(goalWeeklyTimeNotFinished, "20$minuteString", "$goal - 40$minuteString") - GoalsTestUtils.checkGoalPercent(goalWeeklyTimeNotFinished, "50%") - GoalsTestUtils.checkGoalMark(goalWeeklyTimeNotFinished, isVisible = false) + checkStatisticsGoal(goalWeeklyTimeNotFinished, "20$minuteString", "$goal - 40$minuteString") + checkStatisticsPercent(goalWeeklyTimeNotFinished, "50%") + checkStatisticsMark(goalWeeklyTimeNotFinished, isVisible = false) // Goal time finished scrollTo(goalWeeklyTimeFinished) - GoalsTestUtils.checkGoal(goalWeeklyTimeFinished, "20$minuteString", "$goal - 10$minuteString") - GoalsTestUtils.checkGoalMark(goalWeeklyTimeFinished, isVisible = true) + checkStatisticsGoal(goalWeeklyTimeFinished, "20$minuteString", "$goal - 10$minuteString") + checkStatisticsMark(goalWeeklyTimeFinished, isVisible = true) // Goal count not finished scrollTo(goalWeeklyCountNotFinished) - GoalsTestUtils.checkGoal(goalWeeklyCountNotFinished, "2 Records", "$goal - 4 Records") - GoalsTestUtils.checkGoalPercent(goalWeeklyCountNotFinished, "50%") - GoalsTestUtils.checkGoalMark(goalWeeklyCountNotFinished, isVisible = false) + checkStatisticsGoal(goalWeeklyCountNotFinished, "2 Records", "$goal - 4 Records") + checkStatisticsPercent(goalWeeklyCountNotFinished, "50%") + checkStatisticsMark(goalWeeklyCountNotFinished, isVisible = false) // Goal count finished scrollTo(goalWeeklyCountFinished) - GoalsTestUtils.checkGoal(goalWeeklyCountFinished, "4 Records", "$goal - 3 Records") - GoalsTestUtils.checkGoalMark(goalWeeklyCountFinished, isVisible = true) + checkStatisticsGoal(goalWeeklyCountFinished, "4 Records", "$goal - 3 Records") + checkStatisticsMark(goalWeeklyCountFinished, isVisible = true) // Monthly // Goal time not finished scrollTo(goalMonthlyTimeNotFinished) - GoalsTestUtils.checkGoal(goalMonthlyTimeNotFinished, "30$minuteString", "$goal - 40$minuteString") - GoalsTestUtils.checkGoalPercent(goalMonthlyTimeNotFinished, "75%") - GoalsTestUtils.checkGoalMark(goalMonthlyTimeNotFinished, isVisible = false) + checkStatisticsGoal(goalMonthlyTimeNotFinished, "30$minuteString", "$goal - 40$minuteString") + checkStatisticsPercent(goalMonthlyTimeNotFinished, "75%") + checkStatisticsMark(goalMonthlyTimeNotFinished, isVisible = false) // Goal time finished scrollTo(goalMonthlyTimeFinished) - GoalsTestUtils.checkGoal(goalMonthlyTimeFinished, "30$minuteString", "$goal - 10$minuteString") - GoalsTestUtils.checkGoalMark(goalMonthlyTimeFinished, isVisible = true) + checkStatisticsGoal(goalMonthlyTimeFinished, "30$minuteString", "$goal - 10$minuteString") + checkStatisticsMark(goalMonthlyTimeFinished, isVisible = true) // Goal count not finished scrollTo(goalMonthlyCountNotFinished) - GoalsTestUtils.checkGoal(goalMonthlyCountNotFinished, "3 Records", "$goal - 4 Records") - GoalsTestUtils.checkGoalPercent(goalMonthlyCountNotFinished, "75%") - GoalsTestUtils.checkGoalMark(goalMonthlyCountNotFinished, isVisible = false) + checkStatisticsGoal(goalMonthlyCountNotFinished, "3 Records", "$goal - 4 Records") + checkStatisticsPercent(goalMonthlyCountNotFinished, "75%") + checkStatisticsMark(goalMonthlyCountNotFinished, isVisible = false) // Goal count finished scrollTo(goalMonthlyCountFinished) - GoalsTestUtils.checkGoal(goalMonthlyCountFinished, "5 Records", "$goal - 3 Records") - GoalsTestUtils.checkGoalMark(goalMonthlyCountFinished, isVisible = true) + checkStatisticsGoal(goalMonthlyCountFinished, "5 Records", "$goal - 3 Records") + checkStatisticsMark(goalMonthlyCountFinished, isVisible = true) } private fun scrollTo( diff --git a/app/src/androidTest/java/com/example/util/simpletimetracker/GoalsTestUtils.kt b/app/src/androidTest/java/com/example/util/simpletimetracker/GoalsTestUtils.kt index 7de66d6a5..c8768e878 100644 --- a/app/src/androidTest/java/com/example/util/simpletimetracker/GoalsTestUtils.kt +++ b/app/src/androidTest/java/com/example/util/simpletimetracker/GoalsTestUtils.kt @@ -1,9 +1,13 @@ package com.example.util.simpletimetracker +import android.view.View +import androidx.test.espresso.matcher.ViewMatchers +import androidx.test.espresso.matcher.ViewMatchers.hasDescendant import androidx.test.espresso.matcher.ViewMatchers.hasSibling import androidx.test.espresso.matcher.ViewMatchers.isCompletelyDisplayed import androidx.test.espresso.matcher.ViewMatchers.isDescendantOfA import androidx.test.espresso.matcher.ViewMatchers.withId +import androidx.test.espresso.matcher.ViewMatchers.withSubstring import androidx.test.espresso.matcher.ViewMatchers.withText import com.example.util.simpletimetracker.core.utils.TestUtils import com.example.util.simpletimetracker.domain.model.DayOfWeek @@ -13,6 +17,7 @@ import com.example.util.simpletimetracker.utils.checkViewDoesNotExist import com.example.util.simpletimetracker.utils.checkViewIsDisplayed import com.example.util.simpletimetracker.utils.checkViewIsNotDisplayed import org.hamcrest.CoreMatchers.allOf +import org.hamcrest.Matcher import java.util.Calendar import java.util.concurrent.TimeUnit import com.example.util.simpletimetracker.feature_base_adapter.R as baseR @@ -96,7 +101,7 @@ object GoalsTestUtils { ) } - fun checkNoGoal(typeName: String) { + fun checkNoStatisticsGoal(typeName: String) { allOf( isDescendantOfA(withId(R.id.viewStatisticsGoalItem)), hasSibling(withText(typeName)), @@ -104,7 +109,7 @@ object GoalsTestUtils { ).let(::checkViewDoesNotExist) } - fun checkGoal( + fun checkStatisticsGoal( typeName: String, current: String, goal: String, @@ -113,7 +118,8 @@ object GoalsTestUtils { isDescendantOfA(withId(baseR.id.viewStatisticsGoalItem)), hasSibling(withText(typeName)), withId(R.id.tvStatisticsGoalItemCurrent), - withText(current), + withSubstring(current), + isCompletelyDisplayed(), ).let(::checkViewIsDisplayed) allOf( @@ -121,10 +127,11 @@ object GoalsTestUtils { hasSibling(withText(typeName)), withId(R.id.tvStatisticsGoalItemGoal), withText(goal), + isCompletelyDisplayed(), ).let(::checkViewIsDisplayed) } - fun checkGoalPercent( + fun checkStatisticsPercent( typeName: String, percent: String, ) { @@ -136,7 +143,7 @@ object GoalsTestUtils { ).let(::checkViewIsDisplayed) } - fun checkGoalMark(typeName: String, isVisible: Boolean) { + fun checkStatisticsMark(typeName: String, isVisible: Boolean) { allOf( isDescendantOfA(withId(baseR.id.viewStatisticsGoalItem)), hasSibling(withText(typeName)), @@ -146,6 +153,60 @@ object GoalsTestUtils { } } + fun checkTypeMark(typeName: String, isVisible: Boolean) { + allOf(withId(R.id.viewRecordTypeItem), hasDescendant(withText(typeName)), isCompletelyDisplayed()) + .let(::checkViewIsDisplayed) + allOf(getTypeMatcher(typeName), withId(R.id.ivGoalCheckmarkItemCheckOutline)) + .let(::checkViewIsDisplayed) + allOf(getTypeMatcher(typeName), withId(R.id.ivGoalCheckmarkItemCheck)) + .let { if (isVisible) checkViewIsDisplayed(it) else checkViewIsNotDisplayed(it) } + } + + fun checkNoTypeMark(typeName: String) { + allOf(withId(R.id.viewRecordTypeItem), hasDescendant(withText(typeName)), isCompletelyDisplayed()) + .let(::checkViewIsDisplayed) + allOf(getTypeMatcher(typeName), withId(R.id.ivGoalCheckmarkItemCheckOutline)) + .let(::checkViewIsNotDisplayed) + allOf(getTypeMatcher(typeName), withId(R.id.ivGoalCheckmarkItemCheck)) + .let(::checkViewIsNotDisplayed) + } + + fun checkRunningGoal(typeName: String, goal: String) { + allOf( + isDescendantOfA(withId(R.id.viewRunningRecordItem)), + hasSibling(withText(typeName)), + withId(R.id.tvRunningRecordItemGoalTime), + ViewMatchers.withSubstring(goal), + ).let(::checkViewIsDisplayed) + } + + fun checkNoRunningGoal(typeName: String) { + allOf( + isDescendantOfA(withId(R.id.viewRunningRecordItem)), + hasSibling(withText(typeName)), + withId(R.id.tvRunningRecordItemGoalTime), + ).let(::checkViewIsNotDisplayed) + } + + fun checkRunningMark(typeName: String, isVisible: Boolean) { + allOf( + isDescendantOfA(withId(R.id.viewRunningRecordItem)), + hasSibling(withText(typeName)), + withId(R.id.ivRunningRecordItemGoalTimeCheck), + ).let { + if (isVisible) checkViewIsDisplayed(it) else checkViewIsNotDisplayed(it) + } + } + + private fun getTypeMatcher(typeName: String): Matcher { + return isDescendantOfA( + allOf( + withId(R.id.viewRecordTypeItem), + hasDescendant(withText(typeName)), + ), + ) + } + private fun getDurationGoal( range: RecordTypeGoal.Range, duration: Long,