Skip to content

Commit d65fb8f

Browse files
committed
add new tests
1 parent 9308b97 commit d65fb8f

11 files changed

+678
-52
lines changed

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

Lines changed: 58 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import com.example.util.simpletimetracker.utils.longClickOnView
1616
import com.example.util.simpletimetracker.utils.withCardColor
1717
import com.example.util.simpletimetracker.utils.withTag
1818
import dagger.hilt.android.testing.HiltAndroidTest
19-
import org.hamcrest.CoreMatchers
2019
import org.hamcrest.Matchers.allOf
2120
import org.junit.Test
2221
import org.junit.runner.RunWith
@@ -63,15 +62,7 @@ class DeleteRecordTest : BaseUiTest() {
6362
clickOnViewWithText(coreR.string.record_removed_undo)
6463

6564
// Record is back
66-
checkViewIsDisplayed(
67-
CoreMatchers.allOf(
68-
withId(baseR.id.viewRecordItem),
69-
withCardColor(color),
70-
hasDescendant(withText(name)),
71-
hasDescendant(withTag(icon)),
72-
isCompletelyDisplayed(),
73-
),
74-
)
65+
checkRecord(name = name, color = color, icon = icon)
7566
}
7667

7768
@Test
@@ -107,8 +98,64 @@ class DeleteRecordTest : BaseUiTest() {
10798
clickOnViewWithText(coreR.string.record_removed_undo)
10899

109100
// Record is back
101+
checkRecord(name = name, color = color, icon = icon)
102+
}
103+
104+
@Test
105+
fun deleteRecordMultiselectQuickAction() {
106+
val name1 = "Name1"
107+
val name2 = "Name2"
108+
val color1 = firstColor
109+
val icon1 = firstIcon
110+
val color2 = lastColor
111+
val icon2 = lastIcon
112+
113+
// Add activity
114+
testUtils.addActivity(name = name1, color = color1, icon = icon1)
115+
testUtils.addActivity(name = name2, color = color2, icon = icon2)
116+
testUtils.addRecord(typeName = name1)
117+
testUtils.addRecord(typeName = name2)
118+
119+
// Delete item
120+
NavUtils.openRecordsScreen()
121+
longClickOnView(allOf(withText(name1), isCompletelyDisplayed()))
122+
clickOnViewWithText(R.string.change_record_multiselect)
123+
longClickOnView(allOf(withText(name2), isCompletelyDisplayed()))
124+
longClickOnView(allOf(withText(name2), isCompletelyDisplayed()))
125+
checkViewIsDisplayed(withText(R.string.archive_dialog_delete))
126+
clickOnViewWithText(R.string.archive_dialog_delete)
127+
128+
// Check message
110129
checkViewIsDisplayed(
111-
CoreMatchers.allOf(
130+
allOf(
131+
withText(getString(coreR.string.record_removed, "(2)")),
132+
withId(com.google.android.material.R.id.snackbar_text),
133+
),
134+
)
135+
136+
// Record is deleted
137+
checkViewDoesNotExist(allOf(withText(name1), isCompletelyDisplayed()))
138+
checkViewDoesNotExist(allOf(withText(name2), isCompletelyDisplayed()))
139+
checkViewDoesNotExist(allOf(withCardColor(color1), isCompletelyDisplayed()))
140+
checkViewDoesNotExist(allOf(withCardColor(color2), isCompletelyDisplayed()))
141+
checkViewDoesNotExist(allOf(withTag(icon1), isCompletelyDisplayed()))
142+
checkViewDoesNotExist(allOf(withTag(icon2), isCompletelyDisplayed()))
143+
144+
// Check undo
145+
clickOnViewWithText(coreR.string.record_removed_undo)
146+
147+
// Record is back
148+
checkRecord(name = name1, color = color1, icon = icon1)
149+
checkRecord(name = name2, color = color2, icon = icon2)
150+
}
151+
152+
private fun checkRecord(
153+
name: String,
154+
color: Int,
155+
icon: Int,
156+
) {
157+
checkViewIsDisplayed(
158+
allOf(
112159
withId(baseR.id.viewRecordItem),
113160
withCardColor(color),
114161
hasDescendant(withText(name)),
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
package com.example.util.simpletimetracker
2+
3+
import androidx.test.espresso.Espresso.closeSoftKeyboard
4+
import androidx.test.espresso.Espresso.onView
5+
import androidx.test.espresso.matcher.ViewMatchers.isDescendantOfA
6+
import androidx.test.espresso.matcher.ViewMatchers.withId
7+
import androidx.test.espresso.matcher.ViewMatchers.withText
8+
import androidx.test.ext.junit.runners.AndroidJUnit4
9+
import com.example.util.simpletimetracker.feature_change_record_type.R
10+
import com.example.util.simpletimetracker.utils.BaseUiTest
11+
import com.example.util.simpletimetracker.utils.checkViewDoesNotExist
12+
import com.example.util.simpletimetracker.utils.checkViewIsDisplayed
13+
import com.example.util.simpletimetracker.utils.clickOnView
14+
import com.example.util.simpletimetracker.utils.clickOnViewWithId
15+
import com.example.util.simpletimetracker.utils.clickOnViewWithText
16+
import com.example.util.simpletimetracker.utils.longClickOnView
17+
import com.example.util.simpletimetracker.utils.longClickOnViewWithId
18+
import com.example.util.simpletimetracker.utils.nestedScrollTo
19+
import dagger.hilt.android.testing.HiltAndroidTest
20+
import org.hamcrest.CoreMatchers.allOf
21+
import org.junit.Test
22+
import org.junit.runner.RunWith
23+
import com.example.util.simpletimetracker.core.R as coreR
24+
import com.example.util.simpletimetracker.feature_dialogs.R as dialogsR
25+
26+
@HiltAndroidTest
27+
@RunWith(AndroidJUnit4::class)
28+
class DurationSuggestionsTest : BaseUiTest() {
29+
30+
private val defaultValues = listOf(
31+
"1$minuteString",
32+
"15$minuteString",
33+
"1$hourString",
34+
)
35+
36+
@Test
37+
fun default() {
38+
openTypeEdit()
39+
openDialog()
40+
41+
defaultValues.forEach { checkViewIsDisplayed(withText(it)) }
42+
}
43+
44+
@Test
45+
fun selecting() {
46+
openTypeEdit()
47+
48+
defaultValues.forEach {
49+
openDialog()
50+
clickOnViewWithText(it)
51+
clickOnViewWithText(R.string.duration_dialog_save)
52+
checkViewIsDisplayed(
53+
allOf(isDescendantOfA(withId(R.id.layoutChangeRecordTypeGoalSession)), withText(it)),
54+
)
55+
}
56+
}
57+
58+
@Test
59+
fun deleting() {
60+
openTypeEdit()
61+
openDialog()
62+
63+
defaultValues.forEach {
64+
longClickOnView(withText(it))
65+
checkViewDoesNotExist(withText(it))
66+
}
67+
}
68+
69+
@Test
70+
fun addAndSelect() {
71+
val text = "13$minuteString"
72+
73+
openTypeEdit()
74+
openDialog()
75+
76+
// Adding
77+
checkViewDoesNotExist(withText(text))
78+
clickOnViewWithId(dialogsR.id.tvNumberKeyboard1)
79+
clickOnViewWithId(dialogsR.id.tvNumberKeyboard3)
80+
clickOnViewWithId(dialogsR.id.tvNumberKeyboard0)
81+
clickOnViewWithId(dialogsR.id.tvNumberKeyboard0)
82+
clickOnViewWithText(R.string.running_records_add_type)
83+
84+
// Selecting
85+
checkViewIsDisplayed(withText(text))
86+
longClickOnViewWithId(dialogsR.id.btnNumberKeyboardDelete)
87+
clickOnViewWithText(text)
88+
clickOnViewWithText(R.string.duration_dialog_save)
89+
checkViewIsDisplayed(
90+
allOf(isDescendantOfA(withId(R.id.layoutChangeRecordTypeGoalSession)), withText(text)),
91+
)
92+
93+
// Deleting
94+
openDialog()
95+
longClickOnView(withText(text))
96+
checkViewDoesNotExist(withText(text))
97+
}
98+
99+
private fun openTypeEdit() {
100+
clickOnViewWithText(coreR.string.running_records_add_type)
101+
closeSoftKeyboard()
102+
onView(withText(coreR.string.change_record_type_goal_time_hint)).perform(nestedScrollTo())
103+
clickOnViewWithText(coreR.string.change_record_type_goal_time_hint)
104+
}
105+
106+
private fun openDialog() {
107+
clickOnView(
108+
allOf(
109+
isDescendantOfA(withId(R.id.layoutChangeRecordTypeGoalSession)),
110+
withId(R.id.fieldChangeRecordTypeGoalDuration),
111+
),
112+
)
113+
}
114+
}

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

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import com.example.util.simpletimetracker.utils.NavUtils
1212
import com.example.util.simpletimetracker.utils.checkViewIsDisplayed
1313
import com.example.util.simpletimetracker.utils.clickOnViewWithText
1414
import com.example.util.simpletimetracker.utils.longClickOnView
15+
import com.example.util.simpletimetracker.utils.nthChildOf
1516
import com.example.util.simpletimetracker.utils.tryAction
1617
import com.example.util.simpletimetracker.utils.withCardColor
1718
import com.example.util.simpletimetracker.utils.withTag
@@ -235,6 +236,89 @@ class RecordActionsChangeActivityTest : BaseUiTest() {
235236
}
236237
}
237238

239+
@Test
240+
fun changeMultiselect() {
241+
val name1 = "Name1"
242+
val name2 = "Name2"
243+
val name3 = "Name3"
244+
val calendar = Calendar.getInstance()
245+
246+
// Setup
247+
testUtils.addActivity(name1)
248+
testUtils.addActivity(name2)
249+
testUtils.addActivity(name3)
250+
251+
testUtils.addRunningRecord(name1)
252+
testUtils.addRecord(
253+
typeName = name2,
254+
timeStarted = calendar.timeInMillis - TimeUnit.MINUTES.toMillis(3),
255+
timeEnded = calendar.timeInMillis - TimeUnit.MINUTES.toMillis(2),
256+
)
257+
258+
// Check
259+
NavUtils.openRecordsScreen()
260+
checkViewIsDisplayed(
261+
allOf(
262+
withId(baseR.id.viewRunningRecordItem),
263+
hasDescendant(withText(name1)),
264+
nthChildOf(withId(R.id.rvRecordsList), 0),
265+
isCompletelyDisplayed(),
266+
),
267+
)
268+
checkViewIsDisplayed(
269+
allOf(
270+
withId(baseR.id.viewRecordItem),
271+
hasDescendant(withText(R.string.untracked_time_name)),
272+
nthChildOf(withId(R.id.rvRecordsList), 1),
273+
isCompletelyDisplayed(),
274+
),
275+
)
276+
checkViewIsDisplayed(
277+
allOf(
278+
withId(baseR.id.viewRecordItem),
279+
hasDescendant(withText(name2)),
280+
nthChildOf(withId(R.id.rvRecordsList), 2),
281+
isCompletelyDisplayed(),
282+
),
283+
)
284+
285+
// Change
286+
longClickOnView(allOf(withText(name1), isCompletelyDisplayed()))
287+
clickOnViewWithText(R.string.change_record_multiselect)
288+
longClickOnView(allOf(withText(name2), isCompletelyDisplayed()))
289+
longClickOnView(allOf(withText(R.string.untracked_time_name), isCompletelyDisplayed()))
290+
longClickOnView(allOf(withText(R.string.untracked_time_name), isCompletelyDisplayed()))
291+
clickOnViewWithText(R.string.data_edit_change_activity)
292+
clickOnViewWithText(name3)
293+
294+
tryAction {
295+
checkViewIsDisplayed(
296+
allOf(
297+
withId(baseR.id.viewRunningRecordItem),
298+
hasDescendant(withText(name3)),
299+
nthChildOf(withId(R.id.rvRecordsList), 0),
300+
isCompletelyDisplayed(),
301+
),
302+
)
303+
checkViewIsDisplayed(
304+
allOf(
305+
withId(baseR.id.viewRecordItem),
306+
hasDescendant(withText(name3)),
307+
nthChildOf(withId(R.id.rvRecordsList), 1),
308+
isCompletelyDisplayed(),
309+
),
310+
)
311+
checkViewIsDisplayed(
312+
allOf(
313+
withId(baseR.id.viewRecordItem),
314+
hasDescendant(withText(name3)),
315+
nthChildOf(withId(R.id.rvRecordsList), 2),
316+
isCompletelyDisplayed(),
317+
),
318+
)
319+
}
320+
}
321+
238322
@Suppress("SameParameterValue")
239323
private fun checkRecord(
240324
name: String,

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

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,70 @@ class RecordActionsChangeTagTest : BaseUiTest() {
200200
}
201201
}
202202

203+
@Test
204+
fun changeMultiselect() {
205+
val nameTracked = "NameTracked"
206+
val nameRunning = "NameRunning"
207+
val tag1 = "Tag1"
208+
val tag2 = "Tag2"
209+
val tagGeneral = "TagGeneral"
210+
val fullNameTracked = "$nameTracked - $tag1"
211+
val fullNameRunning = "$nameRunning - $tag2"
212+
213+
testUtils.addActivity(nameTracked)
214+
testUtils.addActivity(nameRunning)
215+
testUtils.addRecordTag(tag1, typeName = nameTracked)
216+
testUtils.addRecordTag(tag2, typeName = nameRunning)
217+
testUtils.addRecordTag(tagGeneral)
218+
testUtils.addRecord(nameTracked, tagNames = listOf(tag1))
219+
testUtils.addRunningRecord(nameRunning, tagNames = listOf(tag2))
220+
221+
// Check record
222+
NavUtils.openRecordsScreen()
223+
checkViewIsDisplayed(
224+
allOf(
225+
withId(baseR.id.viewRecordItem),
226+
hasDescendant(withText(fullNameTracked)),
227+
isCompletelyDisplayed(),
228+
),
229+
)
230+
checkViewIsDisplayed(
231+
allOf(
232+
withId(baseR.id.viewRunningRecordItem),
233+
hasDescendant(withText(fullNameRunning)),
234+
isCompletelyDisplayed(),
235+
),
236+
)
237+
238+
// Change
239+
longClickOnView(allOf(withText(fullNameTracked), isCompletelyDisplayed()))
240+
clickOnViewWithText(R.string.change_record_multiselect)
241+
longClickOnView(allOf(withText(fullNameRunning), isCompletelyDisplayed()))
242+
longClickOnView(allOf(withText(fullNameRunning), isCompletelyDisplayed()))
243+
clickOnViewWithText(R.string.data_edit_change_tag)
244+
checkViewDoesNotExist(withText(tag1))
245+
checkViewDoesNotExist(withText(tag2))
246+
clickOnViewWithText(tagGeneral)
247+
clickOnViewWithText(R.string.change_record_save)
248+
249+
tryAction {
250+
checkViewIsDisplayed(
251+
allOf(
252+
withId(baseR.id.viewRecordItem),
253+
hasDescendant(withText("$nameTracked - $tagGeneral")),
254+
isCompletelyDisplayed(),
255+
),
256+
)
257+
checkViewIsDisplayed(
258+
allOf(
259+
withId(baseR.id.viewRunningRecordItem),
260+
hasDescendant(withText("$nameRunning - $tagGeneral")),
261+
isCompletelyDisplayed(),
262+
),
263+
)
264+
}
265+
}
266+
203267
@Suppress("SameParameterValue")
204268
private fun checkRecord(
205269
name: String,

0 commit comments

Comments
 (0)