Skip to content

Commit 71038be

Browse files
committed
add another manual card order test
1 parent 17137d5 commit 71038be

File tree

4 files changed

+127
-9
lines changed

4 files changed

+127
-9
lines changed

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

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@ import androidx.test.espresso.Espresso.onView
55
import androidx.test.espresso.Espresso.pressBack
66
import androidx.test.espresso.ViewAssertion
77
import androidx.test.espresso.assertion.PositionAssertions.isCompletelyAbove
8+
import androidx.test.espresso.assertion.PositionAssertions.isCompletelyBelow
89
import androidx.test.espresso.assertion.PositionAssertions.isCompletelyLeftOf
10+
import androidx.test.espresso.assertion.PositionAssertions.isCompletelyRightOf
11+
import androidx.test.espresso.assertion.PositionAssertions.isLeftAlignedWith
12+
import androidx.test.espresso.assertion.PositionAssertions.isTopAlignedWith
913
import androidx.test.espresso.assertion.ViewAssertions.matches
1014
import androidx.test.espresso.matcher.ViewMatchers
1115
import androidx.test.espresso.matcher.ViewMatchers.hasDescendant
@@ -17,6 +21,7 @@ import androidx.test.espresso.matcher.ViewMatchers.withId
1721
import androidx.test.espresso.matcher.ViewMatchers.withSubstring
1822
import androidx.test.espresso.matcher.ViewMatchers.withText
1923
import androidx.test.ext.junit.runners.AndroidJUnit4
24+
import androidx.test.platform.app.InstrumentationRegistry
2025
import com.example.util.simpletimetracker.core.extension.setWeekToFirstDay
2126
import com.example.util.simpletimetracker.core.mapper.ColorMapper
2227
import com.example.util.simpletimetracker.domain.model.DayOfWeek
@@ -384,6 +389,49 @@ class SettingsTest : BaseUiTest() {
384389
check(name3, name1) { matcher -> isCompletelyLeftOf(matcher) }
385390
}
386391

392+
@Test
393+
fun cardOrderManual2() {
394+
val name = "Test"
395+
396+
// Add activities
397+
(1..15).forEach {
398+
testUtils.addActivity("$name$it")
399+
}
400+
401+
// Change settings
402+
NavUtils.openSettingsScreen()
403+
NavUtils.openCardSizeScreen()
404+
Thread.sleep(1000)
405+
clickOnViewWithText("4")
406+
pressBack()
407+
clickOnSpinnerWithId(R.id.spinnerSettingsRecordTypeSort)
408+
clickOnViewWithText(R.string.settings_sort_by_color)
409+
clickOnSpinnerWithId(R.id.spinnerSettingsRecordTypeSort)
410+
clickOnViewWithText(R.string.settings_sort_manually)
411+
Thread.sleep(1000)
412+
413+
val resources = InstrumentationRegistry.getInstrumentation().targetContext.resources
414+
val screenWidth = resources.displayMetrics.widthPixels
415+
val screenHeight = resources.displayMetrics.heightPixels
416+
417+
// Drag
418+
(1..15).forEach {
419+
onView(allOf(isDescendantOfA(withId(R.id.viewRecordTypeItem)), withText("$name$it")))
420+
.perform(
421+
drag(Direction.RIGHT, screenWidth),
422+
drag(Direction.DOWN, screenHeight),
423+
)
424+
}
425+
426+
// Check order in settings
427+
checkManualOrder(name)
428+
429+
// Check order on main
430+
pressBack()
431+
NavUtils.openRunningRecordsScreen()
432+
checkManualOrder(name)
433+
}
434+
387435
@Test
388436
fun enableNotifications() {
389437
val name1 = "Test1"
@@ -756,4 +804,65 @@ class SettingsTest : BaseUiTest() {
756804
matcher(allOf(isDescendantOfA(withId(R.id.viewRecordTypeItem)), withText(second)))
757805
)
758806
}
807+
808+
private fun checkManualOrder(name: String) {
809+
check(name + 2, name + 1) { matcher ->
810+
isCompletelyRightOf(matcher)
811+
isTopAlignedWith(matcher)
812+
}
813+
check(name + 3, name + 2) { matcher ->
814+
isCompletelyRightOf(matcher)
815+
isTopAlignedWith(matcher)
816+
}
817+
check(name + 4, name + 3) { matcher ->
818+
isCompletelyRightOf(matcher)
819+
isTopAlignedWith(matcher)
820+
}
821+
822+
check(name + 5, name + 1) { matcher ->
823+
isCompletelyBelow(matcher)
824+
isLeftAlignedWith(matcher)
825+
}
826+
check(name + 6, name + 5) { matcher ->
827+
isCompletelyRightOf(matcher)
828+
isTopAlignedWith(matcher)
829+
}
830+
check(name + 7, name + 6) { matcher ->
831+
isCompletelyRightOf(matcher)
832+
isTopAlignedWith(matcher)
833+
}
834+
check(name + 8, name + 7) { matcher ->
835+
isCompletelyRightOf(matcher)
836+
isTopAlignedWith(matcher)
837+
}
838+
839+
check(name + 9, name + 5) { matcher ->
840+
isCompletelyBelow(matcher)
841+
isLeftAlignedWith(matcher)
842+
}
843+
check(name + 10, name + 9) { matcher ->
844+
isCompletelyRightOf(matcher)
845+
isTopAlignedWith(matcher)
846+
}
847+
check(name + 11, name + 10) { matcher ->
848+
isCompletelyRightOf(matcher)
849+
isTopAlignedWith(matcher)
850+
}
851+
check(name + 12, name + 11) { matcher ->
852+
isCompletelyRightOf(matcher)
853+
isTopAlignedWith(matcher)
854+
}
855+
856+
check(name + 13, name + 9) { matcher ->
857+
isCompletelyBelow(matcher)
858+
}
859+
check(name + 14, name + 13) { matcher ->
860+
isCompletelyRightOf(matcher)
861+
isTopAlignedWith(matcher)
862+
}
863+
check(name + 15, name + 14) { matcher ->
864+
isCompletelyRightOf(matcher)
865+
isTopAlignedWith(matcher)
866+
}
867+
}
759868
}

