[Android] UI test: Playlist fragment

Shivansh Saini git at videolan.org
Mon Dec 16 17:52:53 CET 2019


vlc-android | branch: master | Shivansh Saini <shivanshs9 at gmail.com> | Thu Aug  8 07:03:07 2019 +0530| [f4ff7ef2d2474902fbd0be14269a78930ac49962] | committer: Geoffrey Métais

UI test: Playlist fragment

Signed-off-by: Shivansh Saini <shivanshs9 at gmail.com>

> https://code.videolan.org/videolan/vlc-android/commit/f4ff7ef2d2474902fbd0be14269a78930ac49962
---

 .../org/videolan/vlc/gui/PlaylistActivityUITest.kt |   5 +-
 .../org/videolan/vlc/gui/PlaylistFragmentUITest.kt | 122 +++++++++++++++++----
 2 files changed, 107 insertions(+), 20 deletions(-)

diff --git a/vlc-android/androidTest/org/videolan/vlc/gui/PlaylistActivityUITest.kt b/vlc-android/androidTest/org/videolan/vlc/gui/PlaylistActivityUITest.kt
index 49e570e22..af5cd3f6a 100644
--- a/vlc-android/androidTest/org/videolan/vlc/gui/PlaylistActivityUITest.kt
+++ b/vlc-android/androidTest/org/videolan/vlc/gui/PlaylistActivityUITest.kt
@@ -54,9 +54,12 @@ class PlaylistActivityUITest: BaseUITest() {
     }
 
     @Test
