Skip to content

Commit c43decd

Browse files
committed
add new tests
1 parent 55e38a1 commit c43decd

File tree

6 files changed

+435
-4
lines changed

6 files changed

+435
-4
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,283 @@
1+
package com.example.util.simpletimetracker
2+
3+
import androidx.test.espresso.Espresso.pressBack
4+
import androidx.test.espresso.matcher.ViewMatchers.hasDescendant
5+
import androidx.test.espresso.matcher.ViewMatchers.isCompletelyDisplayed
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.core.extension.setToStartOfDay
10+
import com.example.util.simpletimetracker.utils.BaseUiTest
11+
import com.example.util.simpletimetracker.utils.NavUtils
12+
import com.example.util.simpletimetracker.utils.checkViewIsDisplayed
13+
import com.example.util.simpletimetracker.utils.clickOnViewWithText
14+
import com.example.util.simpletimetracker.utils.longClickOnView
15+
import com.example.util.simpletimetracker.utils.tryAction
16+
import com.example.util.simpletimetracker.utils.withCardColor
17+
import com.example.util.simpletimetracker.utils.withTag
18+
import dagger.hilt.android.testing.HiltAndroidTest
19+
import org.hamcrest.CoreMatchers.allOf
20+
import org.junit.Test
21+
import org.junit.runner.RunWith
22+
import java.util.Calendar
23+
import java.util.concurrent.TimeUnit
24+
import com.example.util.simpletimetracker.core.R as coreR
25+
import com.example.util.simpletimetracker.feature_base_adapter.R as baseR
26+
27+
@HiltAndroidTest
28+
@RunWith(AndroidJUnit4::class)
29+
class RecordActionsChangeActivityTest : BaseUiTest() {
30+
31+
@Test
32+
fun visibility() {
33+
val name1 = "Name1"
34+
val name2 = "Name2"
35+
36+
// Setup
37+
testUtils.addActivity(name1)
38+
testUtils.addActivity(name2)
39+
testUtils.addRecord(name1)
40+
calendar.timeInMillis = System.currentTimeMillis()
41+
testUtils.addRecord(
42+
typeName = name1,
43+
timeStarted = calendar.timeInMillis - TimeUnit.DAYS.toMillis(1),
44+
timeEnded = calendar.timeInMillis - TimeUnit.DAYS.toMillis(1),
45+
)
46+
testUtils.addRunningRecord(name2)
47+
Thread.sleep(1000)
48+
49+
// Running record - shown
50+
NavUtils.openRecordsScreen()
51+
longClickOnView(allOf(withText(name2), isCompletelyDisplayed()))
52+
checkViewIsDisplayed(withText(coreR.string.data_edit_change_activity))
53+
pressBack()
54+
55+
// Record - shown
56+
longClickOnView(allOf(withText(name1), isCompletelyDisplayed()))
57+
checkViewIsDisplayed(withText(coreR.string.data_edit_change_activity))
58+
pressBack()
59+
60+
// Untracked - shown
61+
longClickOnView(allOf(withText(coreR.string.untracked_time_name), isCompletelyDisplayed()))
62+
checkViewIsDisplayed(withText(coreR.string.data_edit_change_activity))
63+
}
64+
65+
@Test
66+
fun record() {
67+
val name1 = "Name1"
68+
val name2 = "Name2"
69+
val color1 = firstColor
70+
val color2 = lastColor
71+
val icon1 = firstIcon
72+
val icon2 = lastIcon
73+
val comment = "Some_comment"
74+
val tag = "Tag"
75+
val tagGeneral = "TagGeneral"
76+
val fullName1 = "$name1 - $tag, $tagGeneral"
77+
val fullName2 = "$name2 - $tagGeneral"
78+
val calendar = Calendar.getInstance()
79+
80+
// Setup
81+
val current = calendar.timeInMillis
82+
val difference = TimeUnit.MINUTES.toMillis(30)
83+
val timeStartedTimestamp = current - difference
84+
val timeStartedPreview = timeStartedTimestamp.formatTime()
85+
val timeEndedPreview = current.formatTime()
86+
val timeRangePreview = difference.formatInterval()
87+
88+
testUtils.addActivity(name = name1, color = color1, icon = icon1)
89+
testUtils.addActivity(name = name2, color = color2, icon = icon2)
90+
testUtils.addRecordTag(tag, typeName = name1)
91+
testUtils.addRecordTag(tagGeneral)
92+
testUtils.addRecord(
93+
typeName = name1,
94+
timeStarted = timeStartedTimestamp,
95+
timeEnded = current,
96+
tagNames = listOf(tag, tagGeneral),
97+
comment = comment,
98+
)
99+
100+
// Check record
101+
NavUtils.openRecordsScreen()
102+
checkRecord(
103+
name = fullName1,
104+
color = color1,
105+
icon = icon1,
106+
timeStartedPreview = timeStartedPreview,
107+
timeEndedPreview = timeEndedPreview,
108+
timeRangePreview = timeRangePreview,
109+
comment = comment,
110+
)
111+
112+
// Change
113+
longClickOnView(allOf(withText(fullName1), isCompletelyDisplayed()))
114+
clickOnViewWithText(R.string.data_edit_change_activity)
115+
clickOnViewWithText(name2)
116+
117+
tryAction {
118+
checkRecord(
119+
name = fullName2,
120+
color = color2,
121+
icon = icon2,
122+
timeStartedPreview = timeStartedPreview,
123+
timeEndedPreview = timeEndedPreview,
124+
timeRangePreview = timeRangePreview,
125+
comment = comment,
126+
)
127+
}
128+
}
129+
130+
@Test
131+
fun untrackedRecord() {
132+
val name1 = "Name1"
133+
val color1 = firstColor
134+
val icon1 = firstIcon
135+
val calendar = Calendar.getInstance()
136+
137+
// Setup
138+
testUtils.addActivity(name = name1, color = color1, icon = icon1)
139+
val current = calendar.timeInMillis
140+
val yesterday = current - TimeUnit.DAYS.toMillis(1)
141+
testUtils.addRecord(typeName = name1, timeStarted = yesterday, timeEnded = yesterday)
142+
143+
val startOfDay = calendar.apply { setToStartOfDay() }.timeInMillis
144+
val timeStartedPreview = startOfDay.formatTime()
145+
val timeEndedPreview = current.formatTime()
146+
val difference = current - startOfDay
147+
val timeRangePreview = difference.formatInterval()
148+
149+
// Check record
150+
NavUtils.openRecordsScreen()
151+
checkViewIsDisplayed(
152+
allOf(
153+
withId(baseR.id.viewRecordItem),
154+
hasDescendant(withText(coreR.string.untracked_time_name)),
155+
hasDescendant(withText(timeStartedPreview)),
156+
hasDescendant(withText(timeEndedPreview)),
157+
hasDescendant(withText(timeRangePreview)),
158+
isCompletelyDisplayed(),
159+
),
160+
)
161+
162+
// Change
163+
longClickOnView(withText(coreR.string.untracked_time_name))
164+
clickOnViewWithText(R.string.data_edit_change_activity)
165+
clickOnViewWithText(name1)
166+
167+
tryAction {
168+
checkRecord(
169+
name = name1,
170+
color = color1,
171+
icon = icon1,
172+
timeStartedPreview = timeStartedPreview,
173+
timeEndedPreview = timeEndedPreview,
174+
timeRangePreview = timeRangePreview,
175+
comment = "",
176+
)
177+
}
178+
}
179+
180+
@Test
181+
fun runningRecord() {
182+
val name1 = "Name1"
183+
val name2 = "Name2"
184+
val color1 = firstColor
185+
val color2 = lastColor
186+
val icon1 = firstIcon
187+
val icon2 = lastIcon
188+
val comment = "Some_comment"
189+
val tag = "Tag"
190+
val tagGeneral = "TagGeneral"
191+
val fullName1 = "$name1 - $tag, $tagGeneral"
192+
val fullName2 = "$name2 - $tagGeneral"
193+
val calendar = Calendar.getInstance()
194+
195+
// Setup
196+
val current = calendar.timeInMillis
197+
val difference = TimeUnit.MINUTES.toMillis(30)
198+
val timeStartedTimestamp = current - difference
199+
val timeStartedPreview = timeStartedTimestamp.formatTime()
200+
201+
testUtils.addActivity(name = name1, color = color1, icon = icon1)
202+
testUtils.addActivity(name = name2, color = color2, icon = icon2)
203+
testUtils.addRecordTag(tag, typeName = name1)
204+
testUtils.addRecordTag(tagGeneral)
205+
testUtils.addRunningRecord(
206+
typeName = name1,
207+
timeStarted = timeStartedTimestamp,
208+
tagNames = listOf(tag, tagGeneral),
209+
comment = comment,
210+
)
211+
212+
// Check record
213+
NavUtils.openRecordsScreen()
214+
checkRunningRecord(
215+
name = fullName1,
216+
color = color1,
217+
icon = icon1,
218+
timeStartedPreview = timeStartedPreview,
219+
comment = comment,
220+
)
221+
222+
// Change
223+
longClickOnView(allOf(withText(fullName1), isCompletelyDisplayed()))
224+
clickOnViewWithText(R.string.data_edit_change_activity)
225+
clickOnViewWithText(name2)
226+
227+
tryAction {
228+
checkRunningRecord(
229+
name = fullName2,
230+
color = color2,
231+
icon = icon2,
232+
timeStartedPreview = timeStartedPreview,
233+
comment = comment,
234+
)
235+
}
236+
}
237+
238+
@Suppress("SameParameterValue")
239+
private fun checkRecord(
240+
name: String,
241+
color: Int,
242+
icon: Int,
243+
timeStartedPreview: String,
244+
timeEndedPreview: String,
245+
timeRangePreview: String,
246+
comment: String,
247+
) {
248+
checkViewIsDisplayed(
249+
allOf(
250+
withId(baseR.id.viewRecordItem),
251+
withCardColor(color),
252+
hasDescendant(withText(name)),
253+
hasDescendant(withTag(icon)),
254+
hasDescendant(withText(timeStartedPreview)),
255+
hasDescendant(withText(timeEndedPreview)),
256+
hasDescendant(withText(timeRangePreview)),
257+
hasDescendant(withText(comment)),
258+
isCompletelyDisplayed(),
259+
),
260+
)
261+
}
262+
263+
@Suppress("SameParameterValue")
264+
private fun checkRunningRecord(
265+
name: String,
266+
color: Int,
267+
icon: Int,
268+
timeStartedPreview: String,
269+
comment: String,
270+
) {
271+
checkViewIsDisplayed(
272+
allOf(
273+
withId(baseR.id.viewRunningRecordItem),
274+
withCardColor(color),
275+
hasDescendant(withText(name)),
276+
hasDescendant(withTag(icon)),
277+
hasDescendant(withText(timeStartedPreview)),
278+
hasDescendant(withText(comment)),
279+
isCompletelyDisplayed(),
280+
),
281+
)
282+
}
283+
}

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

