Skip to content

Commit 32d2e55

Browse files
committed
add more tests
1 parent ebb15c1 commit 32d2e55

File tree

6 files changed

+595
-5
lines changed

6 files changed

+595
-5
lines changed

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

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,21 @@ import androidx.test.espresso.Espresso.onView
66
import androidx.test.espresso.assertion.PositionAssertions.isCompletelyAbove
77
import androidx.test.espresso.assertion.PositionAssertions.isCompletelyBelow
88
import androidx.test.espresso.matcher.ViewMatchers.hasDescendant
9+
import androidx.test.espresso.matcher.ViewMatchers.isDescendantOfA
910
import androidx.test.espresso.matcher.ViewMatchers.withId
1011
import androidx.test.espresso.matcher.ViewMatchers.withParent
1112
import androidx.test.espresso.matcher.ViewMatchers.withText
1213
import androidx.test.ext.junit.runners.AndroidJUnit4
1314
import com.example.util.simpletimetracker.core.mapper.ColorMapper
15+
import com.example.util.simpletimetracker.feature_change_record_type.R
1416
import com.example.util.simpletimetracker.utils.BaseUiTest
1517
import com.example.util.simpletimetracker.utils.NavUtils
1618
import com.example.util.simpletimetracker.utils.checkViewDoesNotExist
1719
import com.example.util.simpletimetracker.utils.checkViewIsDisplayed
1820
import com.example.util.simpletimetracker.utils.checkViewIsNotDisplayed
1921
import com.example.util.simpletimetracker.utils.clickOnRecyclerItem
22+
import com.example.util.simpletimetracker.utils.clickOnView
23+
import com.example.util.simpletimetracker.utils.clickOnViewWithId
2024
import com.example.util.simpletimetracker.utils.clickOnViewWithText
2125
import com.example.util.simpletimetracker.utils.longClickOnView
2226
import com.example.util.simpletimetracker.utils.scrollRecyclerToPosition
@@ -31,6 +35,7 @@ import org.junit.runner.RunWith
3135
import com.example.util.simpletimetracker.core.R as coreR
3236
import com.example.util.simpletimetracker.feature_base_adapter.R as baseR
3337
import com.example.util.simpletimetracker.feature_change_category.R as changeCategoryR
38+
import com.example.util.simpletimetracker.feature_dialogs.R as dialogsR
3439

3540
@HiltAndroidTest
3641
@RunWith(AndroidJUnit4::class)
@@ -118,9 +123,26 @@ class AddCategoryTest : BaseUiTest() {
118123
onView(withText(typeName2)).check(isCompletelyBelow(withId(changeCategoryR.id.viewDividerItem)))
119124

120125
clickOnRecyclerItem(changeCategoryR.id.rvChangeCategoryType, withText(typeName1))
121-
clickOnViewWithText(coreR.string.change_record_type_save)
126+
clickOnViewWithText(coreR.string.change_category_types_hint)
127+
128+
// Selecting goal time
129+
clickOnViewWithText(coreR.string.change_record_type_goal_time_hint)
130+
clickOnView(
131+
allOf(
132+
isDescendantOfA(withId(R.id.layoutChangeRecordTypeGoalSession)),
133+
withId(R.id.fieldChangeRecordTypeGoalDuration),
134+
),
135+
)
136+
clickOnViewWithId(dialogsR.id.tvNumberKeyboard1)
137+
clickOnViewWithId(dialogsR.id.tvNumberKeyboard0)
138+
clickOnViewWithId(dialogsR.id.tvNumberKeyboard0)
139+
clickOnViewWithId(dialogsR.id.tvNumberKeyboard0)
140+
clickOnViewWithText(coreR.string.duration_dialog_save)
141+
checkViewIsDisplayed(withText("10$minuteString"))
142+
clickOnViewWithText(coreR.string.change_record_type_goal_time_hint)
122143

123-
// Category type added
144+
// Category added
145+
clickOnViewWithText(coreR.string.change_record_type_save)
124146
checkViewIsDisplayed(withText(name))
125147
checkViewIsDisplayed(withCardColor(lastColor))
126148

@@ -131,14 +153,30 @@ class AddCategoryTest : BaseUiTest() {
131153
checkViewIsDisplayed(withId(baseR.id.viewDividerItem))
132154
onView(withText(typeName1)).check(isCompletelyAbove(withId(baseR.id.viewDividerItem)))
133155
onView(withText(typeName2)).check(isCompletelyBelow(withId(baseR.id.viewDividerItem)))
156+
157+
// Check goals saved
158+
clickOnViewWithText(coreR.string.change_category_types_hint)
159+
clickOnViewWithText(coreR.string.change_record_type_goal_time_hint)
160+
checkViewIsDisplayed(withText("10$minuteString"))
134161
}
135162

136163
@Test
137-
fun addCategoryTypesEmpty() {
164+
fun addCategoryEmpty() {
138165
NavUtils.openSettingsScreen()
139166
NavUtils.openCategoriesScreen()
140167
clickOnViewWithText(coreR.string.categories_add_category)
141168

169+
// Goal time is disabled
170+
clickOnViewWithText(coreR.string.change_record_type_goal_time_hint)
171+
checkViewIsDisplayed(
172+
allOf(
173+
isDescendantOfA(withId(R.id.layoutChangeRecordTypeGoalSession)),
174+
withId(R.id.tvChangeRecordTypeGoalDurationValue),
175+
withText(coreR.string.change_record_type_goal_time_disabled),
176+
),
177+
)
178+
clickOnViewWithText(coreR.string.change_record_type_goal_time_hint)
179+
142180
// Open activity chooser
143181
clickOnViewWithText(coreR.string.change_category_types_hint)
144182
checkViewIsDisplayed(withText(coreR.string.record_types_empty))

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ class AddRecordTypeTest : BaseUiTest() {
172172
}
173173

174174
@Test
175-
fun addRecordTypeCategoriesEmpty() {
175+
fun addRecordTypeEmpty() {
176176
tryAction { clickOnViewWithText(coreR.string.running_records_add_type) }
177177

178178
// Goal time is disabled
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
package com.example.util.simpletimetracker
2+
3+
import android.view.View
4+
import androidx.test.espresso.matcher.ViewMatchers.hasDescendant
5+
import androidx.test.espresso.matcher.ViewMatchers.isCompletelyDisplayed
6+
import androidx.test.espresso.matcher.ViewMatchers.isDescendantOfA
7+
import androidx.test.espresso.matcher.ViewMatchers.withId
8+
import androidx.test.espresso.matcher.ViewMatchers.withText
9+
import androidx.test.ext.junit.runners.AndroidJUnit4
10+
import com.example.util.simpletimetracker.feature_change_record.R
11+
import com.example.util.simpletimetracker.utils.BaseUiTest
12+
import com.example.util.simpletimetracker.utils.NavUtils
13+
import com.example.util.simpletimetracker.utils.checkViewIsDisplayed
14+
import com.example.util.simpletimetracker.utils.checkViewIsNotDisplayed
15+
import dagger.hilt.android.testing.HiltAndroidTest
16+
import org.hamcrest.CoreMatchers.allOf
17+
import org.hamcrest.Matcher
18+
import org.junit.Test
19+
import org.junit.runner.RunWith
20+
import java.util.concurrent.TimeUnit
21+
22+
@HiltAndroidTest
23+
@RunWith(AndroidJUnit4::class)
24+
class GoalsOnCardsTest : BaseUiTest() {
25+
26+
@Test
27+
fun noGoals() {
28+
val noGoals = "noGoals"
29+
val otherGoals = "otherGoals"
30+
31+
// Add data
32+
testUtils.addActivity(noGoals)
33+
testUtils.addActivity(
34+
name = otherGoals,
35+
goals = listOf(
36+
GoalsTestUtils.getSessionDurationGoal(1),
37+
GoalsTestUtils.getWeeklyDurationGoal(1),
38+
GoalsTestUtils.getMonthlyDurationGoal(1),
39+
GoalsTestUtils.getWeeklyCountGoal(1),
40+
GoalsTestUtils.getMonthlyCountGoal(1),
41+
),
42+
)
43+
Thread.sleep(1000)
44+
45+
// Check
46+
checkNoGoal(noGoals)
47+
checkNoGoal(otherGoals)
48+
}
49+
50+
@Test
51+
fun checkmarks() {
52+
val durationGoal = "durationGoal"
53+
val countGoal = "countGoal"
54+
55+
// Add data
56+
testUtils.addActivity(
57+
name = durationGoal,
58+
goals = listOf(GoalsTestUtils.getDailyDurationGoal(2)),
59+
)
60+
testUtils.addActivity(
61+
name = countGoal,
62+
goals = listOf(GoalsTestUtils.getDailyCountGoal(2)),
63+
)
64+
Thread.sleep(1000)
65+
66+
// Not reached
67+
checkCheckmark(durationGoal, isVisible = false)
68+
checkCheckmark(countGoal, isVisible = false)
69+
70+
// Add records
71+
NavUtils.openRecordsScreen()
72+
val current = System.currentTimeMillis()
73+
testUtils.addRecord(
74+
typeName = durationGoal,
75+
timeStarted = current - TimeUnit.SECONDS.toMillis(1),
76+
timeEnded = current,
77+
)
78+
testUtils.addRecord(
79+
typeName = countGoal,
80+
)
81+
82+
// Not reached
83+
NavUtils.openRunningRecordsScreen()
84+
checkCheckmark(durationGoal, isVisible = false)
85+
checkCheckmark(countGoal, isVisible = false)
86+
87+
// Add more records
88+
NavUtils.openRecordsScreen()
89+
testUtils.addRecord(
90+
typeName = durationGoal,
91+
timeStarted = current - TimeUnit.SECONDS.toMillis(1),
92+
timeEnded = current,
93+
)
94+
testUtils.addRecord(
95+
typeName = countGoal,
96+
)
97+
98+
// Reached
99+
NavUtils.openRunningRecordsScreen()
100+
checkCheckmark(durationGoal, isVisible = true)
101+
checkCheckmark(countGoal, isVisible = true)
102+
}
103+
104+
private fun checkNoGoal(typeName: String) {
105+
allOf(withId(R.id.viewRecordTypeItem), hasDescendant(withText(typeName)), isCompletelyDisplayed())
106+
.let(::checkViewIsDisplayed)
107+
allOf(getTypeMatcher(typeName), withId(R.id.ivGoalCheckmarkItemCheckOutline))
108+
.let(::checkViewIsNotDisplayed)
109+
allOf(getTypeMatcher(typeName), withId(R.id.ivGoalCheckmarkItemCheck))
110+
.let(::checkViewIsNotDisplayed)
111+
}
112+
113+
private fun checkCheckmark(typeName: String, isVisible: Boolean) {
114+
allOf(withId(R.id.viewRecordTypeItem), hasDescendant(withText(typeName)), isCompletelyDisplayed())
115+
.let(::checkViewIsDisplayed)
116+
allOf(getTypeMatcher(typeName), withId(R.id.ivGoalCheckmarkItemCheckOutline))
117+
.let(::checkViewIsDisplayed)
118+
allOf(getTypeMatcher(typeName), withId(R.id.ivGoalCheckmarkItemCheck))
119+
.let { if (isVisible) checkViewIsDisplayed(it) else checkViewIsNotDisplayed(it) }
120+
}
121+
122+
private fun getTypeMatcher(typeName: String): Matcher<View> {
123+
return isDescendantOfA(
124+
allOf(
125+
withId(R.id.viewRecordTypeItem),
126+
hasDescendant(withText(typeName)),
127+
),
128+
)
129+
}
130+
}

0 commit comments

Comments
 (0)