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 StatisticsTest.kt
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643package com.example.util.simpletimetracker
import 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.withSubstringimport androidx.test.espresso.matcher.ViewMatchers.withTextimport androidx.test.ext.junit.runners.AndroidJUnit4import 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.clickOnViewWithIdOnPagerimport com.example.util.simpletimetracker.utils.clickOnViewWithTextimport com.example.util.simpletimetracker.utils.withCardColorimport com.example.util.simpletimetracker.utils.withTagimport dagger.hilt.android.testing.HiltAndroidTestimport java.util.concurrent.TimeUnitimport 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 StatisticsTest : BaseUiTest() {
@Test fun statistics() { val name = "Test1" val newName = "Test2"
// Add activities testUtils.addActivity(name = name, color = firstColor, icon = firstIcon) testUtils.addActivity(name = newName, color = lastColor, icon = lastIcon)
// Add records NavUtils.openRecordsScreen() testUtils.addRecord(name) testUtils.addRecord(newName) val before = System.currentTimeMillis() - TimeUnit.DAYS.toMillis(365 * 10) testUtils.addRecord(name, timeStarted = before, timeEnded = before)
NavUtils.openStatisticsScreen()
// Check day range checkRecordsRange(firstColor, lastColor, firstIcon, lastIcon, name, newName)
// Switch to week range clickOnView(allOf(withText(coreR.string.title_today), isCompletelyDisplayed())) clickOnViewWithText(coreR.string.range_week) checkRecordsRange(firstColor, lastColor, firstIcon, lastIcon, name, newName)
// Switch to month range clickOnView(allOf(withText(coreR.string.title_this_week), isCompletelyDisplayed())) clickOnViewWithText(coreR.string.range_month) checkRecordsRange(firstColor, lastColor, firstIcon, lastIcon, name, newName)
// Switch to year range clickOnView(allOf(withText(coreR.string.title_this_month), isCompletelyDisplayed())) clickOnViewWithText(coreR.string.range_year) checkRecordsRange(firstColor, lastColor, firstIcon, lastIcon, name, newName)
// Switch to last days range clickOnView(allOf(withText(coreR.string.title_this_year), isCompletelyDisplayed())) clickOnViewWithText(coreR.string.range_last) checkRecordsRange(firstColor, lastColor, firstIcon, lastIcon, name, newName, checkPrevious = false)
// Switch to overall range clickOnView(allOf(withText(coreR.string.range_last), isCompletelyDisplayed())) clickOnViewWithText(coreR.string.range_overall) Thread.sleep(1000)
checkViewIsDisplayed( allOf( withId(baseR.id.viewStatisticsItem), hasDescendant(withText(coreR.string.untracked_time_name)), hasDescendant(withSubstring("100%")), isCompletelyDisplayed(), ), ) clickOnViewWithIdOnPager(statisticsR.id.btnStatisticsChartFilter) clickOnViewWithText(coreR.string.untracked_time_name) pressBack() checkViewIsDisplayed( allOf( withId(baseR.id.viewStatisticsItem), withCardColor(firstColor), hasDescendant(withTag(firstIcon)), hasDescendant(withText(name)), hasDescendant(withSubstring("50%")), isCompletelyDisplayed(), ), ) checkViewIsDisplayed( allOf( withId(baseR.id.viewStatisticsItem), withCardColor(lastColor), hasDescendant(withTag(lastIcon)), hasDescendant(withText(newName)), hasDescendant(withSubstring("50%")), isCompletelyDisplayed(), ), ) checkViewIsDisplayed( allOf( withId(statisticsR.id.tvStatisticsInfoText), withText("2$hourString 0$minuteString"), ), ) checkViewIsDisplayed( allOf( withText(coreR.string.statistics_hint), isCompletelyDisplayed(), ), ) }
@Test fun statisticsCategories() { val typeName1 = "Type1" val typeName2 = "Type2" val typeName3 = "Type3" val typeName4 = "Type4" val typeName5 = "Type5" val categoryName1 = "Category1" val categoryName2 = "Category2" val categoryName3 = "Category3"
// Add categories NavUtils.openSettingsScreen() NavUtils.openCategoriesScreen() NavUtils.addCategory(categoryName1, firstColor) NavUtils.addCategory(categoryName2, lastColor) NavUtils.addCategory(categoryName3) pressBack()
// Add activities NavUtils.openRunningRecordsScreen() testUtils.addActivity(name = typeName1, categories = listOf(categoryName1)) testUtils.addActivity(name = typeName2, categories = listOf(categoryName1)) testUtils.addActivity(name = typeName3, categories = listOf(categoryName2)) testUtils.addActivity(name = typeName4, categories = listOf(categoryName1, categoryName2)) testUtils.addActivity(name = typeName5)
// Add records NavUtils.openRecordsScreen() testUtils.addRecord(typeName1) testUtils.addRecord(typeName2) testUtils.addRecord(typeName3) testUtils.addRecord(typeName4) testUtils.addRecord(typeName5) val before = System.currentTimeMillis() - TimeUnit.DAYS.toMillis(365 * 10) testUtils.addRecord(typeName1, timeStarted = before, timeEnded = before)
NavUtils.openStatisticsScreen() clickOnViewWithIdOnPager(statisticsR.id.btnStatisticsChartFilter) clickOnViewWithText(coreR.string.category_hint) pressBack()
// Check day range clickOnViewWithId(statisticsR.id.btnStatisticsContainerToday) clickOnViewWithText(coreR.string.range_day) checkCategoryRange(firstColor, lastColor, categoryName1, categoryName2, categoryName3)
// Switch to week range clickOnView(allOf(withText(coreR.string.title_today), isCompletelyDisplayed())) clickOnViewWithText(coreR.string.range_week) checkCategoryRange(firstColor, lastColor, categoryName1, categoryName2, categoryName3)
// Switch to month range clickOnView(allOf(withText(coreR.string.title_this_week), isCompletelyDisplayed())) clickOnViewWithText(coreR.string.range_month) checkCategoryRange(firstColor, lastColor, categoryName1, categoryName2, categoryName3)
// Switch to year range clickOnView(allOf(withText(coreR.string.title_this_month), isCompletelyDisplayed())) clickOnViewWithText(coreR.string.range_year) checkCategoryRange(firstColor, lastColor, categoryName1, categoryName2, categoryName3)
// Switch to last days range clickOnView(allOf(withText(coreR.string.title_this_year), isCompletelyDisplayed())) clickOnViewWithText(coreR.string.range_last) checkCategoryRange(firstColor, lastColor, categoryName1, categoryName2, categoryName3, checkPrevious = false)
// Switch to overall range clickOnView(allOf(withText(coreR.string.range_last), isCompletelyDisplayed())) clickOnViewWithText(coreR.string.range_overall) Thread.sleep(1000)
checkViewIsDisplayed( allOf( withId(baseR.id.viewStatisticsItem), hasDescendant(withText(coreR.string.untracked_time_name)), hasDescendant(withSubstring("100%")), isCompletelyDisplayed(), ), ) clickOnViewWithIdOnPager(statisticsR.id.btnStatisticsChartFilter) clickOnViewWithText(coreR.string.untracked_time_name) pressBack() checkViewIsDisplayed( allOf( withId(baseR.id.viewStatisticsItem), withCardColor(firstColor), hasDescendant(withText(categoryName1)), hasDescendant(withSubstring("50%")), isCompletelyDisplayed(), ), ) checkViewIsDisplayed( allOf( withId(baseR.id.viewStatisticsItem), withCardColor(lastColor), hasDescendant(withText(categoryName2)), hasDescendant(withSubstring("33%")), isCompletelyDisplayed(), ), ) checkViewIsDisplayed( allOf( withId(baseR.id.viewStatisticsItem), hasDescendant(withText(coreR.string.uncategorized_time_name)), hasDescendant(withSubstring("17%")), isCompletelyDisplayed(), ), ) checkViewIsDisplayed( allOf( withId(statisticsR.id.tvStatisticsInfoText), withText("6$hourString 0$minuteString"), ), ) checkViewIsDisplayed( allOf( withText(coreR.string.statistics_hint), isCompletelyDisplayed(), ), ) checkViewDoesNotExist( allOf( withId(baseR.id.viewStatisticsItem), hasDescendant(withText(categoryName3)), ), ) }
@Test fun statisticsTags() { val typeName1 = "Type1" val typeName2 = "Type2" val typeName3 = "Type3" val typeName4 = "Type4" val tagName1 = "Tag1" val tagName2 = "Tag2" val tagName3 = "Tag3"
// Add activities NavUtils.openRunningRecordsScreen() testUtils.addActivity(name = typeName1, color = firstColor) testUtils.addActivity(name = typeName2) testUtils.addActivity(name = typeName3) testUtils.addActivity(name = typeName4)
// Add tags NavUtils.openSettingsScreen() NavUtils.openCategoriesScreen() NavUtils.addRecordTag(tagName1, typeName1) NavUtils.addRecordTag(tagName2, null, lastColor) NavUtils.addRecordTag(tagName3) pressBack()
// Add records NavUtils.openRecordsScreen() testUtils.addRecord(typeName1, tagNames = listOf(tagName1)) testUtils.addRecord(typeName2, tagNames = listOf(tagName2)) testUtils.addRecord(typeName3, tagNames = listOf(tagName2)) testUtils.addRecord(typeName1, tagNames = listOf(tagName1, tagName2)) testUtils.addRecord(typeName4) val before = System.currentTimeMillis() - TimeUnit.DAYS.toMillis(365 * 10) testUtils.addRecord(typeName1, timeStarted = before, timeEnded = before)
NavUtils.openStatisticsScreen() clickOnViewWithIdOnPager(statisticsR.id.btnStatisticsChartFilter) clickOnViewWithText(coreR.string.record_tag_hint_short) pressBack()
// Check day range clickOnViewWithId(statisticsR.id.btnStatisticsContainerToday) clickOnViewWithText(coreR.string.range_day) checkTagRange(firstColor, lastColor, tagName1, tagName2, tagName3)
// Switch to week range clickOnView(allOf(withText(coreR.string.title_today), isCompletelyDisplayed())) clickOnViewWithText(coreR.string.range_week) checkTagRange(firstColor, lastColor, tagName1, tagName2, tagName3)
// Switch to month range clickOnView(allOf(withText(coreR.string.title_this_week), isCompletelyDisplayed())) clickOnViewWithText(coreR.string.range_month) checkTagRange(firstColor, lastColor, tagName1, tagName2, tagName3)
// Switch to year range clickOnView(allOf(withText(coreR.string.title_this_month), isCompletelyDisplayed())) clickOnViewWithText(coreR.string.range_year) checkTagRange(firstColor, lastColor, tagName1, tagName2, tagName3)
// Switch to last days range clickOnView(allOf(withText(coreR.string.title_this_year), isCompletelyDisplayed())) clickOnViewWithText(coreR.string.range_last) checkTagRange(firstColor, lastColor, tagName1, tagName2, tagName3, checkPrevious = false)
// Switch to overall range clickOnView(allOf(withText(coreR.string.range_last), isCompletelyDisplayed())) clickOnViewWithText(coreR.string.range_overall) Thread.sleep(1000)
checkViewIsDisplayed( allOf( withId(baseR.id.viewStatisticsItem), hasDescendant(withText(coreR.string.untracked_time_name)), hasDescendant(withSubstring("100%")), isCompletelyDisplayed(), ), ) clickOnViewWithIdOnPager(statisticsR.id.btnStatisticsChartFilter) clickOnViewWithText(coreR.string.untracked_time_name) pressBack() checkViewIsDisplayed( allOf( withId(baseR.id.viewStatisticsItem), withCardColor(firstColor), hasDescendant(withText(tagName1)), hasDescendant(withSubstring("33%")), isCompletelyDisplayed(), ), ) checkViewIsDisplayed( allOf( withId(baseR.id.viewStatisticsItem), withCardColor(lastColor), hasDescendant(withText(tagName2)), hasDescendant(withSubstring("50%")), isCompletelyDisplayed(), ), ) checkViewIsDisplayed( allOf( withId(baseR.id.viewStatisticsItem), hasDescendant(withText(coreR.string.change_record_untagged)), hasDescendant(withSubstring("17%")), isCompletelyDisplayed(), ), ) checkViewIsDisplayed( allOf( withId(statisticsR.id.tvStatisticsInfoText), withText("6$hourString 0$minuteString"), ), ) checkViewIsDisplayed( allOf( withText(coreR.string.statistics_hint), isCompletelyDisplayed(), ), ) checkViewDoesNotExist( allOf( withId(baseR.id.viewStatisticsItem), hasDescendant(withText(tagName3)), ), ) }
private fun checkRecordsRange( firstColor: Int, lastColor: Int, firstIcon: Int, lastIcon: Int, name: String, newName: String, checkPrevious: Boolean = true, ) { checkViewIsDisplayed( allOf( withId(baseR.id.viewStatisticsItem), hasDescendant(withText(coreR.string.untracked_time_name)), hasDescendant(withSubstring("%")), isCompletelyDisplayed(), ), ) checkViewIsDisplayed( allOf( withId(baseR.id.viewStatisticsItem), withCardColor(firstColor), hasDescendant(withTag(firstIcon)), hasDescendant(withText(name)), hasDescendant(withText("1$hourString 0$minuteString")), hasDescendant(withSubstring("%")), isCompletelyDisplayed(), ), ) checkViewIsDisplayed( allOf( withId(baseR.id.viewStatisticsItem), withCardColor(lastColor), hasDescendant(withTag(lastIcon)), hasDescendant(withText(newName)), hasDescendant(withText("1$hourString 0$minuteString")), hasDescendant(withSubstring("%")), isCompletelyDisplayed(), ), ) checkViewIsDisplayed( allOf( withId(statisticsR.id.layoutStatisticsInfoItem), hasDescendant(withText(coreR.string.statistics_total_tracked)), hasDescendant(withText("2$hourString 0$minuteString")), isCompletelyDisplayed(), ), ) checkViewIsDisplayed( allOf( withText(coreR.string.statistics_hint), isCompletelyDisplayed(), ), ) if (!checkPrevious) return clickOnViewWithId(statisticsR.id.btnStatisticsContainerPrevious) checkViewIsDisplayed( allOf( withId(baseR.id.viewStatisticsItem), hasDescendant(withText(coreR.string.untracked_time_name)), hasDescendant(withText("100%")), hasDescendant(withSubstring("$hourString 0$minuteString")), isCompletelyDisplayed(), ), ) checkViewIsDisplayed( allOf( withId(statisticsR.id.layoutStatisticsInfoItem), hasDescendant(withText(coreR.string.statistics_total_tracked)), hasDescendant(withText("0$secondString")), isCompletelyDisplayed(), ), ) checkViewDoesNotExist( allOf( withText(coreR.string.statistics_hint), isCompletelyDisplayed(), ), ) clickOnViewWithId(statisticsR.id.btnStatisticsContainerNext) }
private fun checkCategoryRange( firstColor: Int, lastColor: Int, categoryName1: String, categoryName2: String, categoryName3: String, checkPrevious: Boolean = true, ) { checkViewIsDisplayed( allOf( withId(baseR.id.viewStatisticsItem), hasDescendant(withText(coreR.string.untracked_time_name)), hasDescendant(withSubstring("%")), isCompletelyDisplayed(), ), ) checkViewIsDisplayed( allOf( withId(baseR.id.viewStatisticsItem), withCardColor(firstColor), hasDescendant(withText(categoryName1)), hasDescendant(withText("3$hourString 0$minuteString")), hasDescendant(withSubstring("%")), isCompletelyDisplayed(), ), ) checkViewIsDisplayed( allOf( withId(baseR.id.viewStatisticsItem), withCardColor(lastColor), hasDescendant(withText(categoryName2)), hasDescendant(withText("2$hourString 0$minuteString")), hasDescendant(withSubstring("%")), isCompletelyDisplayed(), ), ) checkViewIsDisplayed( allOf( withId(baseR.id.viewStatisticsItem), hasDescendant(withText(coreR.string.uncategorized_time_name)), hasDescendant(withText("1$hourString 0$minuteString")), hasDescendant(withSubstring("%")), isCompletelyDisplayed(), ), ) checkViewIsDisplayed( allOf( withId(statisticsR.id.tvStatisticsInfoText), withText("6$hourString 0$minuteString"), ), ) checkViewDoesNotExist( allOf( withId(baseR.id.viewStatisticsItem), hasDescendant(withText(categoryName3)), ), ) checkViewIsDisplayed( allOf( withText(coreR.string.statistics_hint), isCompletelyDisplayed(), ), ) if (!checkPrevious) return clickOnViewWithId(statisticsR.id.btnStatisticsContainerPrevious) checkViewIsDisplayed( allOf( withId(baseR.id.viewStatisticsItem), hasDescendant(withText(coreR.string.untracked_time_name)), hasDescendant(withText("100%")), hasDescendant(withSubstring("$hourString 0$minuteString")), isCompletelyDisplayed(), ), ) checkViewIsDisplayed( allOf( withId(statisticsR.id.layoutStatisticsInfoItem), hasDescendant(withText(coreR.string.statistics_total_tracked)), hasDescendant(withText("0$secondString")), isCompletelyDisplayed(), ), ) checkViewDoesNotExist( allOf( withText(coreR.string.statistics_hint), isCompletelyDisplayed(), ), ) clickOnViewWithId(statisticsR.id.btnStatisticsContainerNext) }
private fun checkTagRange( firstColor: Int, lastColor: Int, tagName1: String, tagName2: String, tagName3: String, checkPrevious: Boolean = true, ) { checkViewIsDisplayed( allOf( withId(baseR.id.viewStatisticsItem), hasDescendant(withText(coreR.string.untracked_time_name)), hasDescendant(withSubstring("%")), isCompletelyDisplayed(), ), ) checkViewIsDisplayed( allOf( withId(baseR.id.viewStatisticsItem), withCardColor(firstColor), hasDescendant(withText(tagName1)), hasDescendant(withText("2$hourString 0$minuteString")), hasDescendant(withSubstring("%")), isCompletelyDisplayed(), ), ) checkViewIsDisplayed( allOf( withId(baseR.id.viewStatisticsItem), withCardColor(lastColor), hasDescendant(withText(tagName2)), hasDescendant(withText("3$hourString 0$minuteString")), hasDescendant(withSubstring("%")), isCompletelyDisplayed(), ), ) checkViewIsDisplayed( allOf( withId(baseR.id.viewStatisticsItem), hasDescendant(withText(coreR.string.change_record_untagged)), hasDescendant(withText("1$hourString 0$minuteString")), hasDescendant(withSubstring("%")), isCompletelyDisplayed(), ), ) checkViewIsDisplayed( allOf( withId(statisticsR.id.tvStatisticsInfoText), withText("6$hourString 0$minuteString"), ), ) checkViewDoesNotExist( allOf( withId(baseR.id.viewStatisticsItem), hasDescendant(withText(tagName3)), ), ) checkViewIsDisplayed( allOf( withText(coreR.string.statistics_hint), isCompletelyDisplayed(), ), ) if (!checkPrevious) return clickOnViewWithId(statisticsR.id.btnStatisticsContainerPrevious) checkViewIsDisplayed( allOf( withId(baseR.id.viewStatisticsItem), hasDescendant(withText(coreR.string.untracked_time_name)), hasDescendant(withText("100%")), hasDescendant(withSubstring("$hourString 0$minuteString")), isCompletelyDisplayed(), ), ) checkViewIsDisplayed( allOf( withId(statisticsR.id.layoutStatisticsInfoItem), hasDescendant(withText(coreR.string.statistics_total_tracked)), hasDescendant(withText("0$secondString")), isCompletelyDisplayed(), ), ) checkViewDoesNotExist( allOf( withText(coreR.string.statistics_hint), isCompletelyDisplayed(), ), ) clickOnViewWithId(statisticsR.id.btnStatisticsContainerNext) }}