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 GoalsTabTest.kt
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347package com.example.util.simpletimetracker
import android.view.Viewimport androidx.test.espresso.Espresso.onViewimport androidx.test.espresso.matcher.ViewMatchers.hasDescendantimport androidx.test.espresso.matcher.ViewMatchers.isCompletelyDisplayedimport 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.addRecordsimport com.example.util.simpletimetracker.GoalsTestUtils.checkNoStatisticsGoalimport com.example.util.simpletimetracker.GoalsTestUtils.checkStatisticsGoalimport com.example.util.simpletimetracker.GoalsTestUtils.checkStatisticsMarkimport com.example.util.simpletimetracker.GoalsTestUtils.checkStatisticsPercentimport com.example.util.simpletimetracker.GoalsTestUtils.durationInSecondsimport com.example.util.simpletimetracker.GoalsTestUtils.getDailyCountGoalimport com.example.util.simpletimetracker.GoalsTestUtils.getDailyDurationGoalimport com.example.util.simpletimetracker.GoalsTestUtils.getMonthlyCountGoalimport com.example.util.simpletimetracker.GoalsTestUtils.getMonthlyDurationGoalimport com.example.util.simpletimetracker.GoalsTestUtils.getSessionDurationGoalimport com.example.util.simpletimetracker.GoalsTestUtils.getWeeklyCountGoalimport com.example.util.simpletimetracker.GoalsTestUtils.getWeeklyDurationGoalimport com.example.util.simpletimetracker.domain.extension.valueimport com.example.util.simpletimetracker.domain.model.RecordTypeGoalimport com.example.util.simpletimetracker.feature_change_record.Rimport com.example.util.simpletimetracker.utils.BaseUiTestimport com.example.util.simpletimetracker.utils.NavUtilsimport com.example.util.simpletimetracker.utils.checkViewIsDisplayedimport com.example.util.simpletimetracker.utils.clickOnViewWithTextimport com.example.util.simpletimetracker.utils.longClickOnViewimport com.example.util.simpletimetracker.utils.scrollRecyclerToViewimport com.example.util.simpletimetracker.utils.selectTabAtPositionimport com.example.util.simpletimetracker.utils.tryActionimport dagger.hilt.android.testing.HiltAndroidTestimport kotlinx.coroutines.runBlockingimport org.hamcrest.CoreMatchers.allOfimport org.hamcrest.Matcherimport org.junit.Testimport org.junit.runner.RunWithimport com.example.util.simpletimetracker.core.R as coreRimport com.example.util.simpletimetracker.feature_base_adapter.R as baseRimport com.example.util.simpletimetracker.feature_change_record_type.R as changeRecordTypeRimport com.example.util.simpletimetracker.feature_goals.R as goalsRimport com.example.util.simpletimetracker.feature_main.R as mainR
@HiltAndroidTest@RunWith(AndroidJUnit4::class)class GoalsTabTest : BaseUiTest() {
override fun setUp() { super.setUp() runBlocking { prefsInteractor.setShowGoalsSeparately(true) } }
@Test fun goalsAdded() { val type = "type"
val goals = listOf( listOf(getSessionDurationGoal(durationInSeconds)), listOf(getDailyDurationGoal(durationInSeconds)), listOf(getDailyCountGoal(10)), listOf(getWeeklyDurationGoal(durationInSeconds)), listOf(getWeeklyCountGoal(10)), listOf(getMonthlyDurationGoal(durationInSeconds)), listOf(getMonthlyCountGoal(10)), listOf( getSessionDurationGoal(durationInSeconds), getDailyCountGoal(10), getWeeklyDurationGoal(2 * durationInSeconds), getMonthlyCountGoal(20), ), )
fun checkGoal(goal: RecordTypeGoal) { val layout = when (goal.range) { is RecordTypeGoal.Range.Session -> changeRecordTypeR.id.layoutChangeRecordTypeGoalSession is RecordTypeGoal.Range.Daily -> changeRecordTypeR.id.layoutChangeRecordTypeGoalDaily is RecordTypeGoal.Range.Weekly -> changeRecordTypeR.id.layoutChangeRecordTypeGoalWeekly is RecordTypeGoal.Range.Monthly -> changeRecordTypeR.id.layoutChangeRecordTypeGoalMonthly } val field = when (goal.type) { is RecordTypeGoal.Type.Duration -> changeRecordTypeR.id.tvChangeRecordTypeGoalDurationValue is RecordTypeGoal.Type.Count -> changeRecordTypeR.id.etChangeRecordTypeGoalCountValue } val value = when (goal.type) { is RecordTypeGoal.Type.Duration -> timeMapper.formatDuration(goal.value) is RecordTypeGoal.Type.Count -> goal.value.toString() }
checkViewIsDisplayed( allOf( isDescendantOfA(withId(layout)), withId(field), withText(value), ), ) }
testUtils.addActivity(type) Thread.sleep(1000)
// Check goals.forEach { goalsToAdd -> // Add goals tryAction { longClickOnView(withText(type)) } clickOnViewWithText(coreR.string.change_record_type_goal_time_hint) goalsToAdd.forEach { goal -> NavUtils.addGoalToActivity(goal) checkGoal(goal) } clickOnViewWithText(coreR.string.change_record_type_save)
// Check goals saved longClickOnView(withText(type)) clickOnViewWithText(coreR.string.change_record_type_goal_time_hint) goalsToAdd.forEach { goal -> checkGoal(goal) NavUtils.disableGoalOnActivity(goal) } clickOnViewWithText(coreR.string.change_record_type_save) } }
@Test fun noGoals() { val noGoals = "noGoals"
// Add data testUtils.addActivity(noGoals) NavUtils.openGoalsScreen()
// No goals checkViewIsDisplayed(allOf(withText(R.string.no_data), isCompletelyDisplayed())) }
@Test fun noGoalsInStatistics() { val goal = getString(coreR.string.change_record_type_goal_time_hint).lowercase()
val someGoals = "someGoals"
// Add data testUtils.addActivity( someGoals, goals = listOf( getDailyDurationGoal(durationInSeconds), ), )
// Goals on separate tab NavUtils.openGoalsScreen() checkStatisticsGoal(someGoals, "0$secondString", "$goal - 10$minuteString")
// No goals in statistics onView(withId(mainR.id.mainTabs)).perform(selectTabAtPosition(3)) Thread.sleep(1000) checkNoStatisticsGoal(someGoals) }
@Test fun allGoals() { val goal = getString(coreR.string.change_record_type_goal_time_hint).lowercase()
val goalDailyTimeNotFinished = "goalDailyTimeNotFinished" val goalDailyTimeFinished = "goalDailyTimeFinished" val goalDailyCountNotFinished = "goalDailyCountNotFinished" val goalDailyCountFinished = "goalDailyCountFinished" val goalWeeklyTimeNotFinished = "goalWeeklyTimeNotFinished" val goalWeeklyTimeFinished = "goalWeeklyTimeFinished" val goalWeeklyCountNotFinished = "goalWeeklyCountNotFinished" val goalWeeklyCountFinished = "goalWeeklyCountFinished" val goalMonthlyTimeNotFinished = "goalMonthlyTimeNotFinished" val goalMonthlyTimeFinished = "goalMonthlyTimeFinished" val goalMonthlyCountNotFinished = "goalMonthlyCountNotFinished" val goalMonthlyCountFinished = "goalMonthlyCountFinished"
// Add data // Daily testUtils.addActivity( goalDailyTimeNotFinished, goals = listOf(getDailyDurationGoal(4 * durationInSeconds)), ) addRecords(testUtils, goalDailyTimeNotFinished)
testUtils.addActivity( goalDailyTimeFinished, goals = listOf(getDailyDurationGoal(durationInSeconds)), ) addRecords(testUtils, goalDailyTimeFinished)
testUtils.addActivity( goalDailyCountNotFinished, goals = listOf(getDailyCountGoal(4)), ) addRecords(testUtils, goalDailyCountNotFinished)
testUtils.addActivity( goalDailyCountFinished, goals = listOf(getDailyCountGoal(3)), ) testUtils.addRecord(goalDailyCountFinished) testUtils.addRecord(goalDailyCountFinished) addRecords(testUtils, goalDailyCountFinished)
// Weekly testUtils.addActivity( goalWeeklyTimeNotFinished, goals = listOf(getWeeklyDurationGoal(4 * durationInSeconds)), ) addRecords(testUtils, goalWeeklyTimeNotFinished)
testUtils.addActivity( goalWeeklyTimeFinished, goals = listOf(getWeeklyDurationGoal(durationInSeconds)), ) addRecords(testUtils, goalWeeklyTimeFinished)
testUtils.addActivity( goalWeeklyCountNotFinished, goals = listOf(getWeeklyCountGoal(4)), ) addRecords(testUtils, goalWeeklyCountNotFinished)
testUtils.addActivity( goalWeeklyCountFinished, goals = listOf(getWeeklyCountGoal(3)), ) testUtils.addRecord(goalWeeklyCountFinished) testUtils.addRecord(goalWeeklyCountFinished) addRecords(testUtils, goalWeeklyCountFinished)
// Monthly testUtils.addActivity( goalMonthlyTimeNotFinished, goals = listOf(getMonthlyDurationGoal(4 * durationInSeconds)), ) addRecords(testUtils, goalMonthlyTimeNotFinished)
testUtils.addActivity( goalMonthlyTimeFinished, goals = listOf(getMonthlyDurationGoal(durationInSeconds)), ) addRecords(testUtils, goalMonthlyTimeFinished)
testUtils.addActivity( goalMonthlyCountNotFinished, goals = listOf(getMonthlyCountGoal(4)), ) addRecords(testUtils, goalMonthlyCountNotFinished)
testUtils.addActivity( goalMonthlyCountFinished, goals = listOf(getMonthlyCountGoal(3)), ) testUtils.addRecord(goalMonthlyCountFinished) testUtils.addRecord(goalMonthlyCountFinished) addRecords(testUtils, goalMonthlyCountFinished)
// Open tab NavUtils.openGoalsScreen()
// Daily // Goal time not finished scrollTo(goalDailyTimeNotFinished) checkStatisticsGoal(goalDailyTimeNotFinished, "10$minuteString", "$goal - 40$minuteString") checkStatisticsPercent(goalDailyTimeNotFinished, "25%") checkStatisticsMark(goalDailyTimeNotFinished, isVisible = false)
// Goal time finished scrollTo(goalDailyTimeFinished) checkStatisticsGoal(goalDailyTimeFinished, "10$minuteString", "$goal - 10$minuteString") checkStatisticsMark(goalDailyTimeFinished, isVisible = true)
// Goal count not finished scrollTo(goalDailyCountNotFinished) checkStatisticsGoal(goalDailyCountNotFinished, "1 Record", "$goal - 4 Records") checkStatisticsPercent(goalDailyCountNotFinished, "25%") checkStatisticsMark(goalDailyCountNotFinished, isVisible = false)
// Goal count finished scrollTo(goalDailyCountFinished) checkStatisticsGoal(goalDailyCountFinished, "3 Records", "$goal - 3 Records") checkStatisticsMark(goalDailyCountFinished, isVisible = true)
// Weekly // Goal time not finished scrollTo(goalWeeklyTimeNotFinished) checkStatisticsGoal(goalWeeklyTimeNotFinished, "20$minuteString", "$goal - 40$minuteString") checkStatisticsPercent(goalWeeklyTimeNotFinished, "50%") checkStatisticsMark(goalWeeklyTimeNotFinished, isVisible = false)
// Goal time finished scrollTo(goalWeeklyTimeFinished) checkStatisticsGoal(goalWeeklyTimeFinished, "20$minuteString", "$goal - 10$minuteString") checkStatisticsMark(goalWeeklyTimeFinished, isVisible = true)
// Goal count not finished scrollTo(goalWeeklyCountNotFinished) checkStatisticsGoal(goalWeeklyCountNotFinished, "2 Records", "$goal - 4 Records") checkStatisticsPercent(goalWeeklyCountNotFinished, "50%") checkStatisticsMark(goalWeeklyCountNotFinished, isVisible = false)
// Goal count finished scrollTo(goalWeeklyCountFinished) checkStatisticsGoal(goalWeeklyCountFinished, "4 Records", "$goal - 3 Records") checkStatisticsMark(goalWeeklyCountFinished, isVisible = true)
// Monthly // Goal time not finished scrollTo(goalMonthlyTimeNotFinished) checkStatisticsGoal(goalMonthlyTimeNotFinished, "30$minuteString", "$goal - 40$minuteString") checkStatisticsPercent(goalMonthlyTimeNotFinished, "75%") checkStatisticsMark(goalMonthlyTimeNotFinished, isVisible = false)
// Goal time finished scrollTo(goalMonthlyTimeFinished) checkStatisticsGoal(goalMonthlyTimeFinished, "30$minuteString", "$goal - 10$minuteString") checkStatisticsMark(goalMonthlyTimeFinished, isVisible = true)
// Goal count not finished scrollTo(goalMonthlyCountNotFinished) checkStatisticsGoal(goalMonthlyCountNotFinished, "3 Records", "$goal - 4 Records") checkStatisticsPercent(goalMonthlyCountNotFinished, "75%") checkStatisticsMark(goalMonthlyCountNotFinished, isVisible = false)
// Goal count finished scrollTo(goalMonthlyCountFinished) checkStatisticsGoal(goalMonthlyCountFinished, "5 Records", "$goal - 3 Records") checkStatisticsMark(goalMonthlyCountFinished, isVisible = true) }
private fun scrollTo( typeName: String, additionalMatcher: Matcher<View>? = null, ) { val matchers = listOfNotNull( withId(baseR.id.viewStatisticsGoalItem), hasDescendant(withText(typeName)), additionalMatcher, )
tryAction { scrollRecyclerToView(goalsR.id.rvGoalsList, allOf(matchers)) } }}