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 GoalsRunningTest.kt
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238package com.example.util.simpletimetracker
import androidx.test.espresso.matcher.ViewMatchers.hasDescendantimport androidx.test.espresso.matcher.ViewMatchers.withIdimport androidx.test.espresso.matcher.ViewMatchers.withTextimport androidx.test.ext.junit.runners.AndroidJUnit4import com.example.util.simpletimetracker.GoalsTestUtils.checkRunningGoalimport com.example.util.simpletimetracker.GoalsTestUtils.checkRunningMarkimport com.example.util.simpletimetracker.GoalsTestUtils.checkNoRunningGoalimport com.example.util.simpletimetracker.GoalsTestUtils.durationInSecondsimport com.example.util.simpletimetracker.feature_change_record.Rimport com.example.util.simpletimetracker.utils.BaseUiTestimport com.example.util.simpletimetracker.utils.scrollRecyclerToViewimport com.example.util.simpletimetracker.utils.tryActionimport dagger.hilt.android.testing.HiltAndroidTestimport org.hamcrest.CoreMatchers.allOfimport org.junit.Testimport org.junit.runner.RunWithimport java.util.Calendarimport java.util.concurrent.TimeUnitimport com.example.util.simpletimetracker.core.R as coreRimport com.example.util.simpletimetracker.feature_running_records.R as runningRecordsR
@HiltAndroidTest@RunWith(AndroidJUnit4::class)class GoalsRunningTest : BaseUiTest() {
@Test fun noGoals() { val noGoals = "noGoals"
// Add data testUtils.addActivity(noGoals) testUtils.addRunningRecord(noGoals)
// No goals scrollTo(noGoals) checkNoRunningGoal(noGoals) checkRunningMark(noGoals, isVisible = false) }
@Test fun sessionGoal() { val sessionGoal = getString(coreR.string.change_record_type_session_goal_time).lowercase() val currentTime = Calendar.getInstance().timeInMillis
val sessionGoalNotFinished = "sessionGoalNotFinished" val sessionGoalFinished = "sessionGoalFinished"
// Add data testUtils.addActivity( sessionGoalNotFinished, goals = listOf(GoalsTestUtils.getSessionDurationGoal(durationInSeconds)), ) testUtils.addRecord(sessionGoalNotFinished) testUtils.addRunningRecord(sessionGoalNotFinished)
testUtils.addActivity( sessionGoalFinished, goals = listOf(GoalsTestUtils.getSessionDurationGoal(durationInSeconds)), ) testUtils.addRunningRecord( typeName = sessionGoalFinished, timeStarted = currentTime - TimeUnit.MINUTES.toMillis(10), )
// Session goal not finished scrollTo(sessionGoalNotFinished) checkRunningGoal(sessionGoalNotFinished, "$sessionGoal 9$minuteString") checkRunningMark(sessionGoalNotFinished, isVisible = false)
// Session goal finished scrollTo(sessionGoalFinished) checkRunningGoal(sessionGoalFinished, sessionGoal) checkRunningMark(sessionGoalFinished, isVisible = true) }
@Test fun dailyGoal() { val dailyGoal = getString(coreR.string.change_record_type_daily_goal_time).lowercase() val currentTime = Calendar.getInstance().timeInMillis
val goalTimeNotFinished = "goalTimeNotFinished" val goalTimeFinished = "goalTimeFinished" val goalCountNotFinished = "goalCountNotFinished" val goalCountFinished = "goalCountFinished"
// Add data testUtils.addActivity( goalTimeNotFinished, goals = listOf(GoalsTestUtils.getDailyDurationGoal(durationInSeconds)), ) testUtils.addRecord( typeName = goalTimeNotFinished, timeStarted = currentTime - TimeUnit.MINUTES.toMillis(5), timeEnded = currentTime, ) testUtils.addRunningRecord(goalTimeNotFinished)
testUtils.addActivity( goalTimeFinished, goals = listOf(GoalsTestUtils.getDailyDurationGoal(durationInSeconds)), ) testUtils.addRecord( typeName = goalTimeFinished, timeStarted = currentTime - TimeUnit.MINUTES.toMillis(10), timeEnded = currentTime, ) testUtils.addRunningRecord(goalTimeFinished)
testUtils.addActivity( goalCountNotFinished, goals = listOf(GoalsTestUtils.getDailyCountGoal(5)), ) testUtils.addRecord(goalCountNotFinished) testUtils.addRunningRecord(goalCountNotFinished)
testUtils.addActivity( goalCountFinished, goals = listOf(GoalsTestUtils.getDailyCountGoal(3)), ) testUtils.addRecord(goalCountFinished) testUtils.addRecord(goalCountFinished) testUtils.addRunningRecord(goalCountFinished)
// Goal time not finished scrollTo(goalTimeNotFinished) checkRunningGoal(goalTimeNotFinished, "$dailyGoal 4$minuteString") checkRunningMark(goalTimeNotFinished, isVisible = false)
// Goal time finished scrollTo(goalTimeFinished) checkRunningGoal(goalTimeFinished, dailyGoal) checkRunningMark(goalTimeFinished, isVisible = true)
// Goal count not finished scrollTo(goalCountNotFinished) checkRunningGoal(goalCountNotFinished, "$dailyGoal 3") checkRunningMark(goalCountNotFinished, isVisible = false)
// Goal count finished scrollTo(goalCountFinished) checkRunningGoal(goalCountFinished, dailyGoal) checkRunningMark(goalCountFinished, isVisible = true) }
@Test fun allGoals() { val dailyGoal = getString(coreR.string.change_record_type_daily_goal_time).lowercase() val currentTime = Calendar.getInstance().timeInMillis
val allGoalTimesPresent = "allGoalTimesPresent" val allGoalCountsPresent = "allGoalCountsPresent"
// Add data testUtils.addActivity( name = allGoalTimesPresent, goals = listOf( GoalsTestUtils.getSessionDurationGoal(durationInSeconds), GoalsTestUtils.getDailyDurationGoal(2 * durationInSeconds), GoalsTestUtils.getWeeklyDurationGoal(3 * durationInSeconds), GoalsTestUtils.getMonthlyDurationGoal(4 * durationInSeconds), ), ) testUtils.addRecord( typeName = allGoalTimesPresent, timeStarted = currentTime - TimeUnit.MINUTES.toMillis(5), timeEnded = currentTime, ) testUtils.addRunningRecord(allGoalTimesPresent)
testUtils.addActivity( name = allGoalCountsPresent, goals = listOf( GoalsTestUtils.getDailyCountGoal(10), GoalsTestUtils.getWeeklyCountGoal(10), GoalsTestUtils.getMonthlyCountGoal(10), ), ) testUtils.addRecord(allGoalCountsPresent) testUtils.addRecord(allGoalCountsPresent) testUtils.addRunningRecord(allGoalCountsPresent)
// All goal times scrollTo(allGoalTimesPresent) checkRunningGoal(allGoalTimesPresent, "$dailyGoal 14$minuteString") checkRunningMark(allGoalTimesPresent, isVisible = false)
// All goal counts scrollTo(allGoalCountsPresent) checkRunningGoal(allGoalCountsPresent, "$dailyGoal 7") checkRunningMark(allGoalCountsPresent, isVisible = false) }
@Test fun otherGoals() { val goalTime = "goalTime" val goalCount = "goalCount"
// Add data testUtils.addActivity( goalTime, goals = listOf( GoalsTestUtils.getWeeklyDurationGoal(durationInSeconds), GoalsTestUtils.getMonthlyDurationGoal(durationInSeconds), ), ) testUtils.addRunningRecord(goalTime)
testUtils.addActivity( goalCount, goals = listOf( GoalsTestUtils.getWeeklyCountGoal(10), GoalsTestUtils.getMonthlyCountGoal(10), ), ) testUtils.addRunningRecord(goalCount)
// Weekly and monthly goals are not present scrollTo(goalTime) checkNoRunningGoal(goalTime) checkRunningMark(goalTime, isVisible = false)
scrollTo(goalCount) checkNoRunningGoal(goalCount) checkRunningMark(goalCount, isVisible = false) }
private fun scrollTo(typeName: String) { tryAction { scrollRecyclerToView( runningRecordsR.id.rvRunningRecordsList, allOf(withId(R.id.viewRunningRecordItem), hasDescendant(withText(typeName))), ) } }}