Skip to content

Commit 70cb73d

Browse files
committed
add last comments test
1 parent c91aafe commit 70cb73d

File tree

2 files changed

+98
-1
lines changed
  • app/src/androidTest/java/com/example/util/simpletimetracker
  • core/src/main/java/com/example/util/simpletimetracker/core/utils

2 files changed

+98
-1
lines changed

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

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import androidx.test.espresso.matcher.ViewMatchers.withText
1313
import androidx.test.ext.junit.runners.AndroidJUnit4
1414
import com.example.util.simpletimetracker.utils.BaseUiTest
1515
import com.example.util.simpletimetracker.utils.NavUtils
16+
import com.example.util.simpletimetracker.utils.checkViewDoesNotExist
1617
import com.example.util.simpletimetracker.utils.checkViewIsDisplayed
1718
import com.example.util.simpletimetracker.utils.checkViewIsNotDisplayed
1819
import com.example.util.simpletimetracker.utils.clickOnRecyclerItem
@@ -188,6 +189,101 @@ class AddRecordTest : BaseUiTest() {
188189
checkViewIsDisplayed(withText(R.string.change_record_categories_empty))
189190
}
190191

192+
@Test
193+
fun addRecordComment() {
194+
val nameNoComments = "Name1"
195+
val nameComment = "Name2"
196+
val nameComments = "Name3"
197+
val comment1 = "Comment1"
198+
val comment2 = "Comment2"
199+
val comment3 = "Comment3"
200+
201+
// Add data
202+
testUtils.addActivity(nameNoComments)
203+
testUtils.addActivity(nameComment)
204+
testUtils.addActivity(nameComments)
205+
testUtils.addRecord(nameNoComments)
206+
testUtils.addRecord(nameComment, comment = comment1)
207+
testUtils.addRecord(nameComments, comment = comment2)
208+
testUtils.addRecord(nameComments, comment = comment3)
209+
210+
// Check comments
211+
NavUtils.openRecordsScreen()
212+
clickOnViewWithId(R.id.btnRecordAdd)
213+
214+
// No last comments
215+
checkViewIsNotDisplayed(withText(R.string.change_record_last_comments_hint))
216+
checkViewIsNotDisplayed(withId(R.id.rvChangeRecordLastComments))
217+
checkViewDoesNotExist(withText(comment1))
218+
checkViewDoesNotExist(withText(comment2))
219+
checkViewDoesNotExist(withText(comment3))
220+
221+
// Select activity with no previous comments
222+
clickOnViewWithText(R.string.change_record_type_field)
223+
clickOnRecyclerItem(R.id.rvChangeRecordType, withText(nameNoComments))
224+
clickOnViewWithText(R.string.change_record_type_field)
225+
226+
// Still no last comments
227+
checkViewIsNotDisplayed(withText(R.string.change_record_last_comments_hint))
228+
checkViewIsNotDisplayed(withId(R.id.rvChangeRecordLastComments))
229+
checkViewDoesNotExist(withText(comment1))
230+
checkViewDoesNotExist(withText(comment2))
231+
checkViewDoesNotExist(withText(comment3))
232+
233+
// Select activity with one previous comment
234+
clickOnViewWithText(R.string.change_record_type_field)
235+
clickOnRecyclerItem(R.id.rvChangeRecordType, withText(nameComment))
236+
clickOnViewWithText(R.string.change_record_type_field)
237+
238+
// One last comment
239+
checkViewIsDisplayed(withText(R.string.change_record_last_comments_hint))
240+
checkViewIsNotDisplayed(withId(R.id.rvChangeRecordLastComments))
241+
checkViewDoesNotExist(withText(comment1))
242+
checkViewDoesNotExist(withText(comment2))
243+
checkViewDoesNotExist(withText(comment3))
244+
245+
clickOnViewWithText(R.string.change_record_last_comments_hint)
246+
checkViewIsDisplayed(withId(R.id.rvChangeRecordLastComments))
247+
checkViewIsDisplayed(withText(comment1))
248+
checkViewDoesNotExist(withText(comment2))
249+
checkViewDoesNotExist(withText(comment3))
250+
251+
// Select last comment
252+
clickOnViewWithText(comment1)
253+
tryAction { checkPreviewUpdated(hasDescendant(withText(comment1))) }
254+
typeTextIntoView(R.id.etChangeRecordComment, "")
255+
256+
// Select activity with many previous comments
257+
clickOnViewWithText(R.string.change_record_type_field)
258+
clickOnRecyclerItem(R.id.rvChangeRecordType, withText(nameComments))
259+
clickOnViewWithText(R.string.change_record_type_field)
260+
261+
// Two last comments
262+
checkViewIsDisplayed(withId(R.id.fieldChangeRecordLastComments))
263+
checkViewIsDisplayed(withId(R.id.rvChangeRecordLastComments))
264+
checkViewDoesNotExist(withText(comment1))
265+
checkViewIsDisplayed(withText(comment2))
266+
checkViewIsDisplayed(withText(comment3))
267+
268+
clickOnViewWithId(R.id.fieldChangeRecordLastComments)
269+
checkViewIsNotDisplayed(withId(R.id.rvChangeRecordLastComments))
270+
checkViewDoesNotExist(withText(comment1))
271+
checkViewIsNotDisplayed(withText(comment2))
272+
checkViewIsNotDisplayed(withText(comment3))
273+
274+
clickOnViewWithId(R.id.fieldChangeRecordLastComments)
275+
checkViewIsDisplayed(withId(R.id.rvChangeRecordLastComments))
276+
checkViewDoesNotExist(withText(comment1))
277+
checkViewIsDisplayed(withText(comment2))
278+
checkViewIsDisplayed(withText(comment3))
279+
280+
// Select last comment
281+
clickOnViewWithText(comment2)
282+
tryAction { checkPreviewUpdated(hasDescendant(withText(comment2))) }
283+
clickOnViewWithText(comment3)
284+
tryAction { checkPreviewUpdated(hasDescendant(withText(comment3))) }
285+
}
286+
191287
private fun checkPreviewUpdated(matcher: Matcher<View>) =
192288
checkViewIsDisplayed(allOf(withId(R.id.previewChangeRecord), matcher))
193289
}

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
@@ -103,6 +103,7 @@ class TestUtils @Inject constructor(
103103
timeStarted: Long? = null,
104104
timeEnded: Long? = null,
105105
tagNames: List<String> = emptyList(),
106+
comment: String = "",
106107
) = runBlocking {
107108
val type = recordTypeInteractor.getAll().firstOrNull { it.name == typeName }
108109
?: return@runBlocking
@@ -115,7 +116,7 @@ class TestUtils @Inject constructor(
115116
?: (System.currentTimeMillis() - TimeUnit.HOURS.toMillis(1)),
116117
timeEnded = timeEnded
117118
?: System.currentTimeMillis(),
118-
comment = "",
119+
comment = comment,
119120
tagIds = tagIds,
120121
)
121122

0 commit comments

Comments
 (0)