Skip to content
This repository has been archived by the owner on Feb 20, 2023. It is now read-only.

Commit

Permalink
for #9407: fixed old collection tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Oana Horvath committed May 11, 2020
1 parent 55a8bf7 commit bac23b9
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 105 deletions.
137 changes: 32 additions & 105 deletions app/src/androidTest/java/org/mozilla/fenix/ui/CollectionTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,19 @@

package org.mozilla.fenix.ui

import android.net.Uri
import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.NoMatchingViewException
import androidx.test.espresso.assertion.ViewAssertions
import androidx.test.espresso.matcher.ViewMatchers
import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.uiautomator.By
import androidx.test.uiautomator.UiDevice
import androidx.test.uiautomator.Until
import okhttp3.mockwebserver.MockWebServer
import org.junit.Ignore
import org.junit.Before
import org.junit.After
import org.junit.Test
import org.junit.Rule
import org.mozilla.fenix.R
import org.mozilla.fenix.helpers.AndroidAssetDispatcher
import org.mozilla.fenix.helpers.HomeActivityTestRule
import org.mozilla.fenix.helpers.TestAssetHelper
import org.mozilla.fenix.helpers.click
import org.mozilla.fenix.ui.robots.browserScreen
import org.mozilla.fenix.ui.robots.homeScreen
import org.mozilla.fenix.ui.robots.navigationToolbar

Expand All @@ -35,6 +27,7 @@ import org.mozilla.fenix.ui.robots.navigationToolbar

class CollectionTest {
/* ktlint-disable no-blank-line-before-rbrace */ // This imposes unreadable grouping.

private val mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())
private lateinit var mockWebServer: MockWebServer

Expand All @@ -55,161 +48,95 @@ class CollectionTest {
}

@Test
@Ignore("Temp disable test - see: https://github.com/mozilla-mobile/fenix/issues/5793")
// open a webpage, and add currently opened tab to existing collection
fun addTabToCollectionTest() {
val firstWebPage = TestAssetHelper.getGenericAsset(mockWebServer, 1)
val secondWebPage = TestAssetHelper.getGenericAsset(mockWebServer, 2)

createCollection(firstWebPage.url, "testcollection_1")
createCollectionFromTab("testcollection_1")

// Close the open tab
homeScreen {
verifyHomeScreen()
}
onView(ViewMatchers.withId(R.id.close_tab_button)).click()

// On homeview, open another webpage
navigationToolbar {
verifyExistingTabList()
closeTab()
}.openNavigationToolbar {
}.enterURLAndEnterToBrowser(secondWebPage.url) {
verifyPageContent(secondWebPage.content)
}

// Save the current page to the testcollection_1
navigationToolbar {
}.openThreeDotMenu {
// click save to collection menu item, type collection name
clickBrowserViewSaveCollectionButton()
org.mozilla.fenix.ui.robots.mDevice.wait(
Until.findObject(By.text("testcollection_1")),
TestAssetHelper.waitingTime)
onView(ViewMatchers.withText("testcollection_1")).click()
mDevice.pressBack() // go to main page
}

// close currently opened tab
homeScreen {
verifyHomeScreen()
onView(ViewMatchers.withId(R.id.close_tab_button)).click()
org.mozilla.fenix.ui.robots.mDevice.wait(
Until.findObject(By.text("testcollection_1")),
TestAssetHelper.waitingTime)
// On homeview, expand the collection and open the first saved page
onView(ViewMatchers.withText("testcollection_1")).click()
onView(ViewMatchers.withText("Test_Page_1")).click()
}
// Page content: 1
browserScreen {
verifyPageContent("Page content: 1")
mDevice.pressBack() // go to main page
}

// tab_in_collection_item
homeScreen {
verifyHomeScreen()
onView(ViewMatchers.withId(R.id.close_tab_button)).click()
}.selectExistingCollection("testcollection_1") {
verifySnackBarText("Tab saved!")
}.openHomeScreen {
verifyExistingTabList()
closeTab()
// On homeview, expand the collection and open the first saved page
org.mozilla.fenix.ui.robots.mDevice.wait(
Until.findObject(By.text("Test_Page_2")),
TestAssetHelper.waitingTime)
onView(ViewMatchers.withText("Test_Page_2")).click()
}

// Page content: 2
browserScreen {
verifyPageContent("Page content: 2")
expandCollection("testcollection_1")
verifyItemInCollectionExists("Test_Page_1")
verifyItemInCollectionExists("Test_Page_2")
}
}

@Test
@Ignore("Temp disable test - see: https://github.com/mozilla-mobile/fenix/issues/5793")
// Rename Collection from the Homescreen
fun renameCollectionTest() {

val firstWebPage = TestAssetHelper.getGenericAsset(mockWebServer, 1)

createCollection(firstWebPage.url, "testcollection_1")
createCollectionFromTab("testcollection_1")

homeScreen {
// On homeview, tap the 3-dot button to expand, select rename, rename collection
clickCollectionThreeDotButton()
selectRenameCollection()
typeCollectionName("renamed_collection")
mDevice.wait(Until.findObject(By.text("renamed_collection")), TestAssetHelper.waitingTime)
// Verify the new name is displayed on homeview
onView(ViewMatchers.withText("renamed_collection"))
.check(ViewAssertions
.matches(ViewMatchers.withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)))
verifyCollectionIsDisplayed("renamed_collection")
}
}

@Test
@Ignore("Temp disable test - see: https://github.com/mozilla-mobile/fenix/issues/5793")
// Delete Collection from the Homescreen
fun deleteCollectionTest() {

val firstWebPage = TestAssetHelper.getGenericAsset(mockWebServer, 1)

createCollection(firstWebPage.url, "testcollection_1")
createCollectionFromTab("testcollection_1")

homeScreen {
// Choose delete collection from homeview, and confirm
clickCollectionThreeDotButton()
selectDeleteCollection()
confirmDeleteCollection()

// Check for No collections caption
onView(ViewMatchers.withText("No collections"))
.check(ViewAssertions
.matches(ViewMatchers.withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)))
verifyNoCollectionsHeader()
}
}

@Test
@Ignore("Temp disable test - see: https://github.com/mozilla-mobile/fenix/issues/5793")
fun createCollectionTest() {
val firstWebPage = TestAssetHelper.getGenericAsset(mockWebServer, 1)
val secondWebPage = TestAssetHelper.getGenericAsset(mockWebServer, 2)

createCollection(firstWebPage.url, "testcollection_1")
createCollection(secondWebPage.url, "testcollection_2", false)
fun createCollectionFromTabTest() {
createCollectionFromTab("testcollection_1")
createCollectionFromTab("testcollection_2", false)

// On the main screen, swipe to bottom until the collections are shown
homeScreen {
// swipe to bottom until the collections are shown
verifyHomeScreen()
try {
onView(ViewMatchers.withText("testcollection_1"))
.check(ViewAssertions
.matches(ViewMatchers.withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)))
verifyCollectionIsDisplayed("testcollection_1")
} catch (e: NoMatchingViewException) {
scrollToElementByText("testcollection_1")
}
onView(ViewMatchers.withText("testcollection_2")).check(ViewAssertions
.matches(ViewMatchers.withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)))
verifyCollectionIsDisplayed("testcollection_2")
}
}

private fun createCollection(url: Uri, collectionName: String, firstCollection: Boolean = true) {
private fun createCollectionFromTab(collectionName: String, firstCollection: Boolean = true) {
val firstWebPage = TestAssetHelper.getGenericAsset(mockWebServer, 1)

// Open a webpage and save to collection "testcollection_1"
navigationToolbar {
}.enterURLAndEnterToBrowser(url) {
}.enterURLAndEnterToBrowser(firstWebPage.url) {
verifyPageContent(firstWebPage.content)
}
navigationToolbar {
}.openThreeDotMenu {
// click save to collection menu item, type collection name
clickBrowserViewSaveCollectionButton()
if (!firstCollection)
clickAddNewCollection()

}.typeCollectionName(collectionName) {}

mDevice.pressBack() // go to main page
org.mozilla.fenix.ui.robots.mDevice.wait(
Until.findObject(By.text(collectionName)),
TestAssetHelper.waitingTime)
}.typeCollectionName(collectionName) {
verifySnackBarText("Tab saved!")
}.openHomeScreen {
mDevice.wait(
Until.findObject(By.text(collectionName)),
TestAssetHelper.waitingTime
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,17 @@ class HomeScreenRobot {
collectionNameTextField().perform(ViewActions.pressImeActionButton())
}

fun verifyCollectionIsDisplayed(title: String) {
mDevice.wait(findObject(text("renamed_collection")), waitingTime)
collectionTitle(title).check(matches(isDisplayed()))
}

fun expandCollection(title: String) = collectionTitle(title).click()

fun verifyItemInCollectionExists(title: String) =
onView(allOf(withId(R.id.list_element_title), withText(title)))
.check(matches(isDisplayed()))

fun scrollToElementByText(text: String): UiScrollable {
val appView = UiScrollable(UiSelector().scrollable(true))
appView.scrollTextIntoView(text)
Expand Down Expand Up @@ -597,6 +608,9 @@ private fun collectionThreeDotButton() =
private fun collectionNameTextField() =
onView(allOf(ViewMatchers.withResourceName("name_collection_edittext")))

private fun collectionTitle(title: String) =
onView(allOf(withId(R.id.collection_title), withText(title)))

private fun closeTabViaX(title: String) {
val closeButton = onView(
allOf(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@ import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.uiautomator.By
import androidx.test.uiautomator.UiDevice
import androidx.test.uiautomator.Until
import org.hamcrest.CoreMatchers
import org.hamcrest.Matchers.allOf
import org.mozilla.fenix.R
import org.mozilla.fenix.helpers.TestAssetHelper
import org.mozilla.fenix.helpers.TestAssetHelper.waitingTime
import org.mozilla.fenix.helpers.click
import org.mozilla.fenix.helpers.ext.waitNotNull
Expand Down Expand Up @@ -245,6 +247,16 @@ class ThreeDotMenuMainRobot {
AddToHomeScreenRobot().interact()
return AddToHomeScreenRobot.Transition()
}

fun selectExistingCollection(title: String, interact: BrowserRobot.() -> Unit): BrowserRobot.Transition {
org.mozilla.fenix.ui.robots.mDevice.wait(
Until.findObject(By.text("testcollection_1")),
waitingTime)
onView(withText(title)).click()

BrowserRobot().interact()
return BrowserRobot.Transition()
}
}
}

Expand Down Expand Up @@ -374,3 +386,4 @@ private fun assertAddToFirefoxHome() {
)
).check(matches(withEffectiveVisibility(Visibility.VISIBLE)))
}

0 comments on commit bac23b9

Please sign in to comment.