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 GoalsStatisticsTest.kt
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668package com.example.util.simpletimetracker
import androidx.test.espresso.Espresso.onViewimport androidx.test.espresso.Espresso.pressBackimport androidx.test.espresso.matcher.ViewMatchers.hasDescendantimport androidx.test.espresso.matcher.ViewMatchers.isCompletelyDisplayedimport 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.getDailyCountGoalCategoryimport com.example.util.simpletimetracker.GoalsTestUtils.getDailyDurationGoalimport com.example.util.simpletimetracker.GoalsTestUtils.getDailyDurationGoalCategoryimport com.example.util.simpletimetracker.GoalsTestUtils.getMonthlyCountGoalimport com.example.util.simpletimetracker.GoalsTestUtils.getMonthlyCountGoalCategoryimport com.example.util.simpletimetracker.GoalsTestUtils.getMonthlyDurationGoalimport com.example.util.simpletimetracker.GoalsTestUtils.getMonthlyDurationGoalCategoryimport com.example.util.simpletimetracker.GoalsTestUtils.getWeeklyCountGoalimport com.example.util.simpletimetracker.GoalsTestUtils.getWeeklyCountGoalCategoryimport com.example.util.simpletimetracker.GoalsTestUtils.getWeeklyDurationGoalimport com.example.util.simpletimetracker.GoalsTestUtils.getWeeklyDurationGoalCategoryimport com.example.util.simpletimetracker.utils.BaseUiTestimport com.example.util.simpletimetracker.utils.NavUtilsimport com.example.util.simpletimetracker.utils.clickOnViewWithIdimport com.example.util.simpletimetracker.utils.clickOnViewWithIdOnPagerimport com.example.util.simpletimetracker.utils.clickOnViewWithTextimport com.example.util.simpletimetracker.utils.scrollRecyclerInPagerToViewimport com.example.util.simpletimetracker.utils.scrollToBottomimport com.example.util.simpletimetracker.utils.tryActionimport dagger.hilt.android.testing.HiltAndroidTestimport org.hamcrest.CoreMatchers.allOfimport 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_statistics.R as statisticsR
@HiltAndroidTest@RunWith(AndroidJUnit4::class)class GoalsStatisticsTest : BaseUiTest() {
@Test fun dailyGoal() { val goal = getString(coreR.string.change_record_type_goal_time_hint).lowercase()
val goalTimeNotFinished = "goalTimeNotFinished" val goalTimeFinished = "goalTimeFinished" val goalCountNotFinished = "goalCountNotFinished" val goalCountFinished = "goalCountFinished" val otherGoals = "otherDailyGoals"
// Add data testUtils.addActivity( goalTimeNotFinished, goals = listOf(getDailyDurationGoal(4 * durationInSeconds)), ) addRecords(testUtils, goalTimeNotFinished)
testUtils.addActivity( goalTimeFinished, goals = listOf(getDailyDurationGoal(durationInSeconds)), ) addRecords(testUtils, goalTimeFinished)
testUtils.addActivity( goalCountNotFinished, goals = listOf(getDailyCountGoal(4)), ) addRecords(testUtils, goalCountNotFinished)
testUtils.addActivity( goalCountFinished, goals = listOf(getDailyCountGoal(3)), ) testUtils.addRecord(goalCountFinished) testUtils.addRecord(goalCountFinished) addRecords(testUtils, goalCountFinished)
testUtils.addActivity( otherGoals, goals = listOf( getWeeklyDurationGoal(durationInSeconds), getMonthlyCountGoal(1), ), ) addRecords(testUtils, otherGoals)
NavUtils.openStatisticsScreen()
// Goal time not finished scrollTo(goalTimeNotFinished) checkStatisticsGoal(goalTimeNotFinished, "10$minuteString", "$goal - 40$minuteString") checkStatisticsPercent(goalTimeNotFinished, "25%") checkStatisticsMark(goalTimeNotFinished, isVisible = false)
// Goal time finished scrollTo(goalTimeFinished) checkStatisticsGoal(goalTimeFinished, "10$minuteString", "$goal - 10$minuteString") checkStatisticsMark(goalTimeFinished, isVisible = true)
// Goal count not finished scrollTo(goalCountNotFinished) checkStatisticsGoal(goalCountNotFinished, "1 Record", "$goal - 4 Records") checkStatisticsPercent(goalCountNotFinished, "25%") checkStatisticsMark(goalCountNotFinished, isVisible = false)
// Goal count finished scrollTo(goalCountFinished) checkStatisticsGoal(goalCountFinished, "3 Records", "$goal - 3 Records") checkStatisticsMark(goalCountFinished, isVisible = true)
// Other goals scrollBottom() checkNoStatisticsGoal(otherGoals) }
@Test fun weeklyGoal() { val goal = getString(coreR.string.change_record_type_goal_time_hint).lowercase()
val goalTimeNotFinished = "goalTimeNotFinished" val goalTimeFinished = "goalTimeFinished" val goalCountNotFinished = "goalCountNotFinished" val goalCountFinished = "goalCountFinished" val otherGoals = "otherWeeklyGoals"
// Add data testUtils.addActivity( goalTimeNotFinished, goals = listOf(getWeeklyDurationGoal(4 * durationInSeconds)), ) addRecords(testUtils, goalTimeNotFinished)
testUtils.addActivity( goalTimeFinished, goals = listOf(getWeeklyDurationGoal(durationInSeconds)), ) addRecords(testUtils, goalTimeFinished)
testUtils.addActivity( goalCountNotFinished, goals = listOf(getWeeklyCountGoal(4)), ) addRecords(testUtils, goalCountNotFinished)
testUtils.addActivity( goalCountFinished, goals = listOf(getWeeklyCountGoal(3)), ) testUtils.addRecord(goalCountFinished) testUtils.addRecord(goalCountFinished) addRecords(testUtils, goalCountFinished)
testUtils.addActivity( otherGoals, goals = listOf( getDailyDurationGoal(durationInSeconds), getMonthlyCountGoal(1), ), ) addRecords(testUtils, otherGoals)
NavUtils.openStatisticsScreen() clickOnViewWithId(statisticsR.id.btnStatisticsContainerToday) clickOnViewWithText(coreR.string.range_week)
// Goal time not finished scrollTo(goalTimeNotFinished) checkStatisticsGoal(goalTimeNotFinished, "20$minuteString", "$goal - 40$minuteString") checkStatisticsPercent(goalTimeNotFinished, "50%") checkStatisticsMark(goalTimeNotFinished, isVisible = false)
// Goal time finished scrollTo(goalTimeFinished) checkStatisticsGoal(goalTimeFinished, "20$minuteString", "$goal - 10$minuteString") checkStatisticsMark(goalTimeFinished, isVisible = true)
// Goal count not finished scrollTo(goalCountNotFinished) checkStatisticsGoal(goalCountNotFinished, "2 Records", "$goal - 4 Records") checkStatisticsPercent(goalCountNotFinished, "50%") checkStatisticsMark(goalCountNotFinished, isVisible = false)
// Goal count finished scrollTo(goalCountFinished) checkStatisticsGoal(goalCountFinished, "4 Records", "$goal - 3 Records") checkStatisticsMark(goalCountFinished, isVisible = true)
// Other goals scrollBottom() checkNoStatisticsGoal(otherGoals) }
@Test fun monthlyGoal() { val goal = getString(coreR.string.change_record_type_goal_time_hint).lowercase()
val goalTimeNotFinished = "goalTimeNotFinished" val goalTimeFinished = "goalTimeFinished" val goalCountNotFinished = "goalCountNotFinished" val goalCountFinished = "goalCountFinished" val otherGoals = "otherMonthlyGoals"
// Add data testUtils.addActivity( goalTimeNotFinished, goals = listOf(getMonthlyDurationGoal(4 * durationInSeconds)), ) addRecords(testUtils, goalTimeNotFinished)
testUtils.addActivity( goalTimeFinished, goals = listOf(getMonthlyDurationGoal(durationInSeconds)), ) addRecords(testUtils, goalTimeFinished)
testUtils.addActivity( goalCountNotFinished, goals = listOf(getMonthlyCountGoal(4)), ) addRecords(testUtils, goalCountNotFinished)
testUtils.addActivity( goalCountFinished, goals = listOf(getMonthlyCountGoal(3)), ) testUtils.addRecord(goalCountFinished) testUtils.addRecord(goalCountFinished) addRecords(testUtils, goalCountFinished)
testUtils.addActivity( otherGoals, goals = listOf( getDailyDurationGoal(durationInSeconds), getWeeklyCountGoal(1), ), ) addRecords(testUtils, otherGoals)
NavUtils.openStatisticsScreen() clickOnViewWithId(statisticsR.id.btnStatisticsContainerToday) clickOnViewWithText(coreR.string.range_month)
// Goal time not finished scrollTo(goalTimeNotFinished) checkStatisticsGoal(goalTimeNotFinished, "30$minuteString", "$goal - 40$minuteString") checkStatisticsPercent(goalTimeNotFinished, "75%") checkStatisticsMark(goalTimeNotFinished, isVisible = false)
// Goal time finished scrollTo(goalTimeFinished) checkStatisticsGoal(goalTimeFinished, "30$minuteString", "$goal - 10$minuteString") checkStatisticsMark(goalTimeFinished, isVisible = true)
// Goal count not finished scrollTo(goalCountNotFinished) checkStatisticsGoal(goalCountNotFinished, "3 Records", "$goal - 4 Records") checkStatisticsPercent(goalCountNotFinished, "75%") checkStatisticsMark(goalCountNotFinished, isVisible = false)
// Goal count finished scrollTo(goalCountFinished) checkStatisticsGoal(goalCountFinished, "5 Records", "$goal - 3 Records") checkStatisticsMark(goalCountFinished, isVisible = true)
// Other goals scrollBottom() checkNoStatisticsGoal(otherGoals) }
@Test fun dailyCategoryGoal() { val goal = getString(coreR.string.change_record_type_goal_time_hint).lowercase()
val goalTimeNotFinished = "goalTimeNotFinished" val goalTimeFinished = "goalTimeFinished" val goalCountNotFinished = "goalCountNotFinished" val goalCountFinished = "goalCountFinished" val otherGoals = "otherDailyGoals"
// Add data testUtils.addCategory( goalTimeNotFinished, goals = listOf(getDailyDurationGoalCategory(8 * durationInSeconds)), ) testUtils.addActivity( goalTimeNotFinished.first(), categories = listOf(goalTimeNotFinished), ) testUtils.addActivity( goalTimeNotFinished.second(), categories = listOf(goalTimeNotFinished), ) addRecords(testUtils, goalTimeNotFinished.first()) addRecords(testUtils, goalTimeNotFinished.second())
testUtils.addCategory( goalTimeFinished, goals = listOf(getDailyDurationGoalCategory(2 * durationInSeconds)), ) testUtils.addActivity( goalTimeFinished.first(), categories = listOf(goalTimeFinished), ) testUtils.addActivity( goalTimeFinished.second(), categories = listOf(goalTimeFinished), ) addRecords(testUtils, goalTimeFinished.first()) addRecords(testUtils, goalTimeFinished.second())
testUtils.addCategory( goalCountNotFinished, goals = listOf(getDailyCountGoalCategory(8)), ) testUtils.addActivity( goalCountNotFinished.first(), categories = listOf(goalCountNotFinished), ) testUtils.addActivity( goalCountNotFinished.second(), categories = listOf(goalCountNotFinished), ) addRecords(testUtils, goalCountNotFinished.first()) addRecords(testUtils, goalCountNotFinished.second())
testUtils.addCategory( goalCountFinished, goals = listOf(getDailyCountGoalCategory(3)), ) testUtils.addActivity( goalCountFinished.first(), categories = listOf(goalCountFinished), ) testUtils.addActivity( goalCountFinished.second(), categories = listOf(goalCountFinished), ) testUtils.addRecord(goalCountFinished.first()) testUtils.addRecord(goalCountFinished.second()) addRecords(testUtils, goalCountFinished.first())
testUtils.addCategory( otherGoals, goals = listOf( getWeeklyDurationGoalCategory(durationInSeconds), getMonthlyCountGoalCategory(1), ), ) testUtils.addActivity( otherGoals.first(), categories = listOf(otherGoals), ) testUtils.addActivity( otherGoals.second(), categories = listOf(otherGoals), ) addRecords(testUtils, otherGoals.first()) addRecords(testUtils, otherGoals.second())
NavUtils.openStatisticsScreen() clickOnViewWithIdOnPager(statisticsR.id.btnStatisticsChartFilter) clickOnViewWithText(coreR.string.category_hint) pressBack()
// Goal time not finished scrollTo(goalTimeNotFinished) checkStatisticsGoal(goalTimeNotFinished, "20$minuteString", "$goal - 1$hourString 20$minuteString") checkStatisticsPercent(goalTimeNotFinished, "25%") checkStatisticsMark(goalTimeNotFinished, isVisible = false)
// Goal time finished scrollTo(goalTimeFinished) checkStatisticsGoal(goalTimeFinished, "20$minuteString", "$goal - 20$minuteString") checkStatisticsMark(goalTimeFinished, isVisible = true)
// Goal count not finished scrollTo(goalCountNotFinished) checkStatisticsGoal(goalCountNotFinished, "2 Records", "$goal - 8 Records") checkStatisticsPercent(goalCountNotFinished, "25%") checkStatisticsMark(goalCountNotFinished, isVisible = false)
// Goal count finished scrollTo(goalCountFinished) checkStatisticsGoal(goalCountFinished, "3 Records", "$goal - 3 Records") checkStatisticsMark(goalCountFinished, isVisible = true)
// Other goals scrollBottom() checkNoStatisticsGoal(otherGoals) }
@Test fun weeklyCategoryGoal() { val goal = getString(coreR.string.change_record_type_goal_time_hint).lowercase()
val goalTimeNotFinished = "goalTimeNotFinished" val goalTimeFinished = "goalTimeFinished" val goalCountNotFinished = "goalCountNotFinished" val goalCountFinished = "goalCountFinished" val otherGoals = "otherWeeklyGoals"
// Add data testUtils.addCategory( goalTimeNotFinished, goals = listOf(getWeeklyDurationGoalCategory(8 * durationInSeconds)), ) testUtils.addActivity( goalTimeNotFinished.first(), categories = listOf(goalTimeNotFinished), ) testUtils.addActivity( goalTimeNotFinished.second(), categories = listOf(goalTimeNotFinished), ) addRecords(testUtils, goalTimeNotFinished.first()) addRecords(testUtils, goalTimeNotFinished.second())
testUtils.addCategory( goalTimeFinished, goals = listOf(getWeeklyDurationGoalCategory(2 * durationInSeconds)), ) testUtils.addActivity( goalTimeFinished.first(), categories = listOf(goalTimeFinished), ) testUtils.addActivity( goalTimeFinished.second(), categories = listOf(goalTimeFinished), ) addRecords(testUtils, goalTimeFinished.first()) addRecords(testUtils, goalTimeFinished.second())
testUtils.addCategory( goalCountNotFinished, goals = listOf(getWeeklyCountGoalCategory(8)), ) testUtils.addActivity( goalCountNotFinished.first(), categories = listOf(goalCountNotFinished), ) testUtils.addActivity( goalCountNotFinished.second(), categories = listOf(goalCountNotFinished), ) addRecords(testUtils, goalCountNotFinished.first()) addRecords(testUtils, goalCountNotFinished.second())
testUtils.addCategory( goalCountFinished, goals = listOf(getWeeklyCountGoalCategory(3)), ) testUtils.addActivity( goalCountFinished.first(), categories = listOf(goalCountFinished), ) testUtils.addActivity( goalCountFinished.second(), categories = listOf(goalCountFinished), ) testUtils.addRecord(goalCountFinished.first()) testUtils.addRecord(goalCountFinished.second()) addRecords(testUtils, goalCountFinished.first())
testUtils.addCategory( otherGoals, goals = listOf( getDailyDurationGoalCategory(durationInSeconds), getMonthlyCountGoalCategory(1), ), ) testUtils.addActivity( otherGoals.first(), categories = listOf(otherGoals), ) testUtils.addActivity( otherGoals.second(), categories = listOf(otherGoals), ) addRecords(testUtils, otherGoals.first()) addRecords(testUtils, otherGoals.second())
NavUtils.openStatisticsScreen() clickOnViewWithId(statisticsR.id.btnStatisticsContainerToday) clickOnViewWithText(coreR.string.range_week) clickOnViewWithIdOnPager(statisticsR.id.btnStatisticsChartFilter) clickOnViewWithText(coreR.string.category_hint) pressBack()
// Goal time not finished scrollTo(goalTimeNotFinished) checkStatisticsGoal(goalTimeNotFinished, "40$minuteString", "$goal - 1$hourString 20$minuteString") checkStatisticsPercent(goalTimeNotFinished, "50%") checkStatisticsMark(goalTimeNotFinished, isVisible = false)
// Goal time finished scrollTo(goalTimeFinished) checkStatisticsGoal(goalTimeFinished, "40$minuteString", "$goal - 20$minuteString") checkStatisticsMark(goalTimeFinished, isVisible = true)
// Goal count not finished scrollTo(goalCountNotFinished) checkStatisticsGoal(goalCountNotFinished, "4 Records", "$goal - 8 Records") checkStatisticsPercent(goalCountNotFinished, "50%") checkStatisticsMark(goalCountNotFinished, isVisible = false)
// Goal count finished scrollTo(goalCountFinished) checkStatisticsGoal(goalCountFinished, "4 Records", "$goal - 3 Records") checkStatisticsMark(goalCountFinished, isVisible = true)
// Other goals scrollBottom() checkNoStatisticsGoal(otherGoals) }
@Test fun monthlyCategoryGoal() { val goal = getString(coreR.string.change_record_type_goal_time_hint).lowercase()
val goalTimeNotFinished = "goalTimeNotFinished" val goalTimeFinished = "goalTimeFinished" val goalCountNotFinished = "goalCountNotFinished" val goalCountFinished = "goalCountFinished" val otherGoals = "otherMonthlyGoals"
// Add data testUtils.addCategory( goalTimeNotFinished, goals = listOf(getMonthlyDurationGoalCategory(8 * durationInSeconds)), ) testUtils.addActivity( goalTimeNotFinished.first(), categories = listOf(goalTimeNotFinished), ) testUtils.addActivity( goalTimeNotFinished.second(), categories = listOf(goalTimeNotFinished), ) addRecords(testUtils, goalTimeNotFinished.first()) addRecords(testUtils, goalTimeNotFinished.second())
testUtils.addCategory( goalTimeFinished, goals = listOf(getMonthlyDurationGoalCategory(2 * durationInSeconds)), ) testUtils.addActivity( goalTimeFinished.first(), categories = listOf(goalTimeFinished), ) testUtils.addActivity( goalTimeFinished.second(), categories = listOf(goalTimeFinished), ) addRecords(testUtils, goalTimeFinished.first()) addRecords(testUtils, goalTimeFinished.second())
testUtils.addCategory( goalCountNotFinished, goals = listOf(getMonthlyCountGoalCategory(8)), ) testUtils.addActivity( goalCountNotFinished.first(), categories = listOf(goalCountNotFinished), ) testUtils.addActivity( goalCountNotFinished.second(), categories = listOf(goalCountNotFinished), ) addRecords(testUtils, goalCountNotFinished.first()) addRecords(testUtils, goalCountNotFinished.second())
testUtils.addCategory( goalCountFinished, goals = listOf(getMonthlyCountGoalCategory(3)), ) testUtils.addActivity( goalCountFinished.first(), categories = listOf(goalCountFinished), ) testUtils.addActivity( goalCountFinished.second(), categories = listOf(goalCountFinished), ) testUtils.addRecord(goalCountFinished.first()) testUtils.addRecord(goalCountFinished.second()) addRecords(testUtils, goalCountFinished.first())
testUtils.addCategory( otherGoals, goals = listOf( getDailyDurationGoalCategory(durationInSeconds), getWeeklyCountGoalCategory(1), ), ) testUtils.addActivity( otherGoals.first(), categories = listOf(otherGoals), ) testUtils.addActivity( otherGoals.second(), categories = listOf(otherGoals), ) addRecords(testUtils, otherGoals.first()) addRecords(testUtils, otherGoals.second())
NavUtils.openStatisticsScreen() clickOnViewWithId(statisticsR.id.btnStatisticsContainerToday) clickOnViewWithText(coreR.string.range_month) clickOnViewWithIdOnPager(statisticsR.id.btnStatisticsChartFilter) clickOnViewWithText(coreR.string.category_hint) pressBack()
// Goal time not finished scrollTo(goalTimeNotFinished) checkStatisticsGoal(goalTimeNotFinished, "1$hourString 0$minuteString", "$goal - 1$hourString 20$minuteString") checkStatisticsPercent(goalTimeNotFinished, "75%") checkStatisticsMark(goalTimeNotFinished, isVisible = false)
// Goal time finished scrollTo(goalTimeFinished) checkStatisticsGoal(goalTimeFinished, "1$hourString 0$minuteString", "$goal - 20$minuteString") checkStatisticsMark(goalTimeFinished, isVisible = true)
// Goal count not finished scrollTo(goalCountNotFinished) checkStatisticsGoal(goalCountNotFinished, "6 Records", "$goal - 8 Records") checkStatisticsPercent(goalCountNotFinished, "75%") checkStatisticsMark(goalCountNotFinished, isVisible = false)
// Goal count finished scrollTo(goalCountFinished) checkStatisticsGoal(goalCountFinished, "5 Records", "$goal - 3 Records") checkStatisticsMark(goalCountFinished, isVisible = true)
// Other goals scrollBottom() checkNoStatisticsGoal(otherGoals) }
private fun scrollTo(typeName: String) { tryAction { scrollRecyclerInPagerToView( statisticsR.id.rvStatisticsList, allOf(withId(baseR.id.viewStatisticsGoalItem), hasDescendant(withText(typeName))), ) } }
private fun scrollBottom() { onView(allOf(withId(statisticsR.id.rvStatisticsList), isCompletelyDisplayed())).perform(scrollToBottom()) }
private fun String.first(): String { return this + "1" }
private fun String.second(): String { return this + "2" }}