-    fun whenAtTestPlaylist_checkMediaList() {
+    fun whenAtTestPlaylist_checkMediaListAndPlayButton() {
         onView(withId(R.id.songs))
                 .check(matches(sizeOfAtLeast(1)))
+
+        onView(withId(R.id.fab))
+                .check(matches(isDisplayed()))
     }
 
     @Test
diff --git a/vlc-android/androidTest/org/videolan/vlc/gui/PlaylistFragmentUITest.kt b/vlc-android/androidTest/org/videolan/vlc/gui/PlaylistFragmentUITest.kt
index c5a156857..5c3587b2f 100644
--- a/vlc-android/androidTest/org/videolan/vlc/gui/PlaylistFragmentUITest.kt
+++ b/vlc-android/androidTest/org/videolan/vlc/gui/PlaylistFragmentUITest.kt
@@ -2,6 +2,7 @@ package org.videolan.vlc.gui
 
 import android.content.Intent
 import android.widget.EditText
+import androidx.test.espresso.Espresso
 import androidx.test.espresso.Espresso.*
 import androidx.test.espresso.action.ViewActions.*
 import androidx.test.espresso.assertion.ViewAssertions.*
@@ -13,7 +14,7 @@ import com.google.android.material.internal.NavigationMenuItemView
 import kotlinx.coroutines.ExperimentalCoroutinesApi
 import kotlinx.coroutines.ObsoleteCoroutinesApi
 import org.hamcrest.Matchers.*
-import org.junit.Assert.*
+import org.junit.After
 import org.junit.Before
 import org.junit.Rule
 import org.junit.Test
@@ -40,27 +41,18 @@ class PlaylistFragmentUITest: BaseUITest() {
         activity = activityTestRule.activity
     }
 
+    @After
+    fun resetData() {
+        AbstractMedialibrary.getInstance().playlists.map { it.delete() }
+    }
+
     private fun createDummyPlaylist() {
         val ml = AbstractMedialibrary.getInstance()
-        val pl = ml.createPlaylist("test")
+        val pl = ml.createPlaylist(DUMMY_PLAYLIST)
         pl.append(ml.getPagedVideos(AbstractMedialibrary.SORT_DEFAULT, false, 5, 0).map { it.id })
         pl.append(ml.getPagedAudio(AbstractMedialibrary.SORT_DEFAULT, false, 5, 0).map { it.id })
     }
 
-    @Test
-    fun whenAtRoot_checkAppbar() {
-        onView(withId(R.id.ml_menu_filter))
-                .check(matches(isDisplayed()))
-        onView(withId(R.id.ml_menu_sortby))
-                .check(matches(isDisplayed()))
-
-        openActionBarOverflowOrOptionsMenu(context)
-
-        onView(withText(R.string.refresh))
-                .inRoot(isPlatformPopup())
-                .check(matches(isDisplayed()))
-    }
-
     @Test
     fun whenNoMedia_checkListEmpty() {
         onView(withId(R.id.audio_list))
@@ -109,13 +101,105 @@ class PlaylistFragmentUITest: BaseUITest() {
     @Test
     fun whenOnePlaylist_checkCardDetails() {
         createDummyPlaylist()
-        Thread.sleep(1500)
+        Thread.sleep(2000)
 
         onView(withId(R.id.audio_list))
-                .check(matches(withCount(equalTo(1))))
+                .check(matches(sizeOfAtLeast(1)))
+
+        // Section Header should be T
+//        onView(withId(R.id.section_header))
+//                .check(matches(withText(DUMMY_PLAYLIST[0].toString().toUpperCase())))
 
         val rvMatcher = withRecyclerView(R.id.audio_list)
         onView(rvMatcher.atPositionOnView(0, R.id.title))
-                .check(matches(withText("test")))
+                .check(matches(withText(DUMMY_PLAYLIST)))
+
+        onView(rvMatcher.atPositionOnView(0, R.id.subtitle))
+                .check(matches(withText("1 tracks")))
+    }
+
+    @Test
+    fun whenOnePlaylist_checkContextMenuWorks() {
+        createDummyPlaylist()
+        Thread.sleep(1500)
+
+        onView(withId(R.id.audio_list))
+                .check(matches(sizeOfAtLeast(1)))
+
+        val rvMatcher = withRecyclerView(R.id.audio_list)
+        onView(rvMatcher.atPositionOnView(0, R.id.item_more))
+                .perform(click())
+
+        assertThat(activity.supportFragmentManager.findFragmentByTag("context"), notNullValue())
+
+        onView(withId(R.id.ctx_list))
+                .check(matches(isDisplayed()))
+                .check(matches(sizeOfAtLeast(5)))
+                .check(matches(hasDescendant(withText(R.string.play))))
+                .check(matches(hasDescendant(withText(R.string.append))))
+                .check(matches(hasDescendant(withText(R.string.insert_next))))
+                .check(matches(hasDescendant(withText(R.string.add_to_playlist))))
+                .check(matches(hasDescendant(withText(R.string.delete))))
+    }
+
+    @Test
+    fun whenOnePlaylist_checkLongPressWorks() {
+        createDummyPlaylist()
+        Thread.sleep(1500)
+
+        onView(withId(R.id.audio_list))
+                .check(matches(sizeOfAtLeast(1)))
+
+        val rvMatcher = withRecyclerView(R.id.audio_list)
+        onView(rvMatcher.atPosition(0))
+                .perform(longClick())
+
+        onView(withId(R.id.action_mode_audio_play))
+                .check(matches(isDisplayed()))
+        onView(withId(R.id.action_mode_audio_info))
+                .check(matches(isDisplayed()))
+    }
+
+    @Test
+    fun whenAtRoot_checkAppbarWorks() {
+        onView(withId(R.id.ml_menu_filter))
+                .check(matches(isDisplayed()))
+
+        // Check sort works
+        onView(withId(R.id.ml_menu_sortby))
+                .check(matches(isDisplayed()))
+                .perform(click())
+
+        onView(anyOf(withText(R.string.sortby_name), withId(R.id.ml_menu_sortby_name)))
+                .inRoot(isPlatformPopup())
+                .check(matches(isDisplayed()))
+
+        Espresso.pressBack()
+
+        // Check overflow menu works
+        openActionBarOverflowOrOptionsMenu(context)
+
+        onView(withText(R.string.refresh))
+                .inRoot(isPlatformPopup())
+                .check(matches(isDisplayed()))
+
+        Espresso.pressBack()
+
+        // Check search shows
+        onView(withId(R.id.ml_menu_filter))
+                .perform(click())
+
+        Espresso.pressBack()
+        Espresso.pressBack()
+
+        // Check everything is reset
+        onView(withId(R.id.ml_menu_filter))
+                .check(matches(isDisplayed()))
+        onView(withId(R.id.ml_menu_sortby))
+                .check(matches(isDisplayed()))
+    }
+
+    companion object {
+        val DUMMY_PLAYLIST = "test"
     }
 }
\ No newline at end of file



More information about the Android mailing list