|
| 1 | +package org.wikipedia.main |
| 2 | + |
| 3 | +import androidx.recyclerview.widget.RecyclerView |
| 4 | +import androidx.test.espresso.Espresso.onView |
| 5 | +import androidx.test.espresso.Espresso.pressBack |
| 6 | +import androidx.test.espresso.action.ViewActions.* |
| 7 | +import androidx.test.espresso.assertion.ViewAssertions |
| 8 | +import androidx.test.espresso.contrib.RecyclerViewActions |
| 9 | +import androidx.test.espresso.matcher.ViewMatchers.* |
| 10 | +import androidx.test.ext.junit.rules.ActivityScenarioRule |
| 11 | +import androidx.test.ext.junit.runners.AndroidJUnit4 |
| 12 | +import androidx.test.filters.LargeTest |
| 13 | +import org.hamcrest.Matchers |
| 14 | +import org.hamcrest.Matchers.allOf |
| 15 | +import org.junit.Before |
| 16 | +import org.junit.Rule |
| 17 | +import org.junit.Test |
| 18 | +import org.junit.runner.RunWith |
| 19 | +import org.wikipedia.R |
| 20 | +import org.wikipedia.TestUtil |
| 21 | +import org.wikipedia.TestUtil.childAtPosition |
| 22 | +import org.wikipedia.TestUtil.isNotVisible |
| 23 | +import org.wikipedia.auth.AccountUtil |
| 24 | + |
| 25 | +@LargeTest |
| 26 | +@RunWith(AndroidJUnit4::class) |
| 27 | +class ExploreFeedTests { |
| 28 | + |
| 29 | + @Rule |
| 30 | + @JvmField |
| 31 | + var mActivityTestRule = ActivityScenarioRule(MainActivity::class.java) |
| 32 | + private lateinit var activity: MainActivity |
| 33 | + |
| 34 | + @Before |
| 35 | + fun setActivity() { |
| 36 | + mActivityTestRule.scenario.onActivity { |
| 37 | + activity = it |
| 38 | + } |
| 39 | + } |
| 40 | + @Test |
| 41 | + fun exploreFeedTest() { |
| 42 | + |
| 43 | + // Skip the initial onboarding screens... |
| 44 | + onView(allOf(withId(R.id.fragment_onboarding_skip_button), isDisplayed())) |
| 45 | + .perform(click()) |
| 46 | + |
| 47 | + TestUtil.delay(2) |
| 48 | + |
| 49 | + // Dismiss the Feed customization onboarding card in the feed |
| 50 | + onView(allOf(withId(R.id.view_announcement_action_negative), withText("Got it"), isDisplayed())) |
| 51 | + .perform(click()) |
| 52 | + |
| 53 | + TestUtil.delay(1) |
| 54 | + |
| 55 | + // Featured article card seen and saved to reading lists |
| 56 | + onView(allOf(withId(R.id.view_featured_article_card_content_container), |
| 57 | + childAtPosition(childAtPosition(withClassName(Matchers.`is`("org.wikipedia.feed.featured.FeaturedArticleCardView")), 0), 1), isDisplayed())) |
| 58 | + .perform(scrollTo(), longClick()) |
| 59 | + |
| 60 | + onView(allOf(withId(R.id.title), withText("Save"), |
| 61 | + childAtPosition(childAtPosition(withId(androidx.appcompat.R.id.content), 0), 0), isDisplayed())) |
| 62 | + .perform(click()) |
| 63 | + |
| 64 | + TestUtil.delay(2) |
| 65 | + |
| 66 | + onView(allOf(withId(R.id.feed_view), isNotFocused())).perform(RecyclerViewActions.scrollToPosition<RecyclerView.ViewHolder>(3)) |
| 67 | + TestUtil.delay(2) |
| 68 | + |
| 69 | + // Top read card seen and saved to reading lists |
| 70 | + onView(allOf(withId(R.id.view_list_card_list), childAtPosition(withId(R.id.view_list_card_list_container), 0))) |
| 71 | + .perform(RecyclerViewActions.actionOnItemAtPosition<RecyclerView.ViewHolder>(1, longClick())) |
| 72 | + |
| 73 | + onView(allOf(withId(R.id.title), withText("Save"), |
| 74 | + childAtPosition(childAtPosition(withId(androidx.appcompat.R.id.content), 0), 0), isDisplayed())) |
| 75 | + .perform(click()) |
| 76 | + |
| 77 | + TestUtil.delay(2) |
| 78 | + |
| 79 | + onView(allOf(withId(R.id.feed_view), isNotFocused())).perform(RecyclerViewActions.scrollToPosition<RecyclerView.ViewHolder>(4)) |
| 80 | + |
| 81 | + TestUtil.delay(2) |
| 82 | + |
| 83 | + // Picture of the day card seen and clicked |
| 84 | + onView(allOf(withId(R.id.view_featured_image_card_content_container), |
| 85 | + childAtPosition(childAtPosition(withClassName(Matchers.`is`("org.wikipedia.feed.image.FeaturedImageCardView")), 0), 1), isDisplayed())) |
| 86 | + .perform(click()) |
| 87 | + |
| 88 | + TestUtil.delay(2) |
| 89 | + |
| 90 | + pressBack() |
| 91 | + |
| 92 | + TestUtil.delay(2) |
| 93 | + |
| 94 | + onView(allOf(withId(R.id.feed_view), isNotFocused())).perform(RecyclerViewActions.scrollToPosition<RecyclerView.ViewHolder>(5), click()) |
| 95 | + |
| 96 | + TestUtil.delay(2) |
| 97 | + |
| 98 | + // News card seen and news item saved to reading lists |
| 99 | + onView(allOf(withId(R.id.news_story_items_recyclerview), |
| 100 | + childAtPosition(withClassName(Matchers.`is`("android.widget.LinearLayout")), 1))) |
| 101 | + .perform(RecyclerViewActions.actionOnItemAtPosition<RecyclerView.ViewHolder>(0, longClick())) |
| 102 | + |
| 103 | + onView(allOf(withId(R.id.title), withText("Save"), |
| 104 | + childAtPosition(childAtPosition(withId(androidx.appcompat.R.id.content), 0), 0), isDisplayed())) |
| 105 | + .perform(click()) |
| 106 | + |
| 107 | + TestUtil.delay(2) |
| 108 | + |
| 109 | + pressBack() |
| 110 | + |
| 111 | + TestUtil.delay(2) |
| 112 | + |
| 113 | + onView(allOf(withId(R.id.feed_view), isNotFocused())).perform(RecyclerViewActions.scrollToPosition<RecyclerView.ViewHolder>(6)) |
| 114 | + |
| 115 | + TestUtil.delay(2) |
| 116 | + |
| 117 | + // On this day card seen and saved to reading lists |
| 118 | + onView(allOf(withId(R.id.on_this_day_page), |
| 119 | + childAtPosition(allOf(withId(R.id.event_layout), childAtPosition(withId(R.id.on_this_day_card_view_click_container), 0)), 3), isDisplayed())) |
| 120 | + .perform(longClick()) |
| 121 | + |
| 122 | + onView(allOf(withId(R.id.title), withText("Save"), |
| 123 | + childAtPosition(childAtPosition(withId(androidx.appcompat.R.id.content), 0), 0), isDisplayed())) |
| 124 | + .perform(click()) |
| 125 | + |
| 126 | + TestUtil.delay(2) |
| 127 | + |
| 128 | + goToTop() |
| 129 | + |
| 130 | + TestUtil.delay(2) |
| 131 | + |
| 132 | + onView(allOf(withId(R.id.feed_view), isDisplayed())).perform(RecyclerViewActions.scrollToPosition<RecyclerView.ViewHolder>(7)) |
| 133 | + |
| 134 | + TestUtil.delay(2) |
| 135 | + |
| 136 | + // Random article card seen and saved to reading lists |
| 137 | + onView(allOf(withId(R.id.view_featured_article_card_content_container), |
| 138 | + childAtPosition(childAtPosition(withClassName(Matchers.`is`("org.wikipedia.feed.random.RandomCardView")), 0), 1), isDisplayed())) |
| 139 | + .perform(scrollTo(), longClick()) |
| 140 | + |
| 141 | + onView(allOf(withId(R.id.title), withText("Save"), |
| 142 | + childAtPosition(childAtPosition(withId(androidx.appcompat.R.id.content), 0), 0), isDisplayed())) |
| 143 | + .perform(click()) |
| 144 | + |
| 145 | + TestUtil.delay(2) |
| 146 | + |
| 147 | + if (AccountUtil.isLoggedIn) { |
| 148 | + // Access Suggested edits card |
| 149 | + onView(allOf(withId(R.id.feed_view), isDisplayed())).perform(RecyclerViewActions.scrollToPosition<RecyclerView.ViewHolder>(9)) |
| 150 | + |
| 151 | + TestUtil.delay(2) |
| 152 | + |
| 153 | + onView(allOf(withId(R.id.callToActionButton), withText("Add article description"), |
| 154 | + childAtPosition(allOf(withId(R.id.viewArticleContainer), childAtPosition(withId(R.id.cardItemContainer), 1)), 6), isDisplayed())) |
| 155 | + .perform(click()) |
| 156 | + |
| 157 | + TestUtil.delay(2) |
| 158 | + |
| 159 | + pressBack() |
| 160 | + |
| 161 | + TestUtil.delay(2) |
| 162 | + |
| 163 | + pressBack() |
| 164 | + |
| 165 | + TestUtil.delay(2) |
| 166 | + } |
| 167 | + |
| 168 | + onView(allOf(withId(R.id.feed_view), isDisplayed())).perform(RecyclerViewActions.scrollToPosition<RecyclerView.ViewHolder>(8)) |
| 169 | + |
| 170 | + TestUtil.delay(2) |
| 171 | + |
| 172 | + // Main page card seen clicked |
| 173 | + onView(allOf(withId(R.id.footerActionButton), withText("View main page "), |
| 174 | + childAtPosition(allOf(withId(R.id.card_footer), childAtPosition(withClassName(Matchers.`is`("android.widget.LinearLayout")), 1)), 0), isDisplayed())) |
| 175 | + .perform(click()) |
| 176 | + |
| 177 | + TestUtil.delay(2) |
| 178 | + |
| 179 | + pressBack() |
| 180 | + |
| 181 | + TestUtil.delay(2) |
| 182 | + |
| 183 | + // Access the other navigation tabs - `Saved`, `Search` and `Edits` |
| 184 | + onView(allOf(withId(R.id.nav_tab_reading_lists), withContentDescription("Saved"), |
| 185 | + childAtPosition(childAtPosition(withId(R.id.main_nav_tab_layout), 0), 1), isDisplayed())).perform(click()) |
| 186 | + |
| 187 | + TestUtil.delay(2) |
| 188 | + |
| 189 | + onView(allOf(withId(R.id.nav_tab_search), withContentDescription("Search"), |
| 190 | + childAtPosition(childAtPosition(withId(R.id.main_nav_tab_layout), 0), 2), isDisplayed())).perform(click()) |
| 191 | + |
| 192 | + TestUtil.delay(2) |
| 193 | + |
| 194 | + onView(allOf(withId(R.id.nav_tab_edits), withContentDescription("Edits"), |
| 195 | + childAtPosition(childAtPosition(withId(R.id.main_nav_tab_layout), 0), 3), isDisplayed())).perform(click()) |
| 196 | + |
| 197 | + TestUtil.delay(2) |
| 198 | + |
| 199 | + if (AccountUtil.isLoggedIn) { |
| 200 | + // Click through `Edits` screen stats onboarding |
| 201 | + for (i in 1 until 5) { |
| 202 | + onView(allOf(withId(R.id.buttonView), withText("Got it"), |
| 203 | + childAtPosition(childAtPosition(withClassName(Matchers.`is`("android.widget.LinearLayout")), 1), 0), isDisplayed())) |
| 204 | + .perform(click()) |
| 205 | + TestUtil.delay(2) |
| 206 | + } |
| 207 | + } |
| 208 | + |
| 209 | + // Click on `More` menu |
| 210 | + onView(allOf(withId(R.id.nav_more_container), withContentDescription("More"), isDisplayed())).perform(click()) |
| 211 | + |
| 212 | + TestUtil.delay(2) |
| 213 | + |
| 214 | + // Click on `Settings` option |
| 215 | + onView(allOf(withId(R.id.main_drawer_settings_container), isDisplayed())).perform(click()) |
| 216 | + |
| 217 | + TestUtil.delay(2) |
| 218 | + |
| 219 | + // Click on `Explore feed` option |
| 220 | + onView(allOf(withId(R.id.recycler_view), |
| 221 | + childAtPosition(withId(android.R.id.list_container), 0))) |
| 222 | + .perform(RecyclerViewActions.actionOnItemAtPosition<RecyclerView.ViewHolder>(2, click())) |
| 223 | + |
| 224 | + TestUtil.delay(2) |
| 225 | + |
| 226 | + onView(allOf(withContentDescription("More options"), |
| 227 | + childAtPosition(childAtPosition(withId(androidx.appcompat.R.id.action_bar), 2), 0), isDisplayed())) |
| 228 | + .perform(click()) |
| 229 | + |
| 230 | + TestUtil.delay(2) |
| 231 | + |
| 232 | + onView(allOf(withId(R.id.title), withText("Hide all"), |
| 233 | + childAtPosition(childAtPosition(withId(androidx.appcompat.R.id.content), 0), 0), isDisplayed())) |
| 234 | + .perform(click()) |
| 235 | + |
| 236 | + TestUtil.delay(2) |
| 237 | + |
| 238 | + pressBack() |
| 239 | + |
| 240 | + TestUtil.delay(2) |
| 241 | + |
| 242 | + pressBack() |
| 243 | + |
| 244 | + TestUtil.delay(2) |
| 245 | + |
| 246 | + onView(allOf(withId(R.id.nav_tab_explore), withContentDescription("Explore"), |
| 247 | + childAtPosition(childAtPosition(withId(R.id.main_nav_tab_layout), 0), 0), isDisplayed())).perform(click()) |
| 248 | + |
| 249 | + TestUtil.delay(2) |
| 250 | + |
| 251 | + onView(allOf(withId(R.id.empty_container), withParent(withParent(withId(R.id.swipe_refresh_layout))), isDisplayed())) |
| 252 | + .check(ViewAssertions.matches(isDisplayed())) |
| 253 | + |
| 254 | + TestUtil.delay(2) |
| 255 | + |
| 256 | + // Click on `More` menu |
| 257 | + onView(allOf(withId(R.id.nav_more_container), withContentDescription("More"), isDisplayed())).perform(click()) |
| 258 | + |
| 259 | + TestUtil.delay(2) |
| 260 | + |
| 261 | + // Click on `Settings` option |
| 262 | + onView(allOf(withId(R.id.main_drawer_settings_container), isDisplayed())).perform(click()) |
| 263 | + |
| 264 | + TestUtil.delay(2) |
| 265 | + |
| 266 | + // Click on `Explore feed` option |
| 267 | + onView(allOf(withId(R.id.recycler_view), |
| 268 | + childAtPosition(withId(android.R.id.list_container), 0))) |
| 269 | + .perform(RecyclerViewActions.actionOnItemAtPosition<RecyclerView.ViewHolder>(2, click())) |
| 270 | + TestUtil.delay(2) |
| 271 | + |
| 272 | + onView(allOf(withContentDescription("More options"), |
| 273 | + childAtPosition(childAtPosition(withId(androidx.appcompat.R.id.action_bar), 2), 0), isDisplayed())) |
| 274 | + .perform(click()) |
| 275 | + |
| 276 | + TestUtil.delay(2) |
| 277 | + |
| 278 | + onView(allOf(withId(R.id.title), withText("Show all"), |
| 279 | + childAtPosition(childAtPosition(withId(androidx.appcompat.R.id.content), 0), 0), isDisplayed())) |
| 280 | + .perform(click()) |
| 281 | + |
| 282 | + TestUtil.delay(2) |
| 283 | + |
| 284 | + pressBack() |
| 285 | + |
| 286 | + TestUtil.delay(2) |
| 287 | + |
| 288 | + pressBack() |
| 289 | + |
| 290 | + TestUtil.delay(2) |
| 291 | + |
| 292 | + onView(allOf(withId(R.id.empty_container), withParent(withParent(withId(R.id.swipe_refresh_layout))), isNotVisible())) |
| 293 | + .check(ViewAssertions.matches(isNotVisible())) |
| 294 | + |
| 295 | + TestUtil.delay(2) |
| 296 | + |
| 297 | + // Test `Developer settings activation process via `Settings` screen |
| 298 | + onView(allOf(withId(R.id.nav_more_container), withContentDescription("More"), isDisplayed())).perform(click()) |
| 299 | + |
| 300 | + TestUtil.delay(2) |
| 301 | + |
| 302 | + onView(allOf(withId(R.id.main_drawer_settings_container), isDisplayed())).perform(click()) |
| 303 | + |
| 304 | + TestUtil.delay(2) |
| 305 | + |
| 306 | + onView(allOf(withId(R.id.recycler_view), childAtPosition(withId(android.R.id.list_container), 0))) |
| 307 | + .perform(RecyclerViewActions.actionOnItemAtPosition<RecyclerView.ViewHolder>(16, click())) |
| 308 | + |
| 309 | + TestUtil.delay(2) |
| 310 | + |
| 311 | + for (i in 1 until 8) { |
| 312 | + onView(allOf(withId(R.id.about_logo_image), |
| 313 | + childAtPosition(childAtPosition(withId(R.id.about_container), 0), 0))) |
| 314 | + .perform(scrollTo(), click()) |
| 315 | + TestUtil.delay(2) |
| 316 | + } |
| 317 | + |
| 318 | + TestUtil.delay(2) |
| 319 | + |
| 320 | + pressBack() |
| 321 | + |
| 322 | + TestUtil.delay(2) |
| 323 | + |
| 324 | + onView(allOf(withId(R.id.developer_settings), withContentDescription("Developer settings"), |
| 325 | + childAtPosition(childAtPosition(withId(androidx.appcompat.R.id.action_bar), 2), 0), isDisplayed())) |
| 326 | + .perform(click()) |
| 327 | + |
| 328 | + TestUtil.delay(2) |
| 329 | + |
| 330 | + onView(allOf(withText("Developer settings"), |
| 331 | + withParent(allOf(withId(androidx.appcompat.R.id.action_bar), |
| 332 | + withParent(withId(androidx.appcompat.R.id.action_bar_container)))), isDisplayed())) |
| 333 | + .check(ViewAssertions.matches(withText("Developer settings"))) |
| 334 | + |
| 335 | + TestUtil.delay(2) |
| 336 | + } |
| 337 | + |
| 338 | + private fun goToTop() { |
| 339 | + onView(allOf(withId(R.id.feed_view))).perform(RecyclerViewActions.scrollToPosition<RecyclerView.ViewHolder>(0)) |
| 340 | + TestUtil.delay(2) |
| 341 | + } |
| 342 | +} |
0 commit comments