Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Razeeman committed Dec 10, 2023
1 parent 6649edc commit ebb15c1
Show file tree
Hide file tree
Showing 12 changed files with 62 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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(
Expand All @@ -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()
Expand All @@ -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)
Expand All @@ -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<View>) -> ViewAssertion,
) {
matchers.forEach { matcher ->
onView(allOf(isDescendantOfA(withId(baseR.id.viewRecordTypeItem)), withText(first))).check(
matcher(allOf(isDescendantOfA(withId(baseR.id.viewRecordTypeItem)), withText(second)))
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,15 @@ 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))),
)

// 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))),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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))),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)))
)
Expand All @@ -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(
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -44,7 +45,7 @@ class DeleteRecordTypeTest : BaseUiTest() {
withId(baseR.id.viewRecordTypeItem),
hasDescendant(withText(name)),
hasDescendant(withTag(icon)),
withCardColor(color)
hasDescendant(withCardColor(color))
)
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand All @@ -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
Expand Down Expand Up @@ -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()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class Widget : BaseUiTest() {
checkViewIsDisplayed(
allOf(
withId(baseR.id.viewRecordTypeItem),
withCardColor(color),
hasDescendant(withCardColor(color)),
hasDescendant(withText(name))
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ class WidgetUniversal : BaseUiTest() {
checkViewIsDisplayed(
allOf(
withId(baseR.id.viewRecordTypeItem),
withCardColor(color),
hasDescendant(withCardColor(color)),
hasDescendant(withText(name))
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit ebb15c1

Please sign in to comment.