@@ -12,17 +12,20 @@ import androidx.test.ext.junit.rules.ActivityScenarioRule
12
12
import com.dicoding.moviecatalog.R
13
13
import com.dicoding.moviecatalog.utils.CatalogDatabase
14
14
import com.dicoding.moviecatalog.utils.EspressoIdlingResource
15
+ import com.dicoding.moviecatalog.utils.InlineVariable
15
16
import org.junit.After
16
17
import org.junit.Before
17
18
import org.junit.Rule
18
19
import org.junit.Test
19
20
20
-
21
21
class MainActivityTest {
22
- private val dummyMovie = CatalogDatabase .generateMovieDatabase()
23
- private val dummyCastMovie1 = CatalogDatabase .generateCastListMovie1()
24
- private val dummyCastTvShow1 = CatalogDatabase .generateCastListTvShow1()
25
- private val dummyTvShow = CatalogDatabase .generateTvShowDatabase()
22
+ private val dummyMovie = CatalogDatabase .generateMovieLocal()
23
+ private val dummyGenreMovie = CatalogDatabase .generateGenreMovies()
24
+ private val dummyProductionMovie = CatalogDatabase .generateCompaniesMovies()
25
+ private val dummyProductionTvShow = CatalogDatabase .generateCompaniesTvShow()
26
+ private val dummyGenreTvShow = CatalogDatabase .generateGenreTvShow()
27
+ private val dummyTvShow = CatalogDatabase .generateTvShowLocal()
28
+ private val inlineVariable = InlineVariable ()
26
29
27
30
@get:Rule
28
31
var activityRule = ActivityScenarioRule (MainActivity ::class .java)
@@ -40,6 +43,7 @@ class MainActivityTest {
40
43
41
44
@Test
42
45
fun loadMovie () {
46
+ inlineVariable.delayTwoSecond()
43
47
onView(withText(" MOVIE" )).perform(click())
44
48
onView(withId(R .id.rv_movie)).check(matches(isDisplayed()))
45
49
onView(withId(R .id.rv_movie)).perform(
@@ -51,6 +55,7 @@ class MainActivityTest {
51
55
52
56
@Test
53
57
fun loadDetailMovie () {
58
+ inlineVariable.delayTwoSecond()
54
59
onView(withText(" MOVIE" )).perform(click())
55
60
onView(withId(R .id.rv_movie)).check(matches(isDisplayed()))
56
61
onView(withId(R .id.rv_movie)).perform(
@@ -59,28 +64,40 @@ class MainActivityTest {
59
64
click()
60
65
)
61
66
)
67
+ inlineVariable.delayTwoSecond()
62
68
onView(withId(R .id.movie_title_text)).check(matches(isDisplayed()))
63
69
onView(withId(R .id.movie_title_text)).check(matches(withText(dummyMovie[0 ].title)))
64
70
onView(withId(R .id.movie_release_date)).check(matches(isDisplayed()))
65
- onView(withId(R .id.movie_release_date)).check(matches(withText(dummyMovie[0 ].releaseDate)))
71
+ val releaseDate = inlineVariable.setReleaseDate(dummyMovie[0 ].releaseDate)
72
+ onView(withId(R .id.movie_release_date)).check(matches(withText(releaseDate)))
66
73
onView(withId(R .id.image_poster)).check(matches(isDisplayed()))
67
- onView(withId(R .id.image_poster)).check(matches(withContentDescription(dummyMovie[0 ].imagePath )))
74
+ onView(withId(R .id.image_poster)).check(matches(withContentDescription(dummyMovie[0 ].posterPath )))
68
75
onView(withId(R .id.movie_rating_text)).check(matches(isDisplayed()))
69
- onView(withId(R .id.movie_rating_text)).check(matches(withText(dummyMovie[0 ].rating)))
70
- onView(withId(R .id.movie_duration_text)).check(matches(isDisplayed()))
71
- onView(withId(R .id.movie_duration_text)).check(matches(withText(dummyMovie[0 ].duration)))
76
+ onView(withId(R .id.movie_rating_text)).check(matches(withText(dummyMovie[0 ].voteAverage.toString())))
77
+ onView(withId(R .id.movie_revenue_text)).check(matches(isDisplayed()))
78
+ val revenue = inlineVariable.setRevenue(dummyMovie[0 ].revenue.toString())
79
+ onView(withId(R .id.movie_revenue_text)).check(matches(withText(revenue)))
72
80
onView(withId(R .id.desc_text)).check(matches(isDisplayed()))
73
- onView(withId(R .id.desc_text)).check(matches(withText(dummyMovie[0 ].description)))
74
- onView(withId(R .id.rv_cast)).check(matches(isDisplayed()))
75
- onView(withId(R .id.rv_cast)).perform(
81
+ onView(withId(R .id.desc_text)).check(matches(withText(dummyMovie[0 ].overview)))
82
+ inlineVariable.delayTwoSecond()
83
+ onView(withId(R .id.rv_genre_api)).check(matches(isDisplayed()))
84
+ onView(withId(R .id.rv_genre_api)).perform(
76
85
RecyclerViewActions .scrollToPosition<RecyclerView .ViewHolder >(
77
- dummyCastMovie1.size
86
+ dummyGenreMovie.size
87
+ )
88
+ )
89
+ inlineVariable.delayTwoSecond()
90
+ onView(withId(R .id.rv_companies)).check(matches(isDisplayed()))
91
+ onView(withId(R .id.rv_companies)).perform(
92
+ RecyclerViewActions .scrollToPosition<RecyclerView .ViewHolder >(
93
+ dummyProductionMovie.size
78
94
)
79
95
)
80
96
}
81
97
82
98
@Test
83
99
fun loadDetailTvShow () {
100
+ inlineVariable.delayTwoSecond()
84
101
onView(withText(" TV SHOW" )).perform(click())
85
102
onView(withId(R .id.rv_tvshow)).check(matches(isDisplayed()))
86
103
onView(withId(R .id.rv_tvshow)).perform(
@@ -89,30 +106,49 @@ class MainActivityTest {
89
106
click()
90
107
)
91
108
)
109
+ inlineVariable.delayTwoSecond()
92
110
onView(withId(R .id.movie_title_text)).check(matches(isDisplayed()))
93
- onView(withId(R .id.movie_title_text)).check(matches(withText(dummyTvShow[0 ].title )))
111
+ onView(withId(R .id.movie_title_text)).check(matches(withText(dummyTvShow[0 ].tvShowName )))
94
112
onView(withId(R .id.movie_release_date)).check(matches(isDisplayed()))
95
- onView(withId(R .id.movie_release_date)).check(matches(withText(dummyTvShow[0 ].releaseDate)))
113
+ val releaseDate = dummyTvShow[0 ].tvShowFirstAirDate
114
+ onView(withId(R .id.movie_release_date)).check(
115
+ matches(
116
+ withText(
117
+ inlineVariable.setReleaseDate(
118
+ releaseDate
119
+ )
120
+ )
121
+ )
122
+ )
96
123
onView(withId(R .id.image_poster)).check(matches(isDisplayed()))
97
- onView(withId(R .id.image_poster)).check(matches(withContentDescription(dummyTvShow[0 ].imagePath )))
124
+ onView(withId(R .id.image_poster)).check(matches(withContentDescription(dummyTvShow[0 ].tvShowPoster )))
98
125
onView(withId(R .id.movie_rating_text)).check(matches(isDisplayed()))
99
- onView(withId(R .id.movie_rating_text)).check(matches(withText(dummyTvShow[0 ].rating )))
126
+ onView(withId(R .id.movie_rating_text)).check(matches(withText(dummyTvShow[0 ].tvShowVote.toString() )))
100
127
onView(withId(R .id.movie_episode_text)).check(matches(isDisplayed()))
101
- onView(withId(R .id.movie_episode_text)).check(matches(withText(dummyTvShow[0 ].episode + " | " + dummyTvShow[0 ].season )))
102
- onView(withId(R .id.movie_duration_text )).check(matches(isDisplayed()))
103
- onView(withId(R .id.movie_duration_text )).check(matches(withText(dummyTvShow[0 ].duration )))
128
+ onView(withId(R .id.movie_episode_text)).check(matches(withText(dummyTvShow[0 ].tvShowEpisodes.toString() + " Episode | " + dummyTvShow[0 ].tvShowSeasons.toString() + " Season " )))
129
+ onView(withId(R .id.tvShow_language_text )).check(matches(isDisplayed()))
130
+ onView(withId(R .id.tvShow_language_text )).check(matches(withText(dummyTvShow[0 ].tvShowLanguage )))
104
131
onView(withId(R .id.desc_text)).check(matches(isDisplayed()))
105
- onView(withId(R .id.desc_text)).check(matches(withText(dummyTvShow[0 ].description)))
106
- onView(withId(R .id.rv_cast)).check(matches(isDisplayed()))
107
- onView(withId(R .id.rv_cast)).perform(
132
+ onView(withId(R .id.desc_text)).check(matches(withText(dummyTvShow[0 ].tvShowOverview)))
133
+ inlineVariable.delayTwoSecond()
134
+ onView(withId(R .id.rv_genre_api)).check(matches(isDisplayed()))
135
+ onView(withId(R .id.rv_genre_api)).perform(
108
136
RecyclerViewActions .scrollToPosition<RecyclerView .ViewHolder >(
109
- dummyCastTvShow1.size
137
+ dummyGenreTvShow.size
138
+ )
139
+ )
140
+ inlineVariable.delayTwoSecond()
141
+ onView(withId(R .id.rv_companies)).check(matches(isDisplayed()))
142
+ onView(withId(R .id.rv_companies)).perform(
143
+ RecyclerViewActions .scrollToPosition<RecyclerView .ViewHolder >(
144
+ dummyProductionTvShow.size
110
145
)
111
146
)
112
147
}
113
148
114
149
@Test
115
150
fun loadTvShow () {
151
+ inlineVariable.delayTwoSecond()
116
152
onView(withText(" TV SHOW" )).perform(click())
117
153
onView(withId(R .id.rv_tvshow)).check(matches(isDisplayed()))
118
154
onView(withId(R .id.rv_tvshow)).perform(
@@ -124,6 +160,7 @@ class MainActivityTest {
124
160
125
161
@Test
126
162
fun loadShareMovie () {
163
+ inlineVariable.delayTwoSecond()
127
164
onView(withText(" MOVIE" )).perform(click())
128
165
onView(withId(R .id.rv_movie)).check(matches(isDisplayed()))
129
166
onView(withId(R .id.rv_movie)).perform(
@@ -132,13 +169,15 @@ class MainActivityTest {
132
169
click()
133
170
)
134
171
)
172
+ inlineVariable.delayTwoSecond()
135
173
onView(withId(R .id.img_share)).check(matches(isDisplayed()))
136
174
onView(withId(R .id.img_share)).check(matches(isClickable()))
137
175
onView(withId(R .id.img_share)).perform(click())
138
176
}
139
177
140
178
@Test
141
179
fun loadShareTvShow () {
180
+ inlineVariable.delayTwoSecond()
142
181
onView(withText(" TV SHOW" )).perform(click())
143
182
onView(withId(R .id.rv_tvshow)).check(matches(isDisplayed()))
144
183
onView(withId(R .id.rv_tvshow)).perform(
@@ -147,9 +186,9 @@ class MainActivityTest {
147
186
click()
148
187
)
149
188
)
189
+ inlineVariable.delayTwoSecond()
150
190
onView(withId(R .id.img_share)).check(matches(isDisplayed()))
151
191
onView(withId(R .id.img_share)).check(matches(isClickable()))
152
192
onView(withId(R .id.img_share)).perform(click())
153
193
}
154
-
155
194
}
0 commit comments