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 MainScreenEmptyTest.kt
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249package com.example.util.simpletimetracker
import androidx.test.espresso.Espresso.closeSoftKeyboardimport androidx.test.espresso.Espresso.pressBackimport 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.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.longClickOnViewWithIdimport com.example.util.simpletimetracker.utils.tryActionimport com.example.util.simpletimetracker.utils.typeTextIntoViewimport dagger.hilt.android.testing.HiltAndroidTestimport java.util.concurrent.TimeUnitimport kotlinx.coroutines.runBlockingimport 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_change_record_type.R as changeRecordTypeRimport com.example.util.simpletimetracker.feature_records.R as recordsRimport com.example.util.simpletimetracker.feature_statistics.R as statisticsR
@HiltAndroidTest@RunWith(AndroidJUnit4::class)class MainScreenEmptyTest : BaseUiTest() {
@Test fun mainScreenEmpty() { val name = "Test"
tryAction { checkViewIsDisplayed( withText( getString( coreR.string.running_records_types_empty, getString(coreR.string.running_records_add_type), getString(coreR.string.running_records_add_default), ), ), ) } checkViewDoesNotExist(withText(coreR.string.running_records_empty))
// Add activity NavUtils.openRunningRecordsScreen() clickOnView(withText(coreR.string.running_records_add_type)) typeTextIntoView(changeRecordTypeR.id.etChangeRecordTypeName, name) closeSoftKeyboard() clickOnView(withText(coreR.string.change_record_type_save)) checkViewDoesNotExist(withText(coreR.string.running_records_types_empty)) checkViewIsDisplayed(withText(coreR.string.running_records_empty))
// Start timer clickOnViewWithText(name) checkViewDoesNotExist(withText(coreR.string.running_records_empty)) clickOnView(allOf(isDescendantOfA(withId(baseR.id.viewRunningRecordItem)), withText(name))) tryAction { checkViewIsDisplayed(withText(coreR.string.running_records_empty)) } }
@Test fun recordsEmpty() { val name = "name" testUtils.addActivity(name) val timestamp = System.currentTimeMillis() - TimeUnit.DAYS.toMillis(7) testUtils.addRecord(name, timeStarted = timestamp, timeEnded = timestamp)
runBlocking { prefsInteractor.setShowUntrackedInRecords(true) }
NavUtils.openRecordsScreen() checkViewIsDisplayed( allOf( withId(baseR.id.viewRecordItem), hasDescendant(withText(coreR.string.untracked_time_name)), isCompletelyDisplayed(), ), ) checkViewIsDisplayed(allOf(withText(coreR.string.records_hint), isCompletelyDisplayed())) clickOnViewWithId(recordsR.id.btnRecordsContainerPrevious) checkViewIsDisplayed( allOf( withId(baseR.id.viewRecordItem), hasDescendant(withText(coreR.string.untracked_time_name)), hasDescendant(withSubstring("24$hourString 0$minuteString")), isCompletelyDisplayed(), ), ) checkViewIsDisplayed(allOf(withText(coreR.string.records_hint), isCompletelyDisplayed())) clickOnViewWithId(recordsR.id.btnRecordsContainerNext) clickOnViewWithId(recordsR.id.btnRecordsContainerNext) checkViewIsDisplayed(allOf(withText(coreR.string.no_data), isCompletelyDisplayed())) checkViewDoesNotExist(allOf(withText(coreR.string.records_hint), isCompletelyDisplayed())) checkViewDoesNotExist(allOf(withText(coreR.string.untracked_time_name), isCompletelyDisplayed())) }
@Test fun statisticsEmpty() { val name = "name" testUtils.addActivity(name) val timestamp = System.currentTimeMillis() - TimeUnit.DAYS.toMillis(500) testUtils.addRecord(name, timeStarted = timestamp, timeEnded = timestamp)
NavUtils.openStatisticsScreen() checkRanges()
// Week range clickOnViewWithId(statisticsR.id.btnStatisticsContainerToday) clickOnViewWithText(coreR.string.range_week) checkRanges()
// Month range clickOnViewWithId(statisticsR.id.btnStatisticsContainerToday) clickOnViewWithText(coreR.string.range_month) checkRanges()
// Year range clickOnViewWithId(statisticsR.id.btnStatisticsContainerToday) clickOnViewWithText(coreR.string.range_year) checkRanges()
// Overall range clickOnViewWithId(statisticsR.id.btnStatisticsContainerToday) clickOnViewWithText(coreR.string.range_overall) checkViewIsDisplayed( allOf( withId(baseR.id.viewStatisticsItem), hasDescendant(withText(coreR.string.untracked_time_name)), hasDescendant(withSubstring("100%")), isCompletelyDisplayed(), ), )
// Back to day range clickOnViewWithId(statisticsR.id.btnStatisticsContainerToday) clickOnViewWithText(coreR.string.range_day) checkRanges()
// Empty category statistics clickOnViewWithIdOnPager(statisticsR.id.btnStatisticsEmptyFilter) clickOnViewWithText(coreR.string.category_hint) pressBack() longClickOnViewWithId(statisticsR.id.btnStatisticsContainerToday)
// Day range clickOnViewWithId(statisticsR.id.btnStatisticsContainerToday) clickOnViewWithText(coreR.string.range_day) checkRanges()
// Week range clickOnViewWithId(statisticsR.id.btnStatisticsContainerToday) clickOnViewWithText(coreR.string.range_week) checkRanges()
// Month range clickOnViewWithId(statisticsR.id.btnStatisticsContainerToday) clickOnViewWithText(coreR.string.range_month) checkRanges()
// Year range clickOnViewWithId(statisticsR.id.btnStatisticsContainerToday) clickOnViewWithText(coreR.string.range_year) checkRanges()
// Overall range clickOnViewWithId(statisticsR.id.btnStatisticsContainerToday) clickOnViewWithText(coreR.string.range_overall) checkViewIsDisplayed( allOf( withId(baseR.id.viewStatisticsItem), hasDescendant(withText(coreR.string.untracked_time_name)), hasDescendant(withSubstring("100%")), isCompletelyDisplayed(), ), )
// Back to day range clickOnViewWithId(statisticsR.id.btnStatisticsContainerToday) clickOnViewWithText(coreR.string.range_day) checkRanges()
// Empty tag statistics clickOnViewWithIdOnPager(statisticsR.id.btnStatisticsEmptyFilter) clickOnViewWithText(coreR.string.record_tag_hint_short) pressBack() longClickOnViewWithId(statisticsR.id.btnStatisticsContainerToday)
// Day range clickOnViewWithId(statisticsR.id.btnStatisticsContainerToday) clickOnViewWithText(coreR.string.range_day) checkRanges()
// Week range clickOnViewWithId(statisticsR.id.btnStatisticsContainerToday) clickOnViewWithText(coreR.string.range_week) checkRanges()
// Month range clickOnViewWithId(statisticsR.id.btnStatisticsContainerToday) clickOnViewWithText(coreR.string.range_month) checkRanges()
// Year range clickOnViewWithId(statisticsR.id.btnStatisticsContainerToday) clickOnViewWithText(coreR.string.range_year) checkRanges()
// Overall range clickOnViewWithId(statisticsR.id.btnStatisticsContainerToday) clickOnViewWithText(coreR.string.range_overall) checkViewIsDisplayed( allOf( withId(baseR.id.viewStatisticsItem), hasDescendant(withText(coreR.string.untracked_time_name)), hasDescendant(withSubstring("100%")), isCompletelyDisplayed(), ), )
// Back to day range clickOnViewWithId(statisticsR.id.btnStatisticsContainerToday) clickOnViewWithText(coreR.string.range_day) checkRanges() }
private fun checkRanges() { checkViewIsDisplayed( allOf( withId(baseR.id.viewStatisticsItem), hasDescendant(withText(coreR.string.untracked_time_name)), hasDescendant(withSubstring("100%")), isCompletelyDisplayed(), ), ) clickOnViewWithId(statisticsR.id.btnStatisticsContainerNext) checkViewIsDisplayed(allOf(withText(coreR.string.no_data), isCompletelyDisplayed())) }}