@@ -13,6 +13,7 @@ import androidx.test.espresso.matcher.ViewMatchers.withText
1313import androidx.test.ext.junit.runners.AndroidJUnit4
1414import com.example.util.simpletimetracker.utils.BaseUiTest
1515import com.example.util.simpletimetracker.utils.NavUtils
16+ import com.example.util.simpletimetracker.utils.checkViewDoesNotExist
1617import com.example.util.simpletimetracker.utils.checkViewIsDisplayed
1718import com.example.util.simpletimetracker.utils.checkViewIsNotDisplayed
1819import 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}
0 commit comments