app/src/androidTest/java/com/example/util/simpletimetracker/utils/NavUtils.kt

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,15 @@ import androidx.test.espresso.Espresso.closeSoftKeyboard
55
import androidx.test.espresso.Espresso.onView
66
import androidx.test.espresso.action.ViewActions.click
77
import androidx.test.espresso.contrib.PickerActions
8+
import androidx.test.espresso.contrib.PickerActions.setTime
89
import androidx.test.espresso.matcher.ViewMatchers
910
import androidx.test.espresso.matcher.ViewMatchers.hasDescendant
11+
import androidx.test.espresso.matcher.ViewMatchers.withClassName
1012
import androidx.test.espresso.matcher.ViewMatchers.withId
1113
import androidx.test.espresso.matcher.ViewMatchers.withText
1214
import com.example.util.simpletimetracker.R
1315
import org.hamcrest.CoreMatchers
16+
import org.hamcrest.CoreMatchers.equalTo
1417

1518
object NavUtils {
1619

@@ -170,14 +173,14 @@ object NavUtils {
170173

171174
// Time started
172175
clickOnViewWithId(R.id.tvChangeRecordTimeStarted)
173-
onView(ViewMatchers.withClassName(CoreMatchers.equalTo(TimePicker::class.java.name)))
174-
.perform(PickerActions.setTime(hourStarted, minutesStarted))
176+
onView(withClassName(equalTo(TimePicker::class.java.name)))
177+
.perform(setTime(hourStarted, minutesStarted))
175178
clickOnViewWithId(R.id.btnDateTimeDialogPositive)
176179

177180
// Time ended
178181
clickOnViewWithId(R.id.tvChangeRecordTimeEnded)
179-
onView(ViewMatchers.withClassName(CoreMatchers.equalTo(TimePicker::class.java.name)))
180-
.perform(PickerActions.setTime(hourEnded, minutesEnded))
182+
onView(withClassName(equalTo(TimePicker::class.java.name)))
183+
.perform(setTime(hourEnded, minutesEnded))
181184
clickOnViewWithId(R.id.btnDateTimeDialogPositive)
182185

183186
// Comment

app/src/androidTest/java/com/example/util/simpletimetracker/utils/ViewActions.kt

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import org.hamcrest.Matchers.allOf
2424
import org.hamcrest.Matchers.anyOf
2525

2626
enum class Direction {
27-
UP, DOWN, LEFT, RIGHT
27+
UP, DOWN, LEFT, RIGHT, COORDINATES
2828
}
2929

3030
fun selectTabAtPosition(tabIndex: Int): ViewAction = object : ViewAction {
@@ -76,8 +76,12 @@ fun nestedScrollTo(): ViewAction = object : ViewAction {
7676
}
7777
}
7878

79-
fun drag(direction: Direction, offset: Int): ViewAction = object : ViewAction {
80-
private val SWIPE_EVENT_COUNT = 10
79+
fun drag(
80+
direction: Direction = Direction.COORDINATES,
81+
offset: Int = 0,
82+
coordinates: FloatArray = FloatArray(2) { 0.0f }
83+
): ViewAction = object : ViewAction {
84+
private val SWIPE_EVENT_COUNT = 50
8185

8286
override fun getDescription(): String = "dragging"
8387

@@ -143,13 +147,14 @@ fun drag(direction: Direction, offset: Int): ViewAction = object : ViewAction {
143147
}
144148

145149
private fun getDestinationCoordinates(initial: FloatArray): FloatArray {
146-
val destination = initial.clone()
150+
var destination = initial.clone()
147151

148152
when (direction) {
149153
Direction.UP -> destination[1] = destination[1] - offset
150154
Direction.DOWN -> destination[1] = destination[1] + offset
151155
Direction.LEFT -> destination[0] = destination[0] - offset
152156
Direction.RIGHT -> destination[0] = destination[0] + offset
157+
Direction.COORDINATES -> destination = coordinates
153158
}
154159

155160
return destination

core/src/main/java/com/example/util/simpletimetracker/core/utils/TestUtils.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ class TestUtils @Inject constructor(
6262
?: icons.keys.first()
6363

6464
val colors = ColorMapper.getAvailableColors(false)
65-
val colorId = colors.indexOf(color).takeUnless { it == -1 }.orZero()
65+
val colorId = colors.indexOf(color).takeUnless { it == -1 }
66+
?: (0..colors.size).random()
6667

6768
val availableCategories = categoryInteractor.getAll()
6869

0 commit comments

Comments
 (0)