Something went wrong. Try again.
A fork of Simple Time Tracker with WearOS support. (Now integrated upstream)
Something went wrong. Try again.
SimpleTimeTracker-WearOS app src androidTest java com example util simpletimetracker GoalsDaysOfWeek.kt
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306package com.example.util.simpletimetracker
import android.view.Viewimport androidx.test.espresso.Espresso.pressBackimport androidx.test.espresso.ViewInteractionimport androidx.test.espresso.matcher.ViewMatchers.hasDescendantimport androidx.test.espresso.matcher.ViewMatchers.isDescendantOfAimport androidx.test.espresso.matcher.ViewMatchers.withIdimport androidx.test.espresso.matcher.ViewMatchers.withTextimport androidx.test.ext.junit.runners.AndroidJUnit4import com.example.util.simpletimetracker.GoalsTestUtils.checkNoRunningGoalimport com.example.util.simpletimetracker.GoalsTestUtils.checkNoStatisticsGoalimport com.example.util.simpletimetracker.GoalsTestUtils.checkNoTypeMarkimport com.example.util.simpletimetracker.GoalsTestUtils.checkRunningGoalimport com.example.util.simpletimetracker.GoalsTestUtils.checkStatisticsGoalimport com.example.util.simpletimetracker.GoalsTestUtils.checkTypeMarkimport com.example.util.simpletimetracker.core.Rimport com.example.util.simpletimetracker.data_local.utils.removeIfimport com.example.util.simpletimetracker.utils.BaseUiTestimport com.example.util.simpletimetracker.utils.NavUtilsimport com.example.util.simpletimetracker.utils.checkViewDoesNotExistimport com.example.util.simpletimetracker.utils.checkViewIsDisplayedimport com.example.util.simpletimetracker.utils.clickOnViewimport com.example.util.simpletimetracker.utils.clickOnViewWithIdimport com.example.util.simpletimetracker.utils.clickOnViewWithTextimport com.example.util.simpletimetracker.utils.longClickOnViewimport com.example.util.simpletimetracker.utils.scrollRecyclerInPagerToViewimport com.example.util.simpletimetracker.utils.tryActionimport com.example.util.simpletimetracker.utils.withCardColorimport dagger.hilt.android.testing.HiltAndroidTestimport org.hamcrest.CoreMatchers.allOfimport org.hamcrest.Matcherimport org.junit.Testimport org.junit.runner.RunWithimport java.util.Calendarimport java.util.concurrent.TimeUnitimport com.example.util.simpletimetracker.feature_change_record_type.R as changeRecordTypeRimport com.example.util.simpletimetracker.feature_dialogs.R as dialogsRimport 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<View>, visibilityMatcher: (Matcher<View>) -> 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, ) }}