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 ChangeUntrackedTest.kt
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394package com.example.util.simpletimetracker
import android.view.Viewimport 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.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.checkViewIsNotDisplayedimport com.example.util.simpletimetracker.utils.clickOnRecyclerItemimport com.example.util.simpletimetracker.utils.clickOnViewimport com.example.util.simpletimetracker.utils.clickOnViewWithIdimport com.example.util.simpletimetracker.utils.clickOnViewWithTextimport com.example.util.simpletimetracker.utils.tryActionimport com.example.util.simpletimetracker.utils.withCardColorimport com.example.util.simpletimetracker.utils.withTagimport dagger.hilt.android.testing.HiltAndroidTestimport java.util.concurrent.TimeUnitimport 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.R as changeRecordRimport com.example.util.simpletimetracker.feature_views.R as viewsR
@HiltAndroidTest@RunWith(AndroidJUnit4::class)class ChangeUntrackedTest : BaseUiTest() {
@Test fun changeUntracked() { val name = "Test" val color = firstColor val icon = firstIcon
// Add activity runBlocking { prefsInteractor.setShowUntrackedInRecords(true) } testUtils.addActivity(name = name, color = color, icon = icon) val yesterday = System.currentTimeMillis() - TimeUnit.DAYS.toMillis(1) testUtils.addRecord(typeName = name, timeStarted = yesterday, timeEnded = yesterday)
// Open edit view NavUtils.openRecordsScreen() clickOnView(allOf(withText(coreR.string.untracked_time_name), isCompletelyDisplayed()))
// View is set up checkViewIsNotDisplayed(withId(changeRecordR.id.btnChangeRecordDelete)) checkViewIsNotDisplayed(withId(changeRecordR.id.rvChangeRecordType)) checkPreviewUpdated(withCardColor(viewsR.color.colorUntracked))
// Change item clickOnViewWithText(coreR.string.change_record_type_field) clickOnRecyclerItem(changeRecordR.id.rvChangeRecordType, withText(name))
// Preview is updated checkPreviewUpdated(hasDescendant(withText(name))) checkPreviewUpdated(withCardColor(color)) checkPreviewUpdated(hasDescendant(withTag(icon)))
// Save clickOnViewWithText(coreR.string.change_record_type_save)
// Record updated tryAction { checkViewDoesNotExist(allOf(withText(coreR.string.untracked_time_name), isCompletelyDisplayed())) } checkViewIsDisplayed( allOf( withId(baseR.id.viewRecordItem), withCardColor(color), hasDescendant(withText(name)), hasDescendant(withTag(icon)), isCompletelyDisplayed(), ), )
// Delete record clickOnView(allOf(withText(name), isCompletelyDisplayed())) clickOnViewWithId(changeRecordR.id.btnChangeRecordDelete)
// Untracked is back tryAction { checkViewDoesNotExist(allOf(withText(name), isCompletelyDisplayed())) } checkViewIsDisplayed(allOf(withText(coreR.string.untracked_time_name), isCompletelyDisplayed())) }
private fun checkPreviewUpdated(matcher: Matcher<View>) = checkViewIsDisplayed(allOf(withId(changeRecordR.id.previewChangeRecord), matcher))}