diff --git a/app/src/androidTest/java/com/example/util/simpletimetracker/AddCategoryTest.kt b/app/src/androidTest/java/com/example/util/simpletimetracker/AddCategoryTest.kt index 2f8bf1d55..16d1a2963 100644 --- a/app/src/androidTest/java/com/example/util/simpletimetracker/AddCategoryTest.kt +++ b/app/src/androidTest/java/com/example/util/simpletimetracker/AddCategoryTest.kt @@ -86,6 +86,7 @@ class AddCategoryTest : BaseUiTest() { ) // Open activity chooser + clickOnViewWithText(coreR.string.change_category_color_hint) clickOnViewWithText(coreR.string.change_category_types_hint) checkViewIsNotDisplayed(withId(changeCategoryR.id.rvChangeCategoryColor)) checkViewIsDisplayed(withId(changeCategoryR.id.rvChangeCategoryType)) diff --git a/app/src/androidTest/java/com/example/util/simpletimetracker/AddDefaultRecordTypeTest.kt b/app/src/androidTest/java/com/example/util/simpletimetracker/AddDefaultRecordTypeTest.kt index 041b83f6b..78efd1f19 100644 --- a/app/src/androidTest/java/com/example/util/simpletimetracker/AddDefaultRecordTypeTest.kt +++ b/app/src/androidTest/java/com/example/util/simpletimetracker/AddDefaultRecordTypeTest.kt @@ -1,7 +1,14 @@ package com.example.util.simpletimetracker +import android.view.View +import androidx.test.espresso.Espresso.onView import androidx.test.espresso.Espresso.pressBack +import androidx.test.espresso.ViewAssertion +import androidx.test.espresso.assertion.PositionAssertions.isCompletelyAbove +import androidx.test.espresso.assertion.PositionAssertions.isCompletelyLeftOf +import androidx.test.espresso.assertion.PositionAssertions.isTopAlignedWith import androidx.test.espresso.matcher.ViewMatchers.hasDescendant +import androidx.test.espresso.matcher.ViewMatchers.isDescendantOfA import androidx.test.espresso.matcher.ViewMatchers.withId import androidx.test.espresso.matcher.ViewMatchers.withText import androidx.test.ext.junit.runners.AndroidJUnit4 @@ -14,22 +21,24 @@ import com.example.util.simpletimetracker.utils.tryAction import com.example.util.simpletimetracker.utils.withCardColor import dagger.hilt.android.testing.HiltAndroidTest import org.hamcrest.CoreMatchers.allOf +import org.hamcrest.Matcher import org.junit.Test import org.junit.runner.RunWith import com.example.util.simpletimetracker.core.R as coreR import com.example.util.simpletimetracker.feature_base_adapter.R as baseR -import com.example.util.simpletimetracker.feature_views.R as viewsR @HiltAndroidTest @RunWith(AndroidJUnit4::class) class AddDefaultRecordTypeTest : BaseUiTest() { @Test - fun addRecordType() { + fun default() { val name1 = "Games" + val name1next = "Tv" val color1 = ColorMapper.getAvailableColors()[1] - val name2 = "Work" - val color2 = ColorMapper.getAvailableColors()[10] + val name2 = "Chores" + val name2next = "Cleaning" + val color2 = ColorMapper.getAvailableColors()[5] tryAction { checkViewIsDisplayed( @@ -48,8 +57,11 @@ class AddDefaultRecordTypeTest : BaseUiTest() { // Open dialog clickOnViewWithText(coreR.string.running_records_add_default) Thread.sleep(1000) + checkViewIsDisplayed(withText(coreR.string.nothing_selected)) checkActivity(name1, color1) checkActivity(name2, color2) + checkOrder(name1, name1next, ::isCompletelyLeftOf, ::isTopAlignedWith) + checkOrder(name2, name2next, ::isCompletelyLeftOf, ::isTopAlignedWith) // Close without saving pressBack() @@ -61,21 +73,25 @@ class AddDefaultRecordTypeTest : BaseUiTest() { // Check selection clickOnViewWithText(coreR.string.running_records_add_default) clickOnViewWithText(name1) - checkActivity(name1, viewsR.color.colorFiltered) - checkActivity(name2, color2) + checkViewIsDisplayed(withText(coreR.string.something_selected)) + checkOrder(name1, name1next, ::isCompletelyAbove) + checkOrder(name2, name2next, ::isCompletelyLeftOf, ::isTopAlignedWith) clickOnViewWithText(name1) clickOnViewWithText(name2) - checkActivity(name1, color1) - checkActivity(name2, viewsR.color.colorFiltered) + checkViewIsDisplayed(withText(coreR.string.something_selected)) + checkOrder(name1, name1next, ::isCompletelyLeftOf, ::isTopAlignedWith) + checkOrder(name2, name2next, ::isCompletelyAbove) - clickOnViewWithText(coreR.string.types_filter_show_all) - checkActivity(name1, color1) - checkActivity(name2, color2) + clickOnViewWithText(coreR.string.select_all) + checkViewIsDisplayed(withText(coreR.string.something_selected)) + checkOrder(name1, name1next, ::isCompletelyLeftOf, ::isTopAlignedWith) + checkOrder(name2, name2next, ::isCompletelyLeftOf, ::isTopAlignedWith) - clickOnViewWithText(coreR.string.types_filter_hide_all) - checkActivity(name1, viewsR.color.colorFiltered) - checkActivity(name2, viewsR.color.colorFiltered) + clickOnViewWithText(coreR.string.select_nothing) + checkViewIsDisplayed(withText(coreR.string.nothing_selected)) + checkOrder(name1, name1next, ::isCompletelyLeftOf, ::isTopAlignedWith) + checkOrder(name2, name2next, ::isCompletelyLeftOf, ::isTopAlignedWith) // Try to save when nothing selected clickOnViewWithText(coreR.string.duration_dialog_save) @@ -101,9 +117,21 @@ class AddDefaultRecordTypeTest : BaseUiTest() { checkViewIsDisplayed( allOf( withId(baseR.id.viewRecordTypeItem), - withCardColor(color), + hasDescendant(withCardColor(color)), hasDescendant(withText(name)), ), ) } + + private fun checkOrder( + first: String, + second: String, + vararg matchers: (Matcher) -> ViewAssertion, + ) { + matchers.forEach { matcher -> + onView(allOf(isDescendantOfA(withId(baseR.id.viewRecordTypeItem)), withText(first))).check( + matcher(allOf(isDescendantOfA(withId(baseR.id.viewRecordTypeItem)), withText(second))) + ) + } + } } diff --git a/app/src/androidTest/java/com/example/util/simpletimetracker/AddRecordTypeTest.kt b/app/src/androidTest/java/com/example/util/simpletimetracker/AddRecordTypeTest.kt index 987425c20..d061d20fe 100644 --- a/app/src/androidTest/java/com/example/util/simpletimetracker/AddRecordTypeTest.kt +++ b/app/src/androidTest/java/com/example/util/simpletimetracker/AddRecordTypeTest.kt @@ -78,7 +78,7 @@ class AddRecordTypeTest : BaseUiTest() { // Selecting color clickOnRecyclerItem(changeRecordTypeR.id.rvChangeRecordTypeColor, withCardColor(firstColor)) - checkPreviewUpdated(withCardColor(firstColor)) + checkPreviewUpdated(hasDescendant(withCardColor(firstColor))) checkViewIsDisplayed( allOf(withId(changeRecordTypeR.id.viewColorItemSelected), withParent(withCardColor(firstColor))), ) @@ -86,7 +86,7 @@ class AddRecordTypeTest : BaseUiTest() { // Selecting color scrollRecyclerToPosition(changeRecordTypeR.id.rvChangeRecordTypeColor, lastColorPosition) clickOnRecyclerItem(changeRecordTypeR.id.rvChangeRecordTypeColor, withCardColor(lastColor)) - checkPreviewUpdated(withCardColor(lastColor)) + checkPreviewUpdated(hasDescendant(withCardColor(lastColor))) checkViewIsDisplayed( allOf(withId(changeRecordTypeR.id.viewColorItemSelected), withParent(withCardColor(lastColor))), ) diff --git a/app/src/androidTest/java/com/example/util/simpletimetracker/ArchiveTest.kt b/app/src/androidTest/java/com/example/util/simpletimetracker/ArchiveTest.kt index 24336b84a..d0ccabd19 100644 --- a/app/src/androidTest/java/com/example/util/simpletimetracker/ArchiveTest.kt +++ b/app/src/androidTest/java/com/example/util/simpletimetracker/ArchiveTest.kt @@ -185,7 +185,7 @@ class ArchiveTest : BaseUiTest() { NavUtils.openRecordsScreen() clickOnViewWithId(recordsR.id.btnRecordAdd) clickOnViewWithText(coreR.string.change_record_type_field) - clickOnView(withText(name1)) + clickOnView(allOf(withId(R.id.viewRecordTypeItem), hasDescendant(withText(name1)))) tryAction { checkTagVisible(tag1) } checkTagNotVisible(tag2) checkTagVisible(tag3) diff --git a/app/src/androidTest/java/com/example/util/simpletimetracker/ChangeCategoryTest.kt b/app/src/androidTest/java/com/example/util/simpletimetracker/ChangeCategoryTest.kt index 0399e4358..568bd7b10 100644 --- a/app/src/androidTest/java/com/example/util/simpletimetracker/ChangeCategoryTest.kt +++ b/app/src/androidTest/java/com/example/util/simpletimetracker/ChangeCategoryTest.kt @@ -17,6 +17,7 @@ import com.example.util.simpletimetracker.utils.clickOnRecyclerItem import com.example.util.simpletimetracker.utils.clickOnViewWithText import com.example.util.simpletimetracker.utils.longClickOnView import com.example.util.simpletimetracker.utils.scrollRecyclerToView +import com.example.util.simpletimetracker.utils.tryAction import com.example.util.simpletimetracker.utils.typeTextIntoView import com.example.util.simpletimetracker.utils.withCardColor import dagger.hilt.android.testing.HiltAndroidTest @@ -73,6 +74,7 @@ class ChangeCategoryTest : BaseUiTest() { checkViewIsDisplayed( allOf(withId(changeCategoryR.id.viewColorItemSelected), withParent(withCardColor(lastColor))) ) + clickOnViewWithText(coreR.string.change_record_type_color_hint) clickOnViewWithText(coreR.string.change_category_types_hint) onView(withText(typeName1)).check(isCompletelyAbove(withId(changeCategoryR.id.viewDividerItem))) diff --git a/app/src/androidTest/java/com/example/util/simpletimetracker/ChangeRecordTypeTest.kt b/app/src/androidTest/java/com/example/util/simpletimetracker/ChangeRecordTypeTest.kt index 64fd572fa..1574c2016 100644 --- a/app/src/androidTest/java/com/example/util/simpletimetracker/ChangeRecordTypeTest.kt +++ b/app/src/androidTest/java/com/example/util/simpletimetracker/ChangeRecordTypeTest.kt @@ -56,7 +56,7 @@ class ChangeRecordTypeTest : BaseUiTest() { // Preview is updated checkPreviewUpdated(hasDescendant(withText(name))) - checkPreviewUpdated(withCardColor(firstColor)) + checkPreviewUpdated(hasDescendant(withCardColor(firstColor))) checkPreviewUpdated(hasDescendant(withTag(firstIcon))) // Change item @@ -69,7 +69,7 @@ class ChangeRecordTypeTest : BaseUiTest() { ) scrollRecyclerToView(changeRecordTypeR.id.rvChangeRecordTypeColor, withCardColor(lastColor)) clickOnRecyclerItem(changeRecordTypeR.id.rvChangeRecordTypeColor, withCardColor(lastColor)) - checkPreviewUpdated(withCardColor(lastColor)) + checkPreviewUpdated(hasDescendant(withCardColor(lastColor))) checkViewIsDisplayed( allOf(withId(changeRecordTypeR.id.viewColorItemSelected), withParent(withCardColor(lastColor))), ) diff --git a/app/src/androidTest/java/com/example/util/simpletimetracker/CustomColorTest.kt b/app/src/androidTest/java/com/example/util/simpletimetracker/CustomColorTest.kt index dfa78f3b2..6fea6bc06 100644 --- a/app/src/androidTest/java/com/example/util/simpletimetracker/CustomColorTest.kt +++ b/app/src/androidTest/java/com/example/util/simpletimetracker/CustomColorTest.kt @@ -190,7 +190,7 @@ class CustomColorTest : BaseUiTest() { // Select color clickOnViewWithText(coreR.string.change_record_type_color_hint) clickOnRecyclerItem(changeRecordTypeR.id.rvChangeRecordTypeColor, withCardColorInt(colorInt)) - checkPreviewUpdated(withCardColorInt(colorInt)) + checkPreviewUpdated(hasDescendant(withCardColorInt(colorInt))) checkViewIsDisplayed(allOf(withId(dialogsR.id.viewColorItemSelected), withParent(withCardColorInt(colorInt)))) // Check selected color is preselected on color selection @@ -211,7 +211,7 @@ class CustomColorTest : BaseUiTest() { clickOnViewWithText(coreR.string.duration_dialog_save) // Check new color selected - checkPreviewUpdated(withCardColorInt(customColorInt)) + checkPreviewUpdated(hasDescendant(withCardColorInt(customColorInt))) checkViewIsNotDisplayed( allOf(withId(dialogsR.id.viewColorItemSelected), withParent(withCardColorInt(colorInt))) ) @@ -231,12 +231,12 @@ class CustomColorTest : BaseUiTest() { checkViewIsDisplayed( allOf( withId(dialogsR.id.viewRecordTypeItem), - withCardColorInt(customColorInt), + hasDescendant(withCardColorInt(customColorInt)), hasDescendant(withText(name)), ) ) longClickOnView(withText(name)) - checkPreviewUpdated(withCardColorInt(customColorInt)) + checkPreviewUpdated(hasDescendant(withCardColorInt(customColorInt))) clickOnViewWithText(coreR.string.change_record_type_color_hint) checkViewIsDisplayed( allOf( @@ -343,6 +343,7 @@ class CustomColorTest : BaseUiTest() { withParent(withId(dialogsR.id.layoutColorPaletteItem)) ) ) + clickOnViewWithText(coreR.string.change_category_color_hint) // Save tag typeTextIntoView(changeCategoryR.id.etChangeCategoryName, categoryName) diff --git a/app/src/androidTest/java/com/example/util/simpletimetracker/DeleteRecordTypeTest.kt b/app/src/androidTest/java/com/example/util/simpletimetracker/DeleteRecordTypeTest.kt index 5987c9137..51995d500 100644 --- a/app/src/androidTest/java/com/example/util/simpletimetracker/DeleteRecordTypeTest.kt +++ b/app/src/androidTest/java/com/example/util/simpletimetracker/DeleteRecordTypeTest.kt @@ -35,6 +35,7 @@ class DeleteRecordTypeTest : BaseUiTest() { val icon = firstIcon // Add item + Thread.sleep(1000) testUtils.addActivity(name = name, color = color, icon = icon) testUtils.addRecord(name) @@ -44,7 +45,7 @@ class DeleteRecordTypeTest : BaseUiTest() { withId(baseR.id.viewRecordTypeItem), hasDescendant(withText(name)), hasDescendant(withTag(icon)), - withCardColor(color) + hasDescendant(withCardColor(color)) ) ) } diff --git a/app/src/androidTest/java/com/example/util/simpletimetracker/SettingsTest.kt b/app/src/androidTest/java/com/example/util/simpletimetracker/SettingsTest.kt index a7bfbaab1..583c30e14 100644 --- a/app/src/androidTest/java/com/example/util/simpletimetracker/SettingsTest.kt +++ b/app/src/androidTest/java/com/example/util/simpletimetracker/SettingsTest.kt @@ -91,13 +91,6 @@ class SettingsTest : BaseUiTest() { allOf(withText(coreR.string.untracked_time_name), isCompletelyDisplayed()), ) - // Add record - NavUtils.addRecord(name) - checkViewDoesNotExist( - allOf(withText(coreR.string.untracked_time_name), isCompletelyDisplayed()), - ) - checkViewIsDisplayed(allOf(withText(name), isCompletelyDisplayed())) - // Change setting NavUtils.openSettingsScreen() onView(withId(settingsR.id.checkboxSettingsShowUntrackedInRecords)).perform(nestedScrollTo()) @@ -108,7 +101,6 @@ class SettingsTest : BaseUiTest() { // Untracked is shown NavUtils.openRecordsScreen() checkViewIsDisplayed(allOf(withText(coreR.string.untracked_time_name), isCompletelyDisplayed())) - checkViewIsDisplayed(allOf(withText(name), isCompletelyDisplayed())) } @Test @@ -142,7 +134,7 @@ class SettingsTest : BaseUiTest() { // Add record NavUtils.openRecordsScreen() - NavUtils.addRecord(name) + testUtils.addRecord(name) NavUtils.openStatisticsScreen() checkViewDoesNotExist( allOf(withText(coreR.string.untracked_time_name), isCompletelyDisplayed()), diff --git a/app/src/androidTest/java/com/example/util/simpletimetracker/Widget.kt b/app/src/androidTest/java/com/example/util/simpletimetracker/Widget.kt index a3f1295d3..f223a9b59 100644 --- a/app/src/androidTest/java/com/example/util/simpletimetracker/Widget.kt +++ b/app/src/androidTest/java/com/example/util/simpletimetracker/Widget.kt @@ -53,7 +53,7 @@ class Widget : BaseUiTest() { checkViewIsDisplayed( allOf( withId(baseR.id.viewRecordTypeItem), - withCardColor(color), + hasDescendant(withCardColor(color)), hasDescendant(withText(name)) ) ) diff --git a/app/src/androidTest/java/com/example/util/simpletimetracker/WidgetUniversal.kt b/app/src/androidTest/java/com/example/util/simpletimetracker/WidgetUniversal.kt index 04d1247c2..f4060cf8d 100644 --- a/app/src/androidTest/java/com/example/util/simpletimetracker/WidgetUniversal.kt +++ b/app/src/androidTest/java/com/example/util/simpletimetracker/WidgetUniversal.kt @@ -202,7 +202,7 @@ class WidgetUniversal : BaseUiTest() { checkViewIsDisplayed( allOf( withId(baseR.id.viewRecordTypeItem), - withCardColor(color), + hasDescendant(withCardColor(color)), hasDescendant(withText(name)) ) ) diff --git a/app/src/androidTest/java/com/example/util/simpletimetracker/utils/NavUtils.kt b/app/src/androidTest/java/com/example/util/simpletimetracker/utils/NavUtils.kt index 19300e6ed..f4f753f89 100644 --- a/app/src/androidTest/java/com/example/util/simpletimetracker/utils/NavUtils.kt +++ b/app/src/androidTest/java/com/example/util/simpletimetracker/utils/NavUtils.kt @@ -216,6 +216,7 @@ object NavUtils { clickOnViewWithText(coreR.string.change_category_color_hint) scrollRecyclerToView(changeCategoryR.id.rvChangeCategoryColor, withCardColor(color)) clickOnRecyclerItem(changeCategoryR.id.rvChangeCategoryColor, withCardColor(color)) + clickOnViewWithText(coreR.string.change_category_color_hint) } // Activities