+14-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import com.example.util.simpletimetracker.utils.longClickOnView
1313
import com.example.util.simpletimetracker.utils.tryAction
1414
import dagger.hilt.android.testing.HiltAndroidTest
1515
import kotlinx.coroutines.runBlocking
16-
import org.hamcrest.CoreMatchers
1716
import org.hamcrest.Matchers.allOf
1817
import org.junit.Test
1918
import org.junit.runner.RunWith
@@ -26,21 +25,26 @@ class RecordQuickActionsTest : BaseUiTest() {
2625
@Test
2726
fun recordQuickActions() {
2827
val name = "Test"
28+
val tag = "Tag"
2929

3030
// Add data
3131
testUtils.addActivity(name)
3232
testUtils.addRecord(name)
33+
testUtils.addRecordTag(tag)
3334

3435
// Check
3536
NavUtils.openRecordsScreen()
36-
longClickOnView(CoreMatchers.allOf(withText(name), isCompletelyDisplayed()))
37+
longClickOnView(allOf(withText(name), isCompletelyDisplayed()))
3738

3839
checkViewIsDisplayed(withText(R.string.shortcut_navigation_statistics))
3940
checkViewIsDisplayed(withText(R.string.archive_dialog_delete))
4041
checkViewIsDisplayed(withText(R.string.change_record_continue))
4142
checkViewIsDisplayed(withText(R.string.change_record_repeat))
4243
checkViewIsDisplayed(withText(R.string.change_record_duplicate))
44+
checkViewIsDisplayed(withText(R.string.data_edit_change_activity))
45+
checkViewIsDisplayed(withText(R.string.data_edit_change_tag))
4346
checkViewDoesNotExist(withText(R.string.change_record_merge))
47+
checkViewDoesNotExist(withText(R.string.notification_record_type_stop))
4448
}
4549

4650
@Test
@@ -67,15 +71,20 @@ class RecordQuickActionsTest : BaseUiTest() {
6771
checkViewDoesNotExist(withText(R.string.change_record_continue))
6872
checkViewDoesNotExist(withText(R.string.change_record_repeat))
6973
checkViewDoesNotExist(withText(R.string.change_record_duplicate))
74+
checkViewIsDisplayed(withText(R.string.data_edit_change_activity))
75+
checkViewDoesNotExist(withText(R.string.data_edit_change_tag))
7076
checkViewIsDisplayed(withText(R.string.change_record_merge))
77+
checkViewDoesNotExist(withText(R.string.notification_record_type_stop))
7178
}
7279

7380
@Test
7481
fun runningRecordQuickActions() {
7582
val name = "Test"
83+
val tag = "Tag"
7684

7785
// Add data
7886
testUtils.addActivity(name)
87+
testUtils.addRecordTag(tag)
7988
Thread.sleep(1000)
8089
tryAction { clickOnViewWithText(name) }
8190

@@ -88,6 +97,9 @@ class RecordQuickActionsTest : BaseUiTest() {
8897
checkViewDoesNotExist(withText(R.string.change_record_continue))
8998
checkViewDoesNotExist(withText(R.string.change_record_repeat))
9099
checkViewDoesNotExist(withText(R.string.change_record_duplicate))
100+
checkViewIsDisplayed(withText(R.string.data_edit_change_activity))
101+
checkViewIsDisplayed(withText(R.string.data_edit_change_tag))
91102
checkViewDoesNotExist(withText(R.string.change_record_merge))
103+
checkViewIsDisplayed(withText(R.string.notification_record_type_stop))
92104
}
93105
}

0 commit comments

Comments
 (0)