Skip to content

Commit ebb15c1

Browse files
committed
fix tests
1 parent 6649edc commit ebb15c1

File tree

12 files changed

+62
-36
lines changed

12 files changed

+62
-36
lines changed

app/src/androidTest/java/com/example/util/simpletimetracker/AddCategoryTest.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ class AddCategoryTest : BaseUiTest() {
8686
)
8787

8888
// Open activity chooser
89+
clickOnViewWithText(coreR.string.change_category_color_hint)
8990
clickOnViewWithText(coreR.string.change_category_types_hint)
9091
checkViewIsNotDisplayed(withId(changeCategoryR.id.rvChangeCategoryColor))
9192
checkViewIsDisplayed(withId(changeCategoryR.id.rvChangeCategoryType))

app/src/androidTest/java/com/example/util/simpletimetracker/AddDefaultRecordTypeTest.kt

Lines changed: 43 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
package com.example.util.simpletimetracker
22

3+
import android.view.View
4+
import androidx.test.espresso.Espresso.onView
35
import androidx.test.espresso.Espresso.pressBack
6+
import androidx.test.espresso.ViewAssertion
7+
import androidx.test.espresso.assertion.PositionAssertions.isCompletelyAbove
8+
import androidx.test.espresso.assertion.PositionAssertions.isCompletelyLeftOf
9+
import androidx.test.espresso.assertion.PositionAssertions.isTopAlignedWith
410
import androidx.test.espresso.matcher.ViewMatchers.hasDescendant
11+
import androidx.test.espresso.matcher.ViewMatchers.isDescendantOfA
512
import androidx.test.espresso.matcher.ViewMatchers.withId
613
import androidx.test.espresso.matcher.ViewMatchers.withText
714
import androidx.test.ext.junit.runners.AndroidJUnit4
@@ -14,22 +21,24 @@ import com.example.util.simpletimetracker.utils.tryAction
1421
import com.example.util.simpletimetracker.utils.withCardColor
1522
import dagger.hilt.android.testing.HiltAndroidTest
1623
import org.hamcrest.CoreMatchers.allOf
24+
import org.hamcrest.Matcher
1725
import org.junit.Test
1826
import org.junit.runner.RunWith
1927
import com.example.util.simpletimetracker.core.R as coreR
2028
import com.example.util.simpletimetracker.feature_base_adapter.R as baseR
21-
import com.example.util.simpletimetracker.feature_views.R as viewsR
2229

2330
@HiltAndroidTest
2431
@RunWith(AndroidJUnit4::class)
2532
class AddDefaultRecordTypeTest : BaseUiTest() {
2633

2734
@Test
28-
fun addRecordType() {
35+
fun default() {
2936
val name1 = "Games"
37+
val name1next = "Tv"
3038
val color1 = ColorMapper.getAvailableColors()[1]
31-
val name2 = "Work"
32-
val color2 = ColorMapper.getAvailableColors()[10]
39+
val name2 = "Chores"
40+
val name2next = "Cleaning"
41+
val color2 = ColorMapper.getAvailableColors()[5]
3342

3443
tryAction {
3544
checkViewIsDisplayed(
@@ -48,8 +57,11 @@ class AddDefaultRecordTypeTest : BaseUiTest() {
4857
// Open dialog
4958
clickOnViewWithText(coreR.string.running_records_add_default)
5059
Thread.sleep(1000)
60+
checkViewIsDisplayed(withText(coreR.string.nothing_selected))
5161
checkActivity(name1, color1)
5262
checkActivity(name2, color2)
63+
checkOrder(name1, name1next, ::isCompletelyLeftOf, ::isTopAlignedWith)
64+
checkOrder(name2, name2next, ::isCompletelyLeftOf, ::isTopAlignedWith)
5365

5466
// Close without saving
5567
pressBack()
@@ -61,21 +73,25 @@ class AddDefaultRecordTypeTest : BaseUiTest() {
6173
// Check selection
6274
clickOnViewWithText(coreR.string.running_records_add_default)
6375
clickOnViewWithText(name1)
64-
checkActivity(name1, viewsR.color.colorFiltered)
65-
checkActivity(name2, color2)
76+
checkViewIsDisplayed(withText(coreR.string.something_selected))
77+
checkOrder(name1, name1next, ::isCompletelyAbove)
78+
checkOrder(name2, name2next, ::isCompletelyLeftOf, ::isTopAlignedWith)
6679

6780
clickOnViewWithText(name1)
6881
clickOnViewWithText(name2)
69-
checkActivity(name1, color1)
70-
checkActivity(name2, viewsR.color.colorFiltered)
82+
checkViewIsDisplayed(withText(coreR.string.something_selected))
83+
checkOrder(name1, name1next, ::isCompletelyLeftOf, ::isTopAlignedWith)
84+
checkOrder(name2, name2next, ::isCompletelyAbove)
7185

72-
clickOnViewWithText(coreR.string.types_filter_show_all)
73-
checkActivity(name1, color1)
74-
checkActivity(name2, color2)
86+
clickOnViewWithText(coreR.string.select_all)
87+
checkViewIsDisplayed(withText(coreR.string.something_selected))
88+
checkOrder(name1, name1next, ::isCompletelyLeftOf, ::isTopAlignedWith)
89+
checkOrder(name2, name2next, ::isCompletelyLeftOf, ::isTopAlignedWith)
7590

76-
clickOnViewWithText(coreR.string.types_filter_hide_all)
77-
checkActivity(name1, viewsR.color.colorFiltered)
78-
checkActivity(name2, viewsR.color.colorFiltered)
91+
clickOnViewWithText(coreR.string.select_nothing)
92+
checkViewIsDisplayed(withText(coreR.string.nothing_selected))
93+
checkOrder(name1, name1next, ::isCompletelyLeftOf, ::isTopAlignedWith)
94+
checkOrder(name2, name2next, ::isCompletelyLeftOf, ::isTopAlignedWith)
7995

8096
// Try to save when nothing selected
8197
clickOnViewWithText(coreR.string.duration_dialog_save)
@@ -101,9 +117,21 @@ class AddDefaultRecordTypeTest : BaseUiTest() {
101117
checkViewIsDisplayed(
102118
allOf(
103119
withId(baseR.id.viewRecordTypeItem),
104-
withCardColor(color),
120+
hasDescendant(withCardColor(color)),
105121
hasDescendant(withText(name)),
106122
),
107123
)
108124
}
125+
126+
private fun checkOrder(
127+
first: String,
128+
second: String,
129+
vararg matchers: (Matcher<View>) -> ViewAssertion,
130+
) {
131+
matchers.forEach { matcher ->
132+
onView(allOf(isDescendantOfA(withId(baseR.id.viewRecordTypeItem)), withText(first))).check(
133+
matcher(allOf(isDescendantOfA(withId(baseR.id.viewRecordTypeItem)), withText(second)))
134+
)
135+
}
136+
}
109137
}

app/src/androidTest/java/com/example/util/simpletimetracker/AddRecordTypeTest.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,15 +78,15 @@ class AddRecordTypeTest : BaseUiTest() {
7878

7979
// Selecting color
8080
clickOnRecyclerItem(changeRecordTypeR.id.rvChangeRecordTypeColor, withCardColor(firstColor))
81-
checkPreviewUpdated(withCardColor(firstColor))
81+
checkPreviewUpdated(hasDescendant(withCardColor(firstColor)))
8282
checkViewIsDisplayed(
8383
allOf(withId(changeRecordTypeR.id.viewColorItemSelected), withParent(withCardColor(firstColor))),
8484
)
8585

8686
// Selecting color
8787
scrollRecyclerToPosition(changeRecordTypeR.id.rvChangeRecordTypeColor, lastColorPosition)
8888
clickOnRecyclerItem(changeRecordTypeR.id.rvChangeRecordTypeColor, withCardColor(lastColor))
89-
checkPreviewUpdated(withCardColor(lastColor))
89+
checkPreviewUpdated(hasDescendant(withCardColor(lastColor)))
9090
checkViewIsDisplayed(
9191
allOf(withId(changeRecordTypeR.id.viewColorItemSelected), withParent(withCardColor(lastColor))),
9292
)

app/src/androidTest/java/com/example/util/simpletimetracker/ArchiveTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ class ArchiveTest : BaseUiTest() {
185185
NavUtils.openRecordsScreen()
186186
clickOnViewWithId(recordsR.id.btnRecordAdd)
187187
clickOnViewWithText(coreR.string.change_record_type_field)
188-
clickOnView(withText(name1))
188+
clickOnView(allOf(withId(R.id.viewRecordTypeItem), hasDescendant(withText(name1))))
189189
tryAction { checkTagVisible(tag1) }
190190
checkTagNotVisible(tag2)
191191
checkTagVisible(tag3)

app/src/androidTest/java/com/example/util/simpletimetracker/ChangeCategoryTest.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import com.example.util.simpletimetracker.utils.clickOnRecyclerItem
1717
import com.example.util.simpletimetracker.utils.clickOnViewWithText
1818
import com.example.util.simpletimetracker.utils.longClickOnView
1919
import com.example.util.simpletimetracker.utils.scrollRecyclerToView
20+
import com.example.util.simpletimetracker.utils.tryAction
2021
import com.example.util.simpletimetracker.utils.typeTextIntoView
2122
import com.example.util.simpletimetracker.utils.withCardColor
2223
import dagger.hilt.android.testing.HiltAndroidTest
@@ -73,6 +74,7 @@ class ChangeCategoryTest : BaseUiTest() {
7374
checkViewIsDisplayed(
7475
allOf(withId(changeCategoryR.id.viewColorItemSelected), withParent(withCardColor(lastColor)))
7576
)
77+
clickOnViewWithText(coreR.string.change_record_type_color_hint)
7678

7779
clickOnViewWithText(coreR.string.change_category_types_hint)
7880
onView(withText(typeName1)).check(isCompletelyAbove(withId(changeCategoryR.id.viewDividerItem)))

app/src/androidTest/java/com/example/util/simpletimetracker/ChangeRecordTypeTest.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ class ChangeRecordTypeTest : BaseUiTest() {
5656

5757
// Preview is updated
5858
checkPreviewUpdated(hasDescendant(withText(name)))
59-
checkPreviewUpdated(withCardColor(firstColor))
59+
checkPreviewUpdated(hasDescendant(withCardColor(firstColor)))
6060
checkPreviewUpdated(hasDescendant(withTag(firstIcon)))
6161

6262
// Change item
@@ -69,7 +69,7 @@ class ChangeRecordTypeTest : BaseUiTest() {
6969
)
7070
scrollRecyclerToView(changeRecordTypeR.id.rvChangeRecordTypeColor, withCardColor(lastColor))
7171
clickOnRecyclerItem(changeRecordTypeR.id.rvChangeRecordTypeColor, withCardColor(lastColor))
72-
checkPreviewUpdated(withCardColor(lastColor))
72+
checkPreviewUpdated(hasDescendant(withCardColor(lastColor)))
7373
checkViewIsDisplayed(
7474
allOf(withId(changeRecordTypeR.id.viewColorItemSelected), withParent(withCardColor(lastColor))),
7575
)

app/src/androidTest/java/com/example/util/simpletimetracker/CustomColorTest.kt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ class CustomColorTest : BaseUiTest() {
190190
// Select color
191191
clickOnViewWithText(coreR.string.change_record_type_color_hint)
192192
clickOnRecyclerItem(changeRecordTypeR.id.rvChangeRecordTypeColor, withCardColorInt(colorInt))
193-
checkPreviewUpdated(withCardColorInt(colorInt))
193+
checkPreviewUpdated(hasDescendant(withCardColorInt(colorInt)))
194194
checkViewIsDisplayed(allOf(withId(dialogsR.id.viewColorItemSelected), withParent(withCardColorInt(colorInt))))
195195

196196
// Check selected color is preselected on color selection
@@ -211,7 +211,7 @@ class CustomColorTest : BaseUiTest() {
211211
clickOnViewWithText(coreR.string.duration_dialog_save)
212212

213213
// Check new color selected
214-
checkPreviewUpdated(withCardColorInt(customColorInt))
214+
checkPreviewUpdated(hasDescendant(withCardColorInt(customColorInt)))
215215
checkViewIsNotDisplayed(
216216
allOf(withId(dialogsR.id.viewColorItemSelected), withParent(withCardColorInt(colorInt)))
217217
)
@@ -231,12 +231,12 @@ class CustomColorTest : BaseUiTest() {
231231
checkViewIsDisplayed(
232232
allOf(
233233
withId(dialogsR.id.viewRecordTypeItem),
234-
withCardColorInt(customColorInt),
234+
hasDescendant(withCardColorInt(customColorInt)),
235235
hasDescendant(withText(name)),
236236
)
237237
)
238238
longClickOnView(withText(name))
239-
checkPreviewUpdated(withCardColorInt(customColorInt))
239+
checkPreviewUpdated(hasDescendant(withCardColorInt(customColorInt)))
240240
clickOnViewWithText(coreR.string.change_record_type_color_hint)
241241
checkViewIsDisplayed(
242242
allOf(
@@ -343,6 +343,7 @@ class CustomColorTest : BaseUiTest() {
343343
withParent(withId(dialogsR.id.layoutColorPaletteItem))
344344
)
345345
)
346+
clickOnViewWithText(coreR.string.change_category_color_hint)
346347

347348
// Save tag
348349
typeTextIntoView(changeCategoryR.id.etChangeCategoryName, categoryName)

app/src/androidTest/java/com/example/util/simpletimetracker/DeleteRecordTypeTest.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ class DeleteRecordTypeTest : BaseUiTest() {
3535
val icon = firstIcon
3636

3737
// Add item
38+
Thread.sleep(1000)
3839
testUtils.addActivity(name = name, color = color, icon = icon)
3940
testUtils.addRecord(name)
4041

@@ -44,7 +45,7 @@ class DeleteRecordTypeTest : BaseUiTest() {
4445
withId(baseR.id.viewRecordTypeItem),
4546
hasDescendant(withText(name)),
4647
hasDescendant(withTag(icon)),
47-
withCardColor(color)
48+
hasDescendant(withCardColor(color))
4849
)
4950
)
5051
}

app/src/androidTest/java/com/example/util/simpletimetracker/SettingsTest.kt

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -91,13 +91,6 @@ class SettingsTest : BaseUiTest() {
9191
allOf(withText(coreR.string.untracked_time_name), isCompletelyDisplayed()),
9292
)
9393

94-
// Add record
95-
NavUtils.addRecord(name)
96-
checkViewDoesNotExist(
97-
allOf(withText(coreR.string.untracked_time_name), isCompletelyDisplayed()),
98-
)
99-
checkViewIsDisplayed(allOf(withText(name), isCompletelyDisplayed()))
100-
10194
// Change setting
10295
NavUtils.openSettingsScreen()
10396
onView(withId(settingsR.id.checkboxSettingsShowUntrackedInRecords)).perform(nestedScrollTo())
@@ -108,7 +101,6 @@ class SettingsTest : BaseUiTest() {
108101
// Untracked is shown
109102
NavUtils.openRecordsScreen()
110103
checkViewIsDisplayed(allOf(withText(coreR.string.untracked_time_name), isCompletelyDisplayed()))
111-
checkViewIsDisplayed(allOf(withText(name), isCompletelyDisplayed()))
112104
}
113105

114106
@Test
@@ -142,7 +134,7 @@ class SettingsTest : BaseUiTest() {
142134

143135
// Add record
144136
NavUtils.openRecordsScreen()
145-
NavUtils.addRecord(name)
137+
testUtils.addRecord(name)
146138
NavUtils.openStatisticsScreen()
147139
checkViewDoesNotExist(
148140
allOf(withText(coreR.string.untracked_time_name), isCompletelyDisplayed()),

app/src/androidTest/java/com/example/util/simpletimetracker/Widget.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class Widget : BaseUiTest() {
5353
checkViewIsDisplayed(
5454
allOf(
5555
withId(baseR.id.viewRecordTypeItem),
56-
withCardColor(color),
56+
hasDescendant(withCardColor(color)),
5757
hasDescendant(withText(name))
5858
)
5959
)

0 commit comments

Comments
 (0)