1
1
package com.example.android.architecture.blueprints.todoapp.taskdetail
2
2
3
3
import androidx.fragment.app.testing.launchFragmentInContainer
4
+ import androidx.test.espresso.Espresso.onView
5
+ import androidx.test.espresso.assertion.ViewAssertions.matches
6
+ import androidx.test.espresso.matcher.ViewMatchers.isChecked
7
+ import androidx.test.espresso.matcher.ViewMatchers.isDisplayed
8
+ import androidx.test.espresso.matcher.ViewMatchers.withId
9
+ import androidx.test.espresso.matcher.ViewMatchers.withText
4
10
import androidx.test.ext.junit.runners.AndroidJUnit4
5
11
import androidx.test.filters.MediumTest
6
12
import com.example.android.architecture.blueprints.todoapp.R
@@ -10,6 +16,7 @@ import com.example.android.architecture.blueprints.todoapp.data.source.TasksRepo
10
16
import com.example.android.architecture.blueprints.todoapp.data.source.androidTest.FakeAndroidTestRepository
11
17
import kotlinx.coroutines.ExperimentalCoroutinesApi
12
18
import kotlinx.coroutines.test.runBlockingTest
19
+ import org.hamcrest.Matchers.not
13
20
import org.junit.After
14
21
import org.junit.Assert.*
15
22
import org.junit.Before
@@ -43,5 +50,35 @@ class TaskDetailFragmentTest {
43
50
// WHEN - Details fragment launched to display task
44
51
val bundle = TaskDetailFragmentArgs (activeTask.id).toBundle()
45
52
launchFragmentInContainer<TaskDetailFragment >(bundle, R .style.AppTheme )
53
+
54
+ // THEN - Task details are displayed on the screen
55
+ // make sure that the title/description are both shown and correct
56
+ onView(withId(R .id.task_detail_title_text)).check(matches(isDisplayed()))
57
+ onView(withId(R .id.task_detail_title_text)).check(matches(withText(" Active Task" )))
58
+ onView(withId(R .id.task_detail_description_text)).check(matches(isDisplayed()))
59
+ onView(withId(R .id.task_detail_description_text)).check(matches(withText(" AndroidX Rocks" )))
60
+ // and make sure the "active" checkbox is shown unchecked
61
+ onView(withId(R .id.task_detail_complete_checkbox)).check(matches(isDisplayed()))
62
+ onView(withId(R .id.task_detail_complete_checkbox)).check(matches(not (isChecked())))
63
+ }
64
+
65
+ @Test
66
+ fun completedTaskDetails_DisplayedInUi () = runBlockingTest{
67
+ // GIVEN - Add completed task to the DB
68
+ val activeTask = Task (" Completed Task" , " AndroidX Rocks" , true )
69
+ repository.saveTask(activeTask)
70
+
71
+ // WHEN - Details fragment launched to display task
72
+ val bundle = TaskDetailFragmentArgs (activeTask.id).toBundle()
73
+ launchFragmentInContainer<TaskDetailFragment >(bundle, R .style.AppTheme )
74
+
75
+ // THEN - Task details are displayed on the screen
76
+ onView(withId(R .id.task_detail_title_text)).check(matches(isDisplayed()))
77
+ onView(withId(R .id.task_detail_title_text)).check(matches(withText(" Completed Task" )))
78
+ onView(withId(R .id.task_detail_description_text)).check(matches(isDisplayed()))
79
+ onView(withId(R .id.task_detail_description_text)).check(matches(withText(" AndroidX Rocks" )))
80
+ // make sure that the title/description are both shown and correct
81
+ onView(withId(R .id.task_detail_complete_checkbox)).check(matches(isDisplayed()))
82
+ onView(withId(R .id.task_detail_complete_checkbox)).check(matches(isChecked()))
46
83
}
47
84
}
0 commit comments