@@ -9,6 +9,8 @@ import androidx.test.espresso.matcher.ViewMatchers.hasDescendant
99import androidx.test.espresso.matcher.ViewMatchers.withId
1010import androidx.test.espresso.matcher.ViewMatchers.withText
1111import androidx.test.ext.junit.runners.AndroidJUnit4
12+ import com.example.util.simpletimetracker.SuggestionsTestUtils.checkSuggestion
13+ import com.example.util.simpletimetracker.SuggestionsTestUtils.checkType
1214import com.example.util.simpletimetracker.feature_base_adapter.recordTypeSuggestion.RecordTypeSuggestionViewData
1315import com.example.util.simpletimetracker.utils.BaseUiTest
1416import com.example.util.simpletimetracker.utils.Direction
@@ -17,7 +19,6 @@ import com.example.util.simpletimetracker.utils.checkViewDoesNotExist
1719import com.example.util.simpletimetracker.utils.checkViewIsDisplayed
1820import com.example.util.simpletimetracker.utils.clickOnViewWithText
1921import com.example.util.simpletimetracker.utils.drag
20- import com.example.util.simpletimetracker.utils.scrollRecyclerToView
2122import com.example.util.simpletimetracker.utils.tryAction
2223import com.example.util.simpletimetracker.utils.withTag
2324import dagger.hilt.android.testing.HiltAndroidTest
@@ -106,30 +107,30 @@ class SuggestionsTest : BaseUiTest() {
106107 checkType(type4, false )
107108
108109 // Add suggestions
109- checkSuggestion(withText(R .string.running_records_add_type), typesMap[type1], true )
110+ checkSuggestion(type1, withText(R .string.running_records_add_type), typesMap[type1], true )
110111 .performClick()
111112 clickOnViewWithText(type2)
112113 clickOnViewWithText(R .string.change_record_save)
113- checkSuggestion(withText(type2), typesMap[type1], true )
114+ checkSuggestion(type1, withText(type2), typesMap[type1], true )
114115
115- checkSuggestion(withText(R .string.running_records_add_type), typesMap[type2], true )
116+ checkSuggestion(type2, withText(R .string.running_records_add_type), typesMap[type2], true )
116117 .performClick()
117118 clickOnViewWithText(type1)
118119 clickOnViewWithText(type3)
119120 clickOnViewWithText(R .string.change_record_save)
120- checkSuggestion(withText(type1), typesMap[type2], true )
121- checkSuggestion(withText(type3), typesMap[type2], true )
121+ checkSuggestion(type2, withText(type1), typesMap[type2], true )
122+ checkSuggestion(type2, withText(type3), typesMap[type2], true )
122123
123- checkSuggestion(withText(type1), typesMap[type3], false )
124- checkSuggestion(withText(type2), typesMap[type3], false )
125- checkSuggestion(withText(type3), typesMap[type3], false )
124+ checkSuggestion(type3, withText(type1), typesMap[type3], false )
125+ checkSuggestion(type3, withText(type2), typesMap[type3], false )
126+ checkSuggestion(type3, withText(type3), typesMap[type3], false )
126127
127128 // Check that is saved
128129 clickOnViewWithText(R .string.change_record_save)
129130 NavUtils .openSuggestions()
130- checkSuggestion(withText(type2), typesMap[type1], true )
131- checkSuggestion(withText(type1), typesMap[type2], true )
132- checkSuggestion(withText(type3), typesMap[type2], true )
131+ checkSuggestion(type1, withText(type2), typesMap[type1], true )
132+ checkSuggestion(type2, withText(type1), typesMap[type2], true )
133+ checkSuggestion(type2, withText(type3), typesMap[type2], true )
133134 }
134135
135136 @Test
@@ -163,52 +164,52 @@ class SuggestionsTest : BaseUiTest() {
163164 // Check
164165 clickOnViewWithText(R .string.activity_suggestions_calculate)
165166
166- checkSuggestion(withText(type1), typesMap[type1], false )
167- var type2Matcher = checkSuggestion(withText(type2), typesMap[type1], true )
168- var type3Matcher = checkSuggestion(withText(type3), typesMap[type1], true )
167+ checkSuggestion(type1, withText(type1), typesMap[type1], false )
168+ var type2Matcher = checkSuggestion(type1, withText(type2), typesMap[type1], true )
169+ var type3Matcher = checkSuggestion(type1, withText(type3), typesMap[type1], true )
169170 onView(type3Matcher).check(isCompletelyLeftOf(type2Matcher))
170171
171- checkSuggestion(withText(type1), typesMap[type2], true )
172- checkSuggestion(withText(type2), typesMap[type2], false )
173- checkSuggestion(withText(type3), typesMap[type2], false )
172+ checkSuggestion(type2, withText(type1), typesMap[type2], true )
173+ checkSuggestion(type2, withText(type2), typesMap[type2], false )
174+ checkSuggestion(type2, withText(type3), typesMap[type2], false )
174175
175- checkSuggestion(withText(type1), typesMap[type3], true )
176- checkSuggestion(withText(type2), typesMap[type3], false )
177- checkSuggestion(withText(type3), typesMap[type3], false )
176+ checkSuggestion(type3, withText(type1), typesMap[type3], true )
177+ checkSuggestion(type3, withText(type2), typesMap[type3], false )
178+ checkSuggestion(type3, withText(type3), typesMap[type3], false )
178179
179180 // Check buttons
180181 pressBack()
181182 NavUtils .openSuggestions()
182183
183- checkSuggestion(withText(type1), typesMap[type1], false )
184- checkSuggestion(withText(type2), typesMap[type1], false )
185- checkSuggestion(withText(type3), typesMap[type1], false )
186- checkSuggestion(withText(R .string.shortcut_navigation_statistics), typesMap[type1], true )
184+ checkSuggestion(type1, withText(type1), typesMap[type1], false )
185+ checkSuggestion(type1, withText(type2), typesMap[type1], false )
186+ checkSuggestion(type1, withText(type3), typesMap[type1], false )
187+ checkSuggestion(type1, withText(R .string.shortcut_navigation_statistics), typesMap[type1], true )
187188 .performClick()
188- tryAction { checkSuggestion(withText(type1), typesMap[type1], false ) }
189- type2Matcher = checkSuggestion(withText(type2), typesMap[type1], true )
190- type3Matcher = checkSuggestion(withText(type3), typesMap[type1], true )
189+ tryAction { checkSuggestion(type1, withText(type1), typesMap[type1], false ) }
190+ type2Matcher = checkSuggestion(type1, withText(type2), typesMap[type1], true )
191+ type3Matcher = checkSuggestion(type1, withText(type3), typesMap[type1], true )
191192 onView(type3Matcher).check(isCompletelyLeftOf(type2Matcher))
192193
193194 Thread .sleep(500 )
194- checkSuggestion(withText(type1), typesMap[type2], false )
195- checkSuggestion(withText(type2), typesMap[type2], false )
196- checkSuggestion(withText(type3), typesMap[type2], false )
197- checkSuggestion(withText(R .string.shortcut_navigation_statistics), typesMap[type2], true )
195+ checkSuggestion(type2, withText(type1), typesMap[type2], false )
196+ checkSuggestion(type2, withText(type2), typesMap[type2], false )
197+ checkSuggestion(type2, withText(type3), typesMap[type2], false )
198+ checkSuggestion(type2, withText(R .string.shortcut_navigation_statistics), typesMap[type2], true )
198199 .performClick()
199- tryAction { checkSuggestion(withText(type1), typesMap[type2], true ) }
200- checkSuggestion(withText(type2), typesMap[type2], false )
201- checkSuggestion(withText(type3), typesMap[type2], false )
200+ tryAction { checkSuggestion(type2, withText(type1), typesMap[type2], true ) }
201+ checkSuggestion(type2, withText(type2), typesMap[type2], false )
202+ checkSuggestion(type2, withText(type3), typesMap[type2], false )
202203
203204 Thread .sleep(500 )
204- checkSuggestion(withText(type1), typesMap[type3], false )
205- checkSuggestion(withText(type2), typesMap[type3], false )
206- checkSuggestion(withText(type3), typesMap[type3], false )
207- checkSuggestion(withText(R .string.shortcut_navigation_statistics), typesMap[type3], true )
205+ checkSuggestion(type3, withText(type1), typesMap[type3], false )
206+ checkSuggestion(type3, withText(type2), typesMap[type3], false )
207+ checkSuggestion(type3, withText(type3), typesMap[type3], false )
208+ checkSuggestion(type3, withText(R .string.shortcut_navigation_statistics), typesMap[type3], true )
208209 .performClick()
209- tryAction { checkSuggestion(withText(type1), typesMap[type3], true ) }
210- checkSuggestion(withText(type2), typesMap[type3], false )
211- checkSuggestion(withText(type3), typesMap[type3], false )
210+ tryAction { checkSuggestion(type3, withText(type1), typesMap[type3], true ) }
211+ checkSuggestion(type3, withText(type2), typesMap[type3], false )
212+ checkSuggestion(type3, withText(type3), typesMap[type3], false )
212213 }
213214
214215 @Test
@@ -230,8 +231,8 @@ class SuggestionsTest : BaseUiTest() {
230231 NavUtils .openSuggestions()
231232
232233 // Check
233- var type2Matcher = checkSuggestion(withText(type2), typesMap[type1], true )
234- var type3Matcher = checkSuggestion(withText(type3), typesMap[type1], true )
234+ var type2Matcher = checkSuggestion(type1, withText(type2), typesMap[type1], true )
235+ var type3Matcher = checkSuggestion(type1, withText(type3), typesMap[type1], true )
235236 onView(type2Matcher).check(isCompletelyLeftOf(type3Matcher))
236237
237238 // Reorder
@@ -341,41 +342,6 @@ class SuggestionsTest : BaseUiTest() {
341342 onView(this ).perform(click())
342343 }
343344
344- private fun checkType (
345- name : String ,
346- visible : Boolean ,
347- ) {
348- val matcher = suggestionTypeMatcher(name)
349- if (visible) {
350- scrollRecyclerToView(R .id.rvActivitySuggestionsList, matcher)
351- checkViewIsDisplayed(matcher)
352- } else {
353- checkViewDoesNotExist(matcher)
354- }
355- }
356-
357- private fun checkSuggestion (
358- textMatcher : Matcher <View >,
359- tag : Any? ,
360- visible : Boolean ,
361- ): Matcher <View > {
362- val matcher = suggestionMatcher(textMatcher, tag)
363- if (visible) {
364- scrollRecyclerToView(R .id.rvActivitySuggestionsList, matcher)
365- checkViewIsDisplayed(matcher)
366- } else {
367- checkViewDoesNotExist(matcher)
368- }
369- return matcher
370- }
371-
372- private fun suggestionTypeMatcher (name : String ): Matcher <View > {
373- return allOf(
374- withId(R .id.viewRecordTypeItem),
375- hasDescendant(withText(name)),
376- )
377- }
378-
379345 private fun typeMatcher (name : String ): Matcher <View > {
380346 return allOf(
381347 withId(R .id.viewRecordTypeItem),
@@ -384,17 +350,6 @@ class SuggestionsTest : BaseUiTest() {
384350 )
385351 }
386352
387- private fun suggestionMatcher (
388- textMatcher : Matcher <View >,
389- tag : Any? ,
390- ): Matcher <View > {
391- return allOf(
392- withId(R .id.cvActivitySuggestionListItemContent),
393- withTag(tag ? : Any ()),
394- hasDescendant(textMatcher),
395- )
396- }
397-
398353 private fun checkRunningRecord (name : String ) {
399354 checkViewIsDisplayed(allOf(withId(R .id.viewRunningRecordItem), hasDescendant(withText(name))))
400355 }
0 commit comments