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 DataEditTest.kt
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599package com.example.util.simpletimetracker
import androidx.test.espresso.Espresso.onViewimport androidx.test.espresso.Espresso.pressBackimport androidx.test.espresso.action.ViewActions.clickimport androidx.test.espresso.assertion.ViewAssertions.matchesimport androidx.test.espresso.matcher.ViewMatchers.hasDescendantimport androidx.test.espresso.matcher.ViewMatchers.isCheckedimport androidx.test.espresso.matcher.ViewMatchers.isCompletelyDisplayedimport androidx.test.espresso.matcher.ViewMatchers.isDescendantOfAimport androidx.test.espresso.matcher.ViewMatchers.isEnabledimport androidx.test.espresso.matcher.ViewMatchers.isNotCheckedimport androidx.test.espresso.matcher.ViewMatchers.isNotEnabledimport 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.feature_base_adapter.Rimport com.example.util.simpletimetracker.utils.BaseUiTestimport com.example.util.simpletimetracker.utils.NavUtilsimport com.example.util.simpletimetracker.utils.checkViewIsDisplayedimport com.example.util.simpletimetracker.utils.clickOnViewimport com.example.util.simpletimetracker.utils.clickOnViewWithIdimport com.example.util.simpletimetracker.utils.clickOnViewWithTextimport com.example.util.simpletimetracker.utils.nestedScrollToimport com.example.util.simpletimetracker.utils.nthChildOfimport com.example.util.simpletimetracker.utils.recyclerItemCountimport com.example.util.simpletimetracker.utils.typeTextIntoViewimport com.example.util.simpletimetracker.utils.withCardColorimport com.example.util.simpletimetracker.utils.withTagimport 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_data_edit.R as dataEditRimport com.example.util.simpletimetracker.feature_records.R as recordsR
@Suppress("SameParameterValue")@HiltAndroidTest@RunWith(AndroidJUnit4::class)class DataEditTest : BaseUiTest() {
@Test fun changeButtonState() { val name1 = "TypeName1" val name2 = "TypeName2"
// Add data testUtils.addActivity(name1) testUtils.addActivity(name2) testUtils.addRecord(name1)
// Check NavUtils.openSettingsScreen() NavUtils.openDataEditScreen() onView(withText(coreR.string.data_edit_button_change)).check(matches(isNotEnabled()))
onView(withId(dataEditR.id.checkboxDataEditChangeActivity)).perform(nestedScrollTo(), click()) clickOnViewWithText(name2) onView(withText(coreR.string.data_edit_button_change)).check(matches(isNotEnabled()))
clickOnViewWithText(coreR.string.data_edit_select_records) clickOnViewWithText(coreR.string.activity_hint) clickOnView(allOf(isDescendantOfA(withId(R.id.viewRecordTypeItem)), withText(name2))) pressBack() onView(withText(coreR.string.data_edit_button_change)).check(matches(isNotEnabled()))
clickOnViewWithText(coreR.string.data_edit_select_records) clickOnView(allOf(isDescendantOfA(withId(R.id.viewRecordTypeItem)), withText(name1))) pressBack() onView(withText(coreR.string.data_edit_button_change)).check(matches(isEnabled()))
onView(withId(dataEditR.id.checkboxDataEditChangeActivity)).perform(nestedScrollTo(), click()) onView(withText(coreR.string.data_edit_button_change)).check(matches(isNotEnabled())) }
@Test fun changeType() { val name1 = "TypeName1" val name2 = "TypeName2" val comment1 = "comment1" val comment2 = "comment2" val tag1 = "tag1" val tag2 = "tag2" val tag3 = "tag3"
// Add data testUtils.addActivity(name1, color = firstColor, icon = firstIcon) testUtils.addActivity(name2, color = lastColor, icon = lastIcon)
testUtils.addRecordTag(tag1, name1) testUtils.addRecordTag(tag2, name2) testUtils.addRecordTag(tag3)
testUtils.addRecord(name1, tagNames = listOf(tag1, tag3), comment = comment1) testUtils.addRecord(name1, tagNames = listOf(tag1, tag3), comment = comment1) testUtils.addRecord(name2, tagNames = listOf(tag2, tag3), comment = comment2) testUtils.addRecord(name2, tagNames = listOf(tag2, tag3), comment = comment2) testUtils.addRecord(name2, tagNames = listOf(tag2, tag3), comment = comment2)
// Check before NavUtils.openRecordsScreen() checkRecord( indexes = listOf(0, 1), name = "$name1 - $tag1, $tag3", color = firstColor, icon = firstIcon, comment = comment1, ) checkRecord( indexes = listOf(2, 3, 4), name = "$name2 - $tag2, $tag3", color = lastColor, icon = lastIcon, comment = comment2, )
// Select NavUtils.openSettingsScreen() NavUtils.openDataEditScreen() clickOnViewWithText(coreR.string.data_edit_select_records) clickOnViewWithText(coreR.string.activity_hint) clickOnView(allOf(isDescendantOfA(withId(R.id.viewRecordTypeItem)), withText(name1))) pressBack()
// Check checkViewIsDisplayed( allOf(withId(dataEditR.id.tvDataEditSelectedRecords), withSubstring("2")), ) onView(withText(coreR.string.data_edit_button_change)).check(matches(isNotEnabled())) onView(withId(dataEditR.id.checkboxDataEditChangeActivity)).perform(nestedScrollTo()) onView(withId(dataEditR.id.checkboxDataEditChangeActivity)).check(matches(isNotChecked())) clickOnViewWithId(dataEditR.id.checkboxDataEditChangeActivity) pressBack() onView(withText(coreR.string.data_edit_button_change)).check(matches(isNotEnabled())) onView(withId(dataEditR.id.checkboxDataEditChangeActivity)).perform(nestedScrollTo()) onView(withId(dataEditR.id.checkboxDataEditChangeActivity)).check(matches(isNotChecked()))
// Change onView(withId(dataEditR.id.checkboxDataEditChangeActivity)).perform(nestedScrollTo(), click()) clickOnViewWithText(name2) onView(withText(coreR.string.data_edit_button_change)).check(matches(isEnabled())) onView(withId(dataEditR.id.checkboxDataEditChangeActivity)).perform(nestedScrollTo()) onView(withId(dataEditR.id.checkboxDataEditChangeActivity)).check(matches(isChecked())) clickOnViewWithText(coreR.string.data_edit_button_change) clickOnViewWithText(coreR.string.data_edit_button_change) Thread.sleep(1000)
// Check checkViewIsDisplayed( allOf( withText(coreR.string.data_edit_success_message), withId(com.google.android.material.R.id.snackbar_text), ), ) NavUtils.openRecordsScreen() checkRecord( indexes = listOf(0, 1), name = "$name2 - $tag3", color = lastColor, icon = lastIcon, comment = comment1, ) checkRecord( indexes = listOf(2, 3, 4), name = "$name2 - $tag2, $tag3", color = lastColor, icon = lastIcon, comment = comment2, ) }
@Test fun changeComment() { val name1 = "TypeName1" val name2 = "TypeName2" val comment1 = "comment1" val comment2 = "comment2" val comment3 = "comment3" val tag1 = "tag1" val tag2 = "tag2" val tag3 = "tag3"
// Add data testUtils.addActivity(name1, color = firstColor, icon = firstIcon) testUtils.addActivity(name2, color = lastColor, icon = lastIcon)
testUtils.addRecordTag(tag1, name1) testUtils.addRecordTag(tag2, name2) testUtils.addRecordTag(tag3)
testUtils.addRecord(name1, tagNames = listOf(tag1, tag3), comment = comment1) testUtils.addRecord(name1, tagNames = listOf(tag1, tag3), comment = comment1) testUtils.addRecord(name2, tagNames = listOf(tag2, tag3), comment = comment2) testUtils.addRecord(name2, tagNames = listOf(tag2, tag3), comment = comment2) testUtils.addRecord(name2, tagNames = listOf(tag2, tag3), comment = comment2)
// Check before NavUtils.openRecordsScreen() checkRecord( indexes = listOf(0, 1), name = "$name1 - $tag1, $tag3", color = firstColor, icon = firstIcon, comment = comment1, ) checkRecord( indexes = listOf(2, 3, 4), name = "$name2 - $tag2, $tag3", color = lastColor, icon = lastIcon, comment = comment2, )
// Select NavUtils.openSettingsScreen() NavUtils.openDataEditScreen() clickOnViewWithText(coreR.string.data_edit_select_records) clickOnViewWithText(coreR.string.activity_hint) clickOnView(allOf(isDescendantOfA(withId(R.id.viewRecordTypeItem)), withText(name1))) pressBack()
// Check checkViewIsDisplayed( allOf(withId(dataEditR.id.tvDataEditSelectedRecords), withSubstring("2")), ) onView(withText(coreR.string.data_edit_button_change)).check(matches(isNotEnabled())) onView(withId(dataEditR.id.checkboxDataEditChangeComment)).perform(nestedScrollTo()) onView(withId(dataEditR.id.checkboxDataEditChangeComment)).check(matches(isNotChecked()))
// Change onView(withId(dataEditR.id.checkboxDataEditChangeComment)).perform(nestedScrollTo(), click()) typeTextIntoView(dataEditR.id.etDataEditChangeComment, comment3) onView(withText(coreR.string.data_edit_button_change)).check(matches(isEnabled())) onView(withId(dataEditR.id.checkboxDataEditChangeComment)).perform(nestedScrollTo()) onView(withId(dataEditR.id.checkboxDataEditChangeComment)).check(matches(isChecked())) clickOnViewWithText(coreR.string.data_edit_button_change) clickOnViewWithText(coreR.string.data_edit_button_change) Thread.sleep(1000)
// Check checkViewIsDisplayed( allOf( withText(coreR.string.data_edit_success_message), withId(com.google.android.material.R.id.snackbar_text), ), ) NavUtils.openRecordsScreen() checkRecord( indexes = listOf(0, 1), name = "$name1 - $tag1, $tag3", color = firstColor, icon = firstIcon, comment = comment3, ) checkRecord( indexes = listOf(2, 3, 4), name = "$name2 - $tag2, $tag3", color = lastColor, icon = lastIcon, comment = comment2, ) }
@Test fun addTags() { val name1 = "TypeName1" val name2 = "TypeName2" val comment1 = "comment1" val comment2 = "comment2" val tag1 = "tag1" val tag2 = "tag2" val tag3 = "tag3"
// Add data testUtils.addActivity(name1, color = firstColor, icon = firstIcon) testUtils.addActivity(name2, color = lastColor, icon = lastIcon)
testUtils.addRecordTag(tag1, name1) testUtils.addRecordTag(tag2, name2) testUtils.addRecordTag(tag3)
testUtils.addRecord(name1, comment = comment1) testUtils.addRecord(name1, comment = comment1) testUtils.addRecord(name2, tagNames = listOf(tag2, tag3), comment = comment2) testUtils.addRecord(name2, tagNames = listOf(tag2, tag3), comment = comment2) testUtils.addRecord(name2, tagNames = listOf(tag2, tag3), comment = comment2)
// Check before NavUtils.openRecordsScreen() checkRecord( indexes = listOf(0, 1), name = name1, color = firstColor, icon = firstIcon, comment = comment1, ) checkRecord( indexes = listOf(2, 3, 4), name = "$name2 - $tag2, $tag3", color = lastColor, icon = lastIcon, comment = comment2, )
// Select NavUtils.openSettingsScreen() NavUtils.openDataEditScreen() clickOnViewWithText(coreR.string.data_edit_select_records) clickOnViewWithText(coreR.string.activity_hint) clickOnView(allOf(isDescendantOfA(withId(R.id.viewRecordTypeItem)), withText(name1))) pressBack()
// Check checkViewIsDisplayed( allOf(withId(dataEditR.id.tvDataEditSelectedRecords), withSubstring("2")), ) onView(withText(coreR.string.data_edit_button_change)).check(matches(isNotEnabled())) onView(withId(dataEditR.id.checkboxDataEditAddTag)).perform(nestedScrollTo()) onView(withId(dataEditR.id.checkboxDataEditAddTag)).check(matches(isNotChecked())) clickOnViewWithId(dataEditR.id.checkboxDataEditAddTag) pressBack() onView(withText(coreR.string.data_edit_button_change)).check(matches(isNotEnabled())) onView(withId(dataEditR.id.checkboxDataEditAddTag)).perform(nestedScrollTo()) onView(withId(dataEditR.id.checkboxDataEditAddTag)).check(matches(isNotChecked()))
// Change onView(withId(dataEditR.id.checkboxDataEditAddTag)).perform(nestedScrollTo(), click()) clickOnViewWithText(tag1) clickOnViewWithText(tag3) clickOnViewWithText(coreR.string.records_filter_select) onView(withText(coreR.string.data_edit_button_change)).check(matches(isEnabled())) onView(withId(dataEditR.id.checkboxDataEditAddTag)).perform(nestedScrollTo()) onView(withId(dataEditR.id.checkboxDataEditAddTag)).check(matches(isChecked())) clickOnViewWithText(coreR.string.data_edit_button_change) clickOnViewWithText(coreR.string.data_edit_button_change) Thread.sleep(1000)
// Check checkViewIsDisplayed( allOf( withText(coreR.string.data_edit_success_message), withId(com.google.android.material.R.id.snackbar_text), ), ) NavUtils.openRecordsScreen() checkRecord( indexes = listOf(0, 1), name = "$name1 - $tag1, $tag3", color = firstColor, icon = firstIcon, comment = comment1, ) checkRecord( indexes = listOf(2, 3, 4), name = "$name2 - $tag2, $tag3", color = lastColor, icon = lastIcon, comment = comment2, ) }
@Test fun removeTags() { val name1 = "TypeName1" val name2 = "TypeName2" val comment1 = "comment1" val comment2 = "comment2" val tag1 = "tag1" val tag2 = "tag2" val tag3 = "tag3"
// Add data testUtils.addActivity(name1, color = firstColor, icon = firstIcon) testUtils.addActivity(name2, color = lastColor, icon = lastIcon)
testUtils.addRecordTag(tag1, name1) testUtils.addRecordTag(tag2, name2) testUtils.addRecordTag(tag3)
testUtils.addRecord(name1, tagNames = listOf(tag1, tag3), comment = comment1) testUtils.addRecord(name1, tagNames = listOf(tag1, tag3), comment = comment1) testUtils.addRecord(name2, tagNames = listOf(tag2, tag3), comment = comment2) testUtils.addRecord(name2, tagNames = listOf(tag2, tag3), comment = comment2) testUtils.addRecord(name2, tagNames = listOf(tag2, tag3), comment = comment2)
// Check before NavUtils.openRecordsScreen() checkRecord( indexes = listOf(0, 1), name = "$name1 - $tag1, $tag3", color = firstColor, icon = firstIcon, comment = comment1, ) checkRecord( indexes = listOf(2, 3, 4), name = "$name2 - $tag2, $tag3", color = lastColor, icon = lastIcon, comment = comment2, )
// Select NavUtils.openSettingsScreen() NavUtils.openDataEditScreen() clickOnViewWithText(coreR.string.data_edit_select_records) clickOnViewWithText(coreR.string.activity_hint) clickOnView(allOf(isDescendantOfA(withId(R.id.viewRecordTypeItem)), withText(name1))) pressBack()
// Check checkViewIsDisplayed( allOf(withId(dataEditR.id.tvDataEditSelectedRecords), withSubstring("2")), ) onView(withText(coreR.string.data_edit_button_change)).check(matches(isNotEnabled())) onView(withId(dataEditR.id.checkboxDataEditRemoveTag)).perform(nestedScrollTo()) onView(withId(dataEditR.id.checkboxDataEditRemoveTag)).check(matches(isNotChecked())) clickOnViewWithId(dataEditR.id.checkboxDataEditRemoveTag) pressBack() onView(withText(coreR.string.data_edit_button_change)).check(matches(isNotEnabled())) onView(withId(dataEditR.id.checkboxDataEditRemoveTag)).perform(nestedScrollTo()) onView(withId(dataEditR.id.checkboxDataEditRemoveTag)).check(matches(isNotChecked()))
// Change onView(withId(dataEditR.id.checkboxDataEditRemoveTag)).perform(nestedScrollTo(), click()) clickOnViewWithText(tag1) clickOnViewWithText(tag3) clickOnViewWithText(coreR.string.records_filter_select) onView(withText(coreR.string.data_edit_button_change)).check(matches(isEnabled())) onView(withId(dataEditR.id.checkboxDataEditRemoveTag)).perform(nestedScrollTo()) onView(withId(dataEditR.id.checkboxDataEditRemoveTag)).check(matches(isChecked())) clickOnViewWithText(coreR.string.data_edit_button_change) clickOnViewWithText(coreR.string.data_edit_button_change) Thread.sleep(1000)
// Check checkViewIsDisplayed( allOf( withText(coreR.string.data_edit_success_message), withId(com.google.android.material.R.id.snackbar_text), ), ) NavUtils.openRecordsScreen() checkRecord( indexes = listOf(0, 1), name = name1, color = firstColor, icon = firstIcon, comment = comment1, ) checkRecord( indexes = listOf(2, 3, 4), name = "$name2 - $tag2, $tag3", color = lastColor, icon = lastIcon, comment = comment2, ) }
@Test fun delete() { val name1 = "TypeName1" val name2 = "TypeName2" val comment1 = "comment1" val comment2 = "comment2" val tag1 = "tag1" val tag2 = "tag2" val tag3 = "tag3"
// Add data testUtils.addActivity(name1, color = firstColor, icon = firstIcon) testUtils.addActivity(name2, color = lastColor, icon = lastIcon)
testUtils.addRecordTag(tag1, name1) testUtils.addRecordTag(tag2, name2) testUtils.addRecordTag(tag3)
testUtils.addRecord(name1, tagNames = listOf(tag1, tag3), comment = comment1) testUtils.addRecord(name1, tagNames = listOf(tag1, tag3), comment = comment1) testUtils.addRecord(name2, tagNames = listOf(tag2, tag3), comment = comment2) testUtils.addRecord(name2, tagNames = listOf(tag2, tag3), comment = comment2) testUtils.addRecord(name2, tagNames = listOf(tag2, tag3), comment = comment2)
// Check before NavUtils.openRecordsScreen() checkRecord( indexes = listOf(0, 1), name = "$name1 - $tag1, $tag3", color = firstColor, icon = firstIcon, comment = comment1, ) checkRecord( indexes = listOf(2, 3, 4), name = "$name2 - $tag2, $tag3", color = lastColor, icon = lastIcon, comment = comment2, )
// Select NavUtils.openSettingsScreen() NavUtils.openDataEditScreen() clickOnViewWithText(coreR.string.data_edit_select_records) clickOnViewWithText(coreR.string.activity_hint) clickOnView(allOf(isDescendantOfA(withId(R.id.viewRecordTypeItem)), withText(name1))) pressBack()
// Check checkViewIsDisplayed( allOf(withId(dataEditR.id.tvDataEditSelectedRecords), withSubstring("2")), ) onView(withText(coreR.string.data_edit_button_change)).check(matches(isNotEnabled()))
// Select other changes onView(withId(dataEditR.id.checkboxDataEditChangeActivity)).perform(nestedScrollTo(), click()) clickOnViewWithText(name2) onView(withId(dataEditR.id.checkboxDataEditChangeActivity)).check(matches(isChecked()))
onView(withId(dataEditR.id.checkboxDataEditChangeComment)).perform(nestedScrollTo(), click()) typeTextIntoView(dataEditR.id.etDataEditChangeComment, "temp") onView(withId(dataEditR.id.checkboxDataEditChangeComment)).check(matches(isChecked()))
onView(withId(dataEditR.id.checkboxDataEditAddTag)).perform(nestedScrollTo(), click()) clickOnViewWithText(tag2) clickOnViewWithText(coreR.string.records_filter_select) onView(withId(dataEditR.id.checkboxDataEditAddTag)).check(matches(isChecked()))
onView(withId(dataEditR.id.checkboxDataEditRemoveTag)).perform(nestedScrollTo(), click()) clickOnViewWithText(tag3) clickOnViewWithText(coreR.string.records_filter_select) onView(withId(dataEditR.id.checkboxDataEditRemoveTag)).check(matches(isChecked()))
onView(withText(coreR.string.data_edit_button_change)).check(matches(isEnabled())) onView(withId(dataEditR.id.checkboxDataEditDeleteRecords)).perform(nestedScrollTo(), click())
// Other changes is reset onView(withId(dataEditR.id.checkboxDataEditChangeActivity)).perform(nestedScrollTo()) onView(withId(dataEditR.id.checkboxDataEditChangeActivity)).check(matches(isNotChecked())) onView(withId(dataEditR.id.checkboxDataEditChangeComment)).perform(nestedScrollTo()) onView(withId(dataEditR.id.checkboxDataEditChangeComment)).check(matches(isNotChecked())) onView(withId(dataEditR.id.checkboxDataEditAddTag)).perform(nestedScrollTo()) onView(withId(dataEditR.id.checkboxDataEditAddTag)).check(matches(isNotChecked())) onView(withId(dataEditR.id.checkboxDataEditRemoveTag)).perform(nestedScrollTo()) onView(withId(dataEditR.id.checkboxDataEditRemoveTag)).check(matches(isNotChecked()))
// Change onView(withText(coreR.string.data_edit_button_change)).check(matches(isEnabled())) onView(withId(dataEditR.id.checkboxDataEditDeleteRecords)).perform(nestedScrollTo()) onView(withId(dataEditR.id.checkboxDataEditDeleteRecords)).check(matches(isChecked())) clickOnViewWithText(coreR.string.data_edit_button_change) clickOnViewWithText(coreR.string.data_edit_button_change) Thread.sleep(1000)
// Check checkViewIsDisplayed( allOf( withText(coreR.string.data_edit_success_message), withId(com.google.android.material.R.id.snackbar_text), ), ) NavUtils.openRecordsScreen() onView(allOf(withId(recordsR.id.rvRecordsList), isCompletelyDisplayed())) .check(recyclerItemCount(4)) checkRecord( indexes = listOf(0, 1, 2), name = "$name2 - $tag2, $tag3", color = lastColor, icon = lastIcon, comment = comment2, ) }
private fun checkRecord( indexes: List<Int>, name: String, color: Int, icon: Int, comment: String, ) { indexes.forEach { index -> checkViewIsDisplayed( allOf( nthChildOf(withId(recordsR.id.rvRecordsList), index), withId(baseR.id.viewRecordItem), withCardColor(color), hasDescendant(withText(name)), hasDescendant(withTag(icon)), hasDescendant(withText(comment)), isCompletelyDisplayed(), ), ) } }}