Skip to content

Commit 3a43644

Browse files
committed
add change tag tests
1 parent 660eec6 commit 3a43644

File tree

4 files changed

+99
-4
lines changed

4 files changed

+99
-4
lines changed

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

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import com.example.util.simpletimetracker.utils.clickOnRecyclerItem
2020
import com.example.util.simpletimetracker.utils.clickOnViewWithText
2121
import com.example.util.simpletimetracker.utils.longClickOnView
2222
import com.example.util.simpletimetracker.utils.scrollRecyclerToPosition
23+
import com.example.util.simpletimetracker.utils.tryAction
2324
import com.example.util.simpletimetracker.utils.typeTextIntoView
2425
import com.example.util.simpletimetracker.utils.withCardColor
2526
import dagger.hilt.android.testing.HiltAndroidTest
@@ -135,6 +136,37 @@ class AddCategoryTest : BaseUiTest() {
135136
checkViewIsDisplayed(withText(R.string.record_types_empty))
136137
}
137138

139+
@Test
140+
fun addCategoryFromChangeActivity() {
141+
val categoryName1 = "Category1"
142+
val categoryName2 = "Category2"
143+
val typeName = "Type"
144+
145+
// Add activity
146+
testUtils.addActivity(typeName)
147+
tryAction { longClickOnView(withText(typeName)) }
148+
149+
// Add category
150+
clickOnViewWithText(R.string.change_record_type_category_hint)
151+
clickOnViewWithText(R.string.categories_add_activity_tag)
152+
typeTextIntoView(R.id.etChangeCategoryName, categoryName1)
153+
closeSoftKeyboard()
154+
clickOnViewWithText(R.string.change_category_save)
155+
156+
// Category added
157+
checkViewIsDisplayed(withText(categoryName1))
158+
159+
// Change category
160+
longClickOnView(withText(categoryName1))
161+
typeTextIntoView(R.id.etChangeCategoryName, categoryName2)
162+
closeSoftKeyboard()
163+
clickOnViewWithText(R.string.change_category_save)
164+
165+
// Category changed
166+
checkViewDoesNotExist(withText(categoryName1))
167+
checkViewIsDisplayed(withText(categoryName2))
168+
}
169+
138170
private fun checkPreviewUpdated(matcher: Matcher<View>) =
139171
checkViewIsDisplayed(allOf(withId(R.id.previewChangeCategory), matcher))
140172
}

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

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@ import android.view.View
44
import androidx.test.espresso.Espresso.closeSoftKeyboard
55
import androidx.test.espresso.Espresso.onView
66
import androidx.test.espresso.matcher.ViewMatchers.hasDescendant
7+
import androidx.test.espresso.matcher.ViewMatchers.isCompletelyDisplayed
78
import androidx.test.espresso.matcher.ViewMatchers.isDescendantOfA
89
import androidx.test.espresso.matcher.ViewMatchers.withId
910
import androidx.test.espresso.matcher.ViewMatchers.withParent
1011
import androidx.test.espresso.matcher.ViewMatchers.withText
1112
import androidx.test.ext.junit.runners.AndroidJUnit4
1213
import com.example.util.simpletimetracker.utils.BaseUiTest
1314
import com.example.util.simpletimetracker.utils.NavUtils
15+
import com.example.util.simpletimetracker.utils.checkViewDoesNotExist
1416
import com.example.util.simpletimetracker.utils.checkViewIsDisplayed
1517
import com.example.util.simpletimetracker.utils.checkViewIsNotDisplayed
1618
import com.example.util.simpletimetracker.utils.clickOnRecyclerItem
@@ -208,6 +210,71 @@ class AddRecordTagTest : BaseUiTest() {
208210
onView(withId(R.id.rvCategoriesList)).check(recyclerItemCount(7))
209211
}
210212

213+
@Test
214+
fun addRecordTagFromChangeRecord() {
215+
val tagName1 = "Category1"
216+
val tagName2 = "Category2"
217+
val typeName = "Type"
218+
219+
// Add data
220+
testUtils.addActivity(typeName)
221+
testUtils.addRecord(typeName)
222+
223+
// Add category
224+
NavUtils.openRecordsScreen()
225+
clickOnView(allOf(withText(typeName), isCompletelyDisplayed()))
226+
clickOnViewWithId(R.id.fieldChangeRecordCategory)
227+
clickOnViewWithText(R.string.categories_add_record_tag)
228+
typeTextIntoView(R.id.etChangeRecordTagName, tagName1)
229+
closeSoftKeyboard()
230+
clickOnViewWithText(R.string.change_category_save)
231+
232+
// Category added
233+
checkViewIsDisplayed(withText(tagName1))
234+
235+
// Change category
236+
longClickOnView(withText(tagName1))
237+
typeTextIntoView(R.id.etChangeRecordTagName, tagName2)
238+
closeSoftKeyboard()
239+
clickOnViewWithText(R.string.change_category_save)
240+
241+
// Category changed
242+
checkViewDoesNotExist(withText(tagName1))
243+
checkViewIsDisplayed(withText(tagName2))
244+
}
245+
246+
@Test
247+
fun addRecordTagFromChangeRunningRecord() {
248+
val tagName1 = "Tag1"
249+
val tagName2 = "Tag2"
250+
val typeName = "Type"
251+
252+
// Add data
253+
testUtils.addActivity(typeName)
254+
tryAction { clickOnViewWithText(typeName) }
255+
longClickOnView(allOf(isDescendantOfA(withId(R.id.viewRunningRecordItem)), withText(typeName)))
256+
257+
// Add category
258+
clickOnViewWithId(R.id.fieldChangeRunningRecordCategory)
259+
clickOnViewWithText(R.string.categories_add_record_tag)
260+
typeTextIntoView(R.id.etChangeRecordTagName, tagName1)
261+
closeSoftKeyboard()
262+
clickOnViewWithText(R.string.change_category_save)
263+
264+
// Category added
265+
checkViewIsDisplayed(withText(tagName1))
266+
267+
// Change category
268+
longClickOnView(withText(tagName1))
269+
typeTextIntoView(R.id.etChangeRecordTagName, tagName2)
270+
closeSoftKeyboard()
271+
clickOnViewWithText(R.string.change_category_save)
272+
273+
// Category changed
274+
checkViewDoesNotExist(withText(tagName1))
275+
checkViewIsDisplayed(withText(tagName2))
276+
}
277+
211278
private fun checkPreviewUpdated(matcher: Matcher<View>) =
212279
checkViewIsDisplayed(allOf(withId(R.id.previewChangeRecordTag), matcher))
213280
}

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import android.view.View
44
import android.widget.TimePicker
55
import androidx.test.espresso.Espresso.closeSoftKeyboard
66
import androidx.test.espresso.Espresso.onView
7-
import androidx.test.espresso.contrib.PickerActions
87
import androidx.test.espresso.contrib.PickerActions.setTime
98
import androidx.test.espresso.matcher.ViewMatchers.hasDescendant
109
import androidx.test.espresso.matcher.ViewMatchers.isCompletelyDisplayed

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ package com.example.util.simpletimetracker
33
import androidx.test.espresso.Espresso.onView
44
import androidx.test.espresso.Espresso.pressBack
55
import androidx.test.espresso.action.ViewActions.click
6-
import androidx.test.espresso.assertion.ViewAssertions
7-
import androidx.test.espresso.matcher.ViewMatchers
86
import androidx.test.espresso.matcher.ViewMatchers.hasDescendant
97
import androidx.test.espresso.matcher.ViewMatchers.hasSibling
108
import androidx.test.espresso.matcher.ViewMatchers.isCompletelyDisplayed
@@ -24,7 +22,6 @@ import com.example.util.simpletimetracker.utils.clickOnViewWithText
2422
import com.example.util.simpletimetracker.utils.nestedScrollTo
2523
import com.example.util.simpletimetracker.utils.recyclerItemCount
2624
import com.example.util.simpletimetracker.utils.tryAction
27-
import com.example.util.simpletimetracker.utils.unconstrainedClickOnView
2825
import com.example.util.simpletimetracker.utils.withCardColor
2926
import com.example.util.simpletimetracker.utils.withPluralText
3027
import com.example.util.simpletimetracker.utils.withTag

0 commit comments

Comments
 (0)