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 and added collection tests
Browse files Browse the repository at this point in the history
some code cleanup
  • Loading branch information
Oana Horvath committed May 11, 2020
1 parent bac23b9 commit f2c191d
Show file tree
Hide file tree
Showing 4 changed files with 452 additions and 70 deletions.
248 changes: 227 additions & 21 deletions app/src/androidTest/java/org/mozilla/fenix/ui/CollectionTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ import androidx.test.uiautomator.By
import androidx.test.uiautomator.UiDevice
import androidx.test.uiautomator.Until
import okhttp3.mockwebserver.MockWebServer
import org.junit.Before
import org.junit.After
import org.junit.Test
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.mozilla.fenix.helpers.AndroidAssetDispatcher
import org.mozilla.fenix.helpers.HomeActivityTestRule
import org.mozilla.fenix.helpers.TestAssetHelper
Expand All @@ -30,6 +30,8 @@ class CollectionTest {

private val mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())
private lateinit var mockWebServer: MockWebServer
private val firstCollectionName = "testcollection_1"
private val secondCollectionName = "testcollection_2"

@get:Rule
val activityTestRule = HomeActivityTestRule()
Expand All @@ -47,12 +49,43 @@ class CollectionTest {
mockWebServer.shutdown()
}

@Test
fun verifyCreateFirstCollectionFlowItems() {
val firstWebPage = TestAssetHelper.getGenericAsset(mockWebServer, 1)
val secondWebPage = TestAssetHelper.getGenericAsset(mockWebServer, 2)

navigationToolbar {
}.enterURLAndEnterToBrowser(firstWebPage.url) {
}.openHomeScreen {
}.openNavigationToolbar {
}.enterURLAndEnterToBrowser(secondWebPage.url) {
}.openHomeScreen {
clickSaveCollectionButton()
verifySelectTabsView()
selectAllTabsForCollection()
verifyTabsSelectedCounterText(2)
deselectAllTabsForCollection()
verifyTabsSelectedCounterText(0)
selectTabForCollection(firstWebPage.title)
verifyTabsSelectedCounterText(1)
selectAllTabsForCollection()
saveTabsSelectedForCollection()
verifyNameCollectionView()
verifyDefaultCollectionName("Collection 1")
typeCollectionName(firstCollectionName)
verifySnackBarText("Tabs saved!")
verifyExistingOpenTabs(firstWebPage.title)
verifyExistingOpenTabs(secondWebPage.title)
}
}

@Test
// open a webpage, and add currently opened tab to existing collection
fun addTabToCollectionTest() {
fun addTabToExistingCollectionTest() {
val firstWebPage = TestAssetHelper.getGenericAsset(mockWebServer, 1)
val secondWebPage = TestAssetHelper.getGenericAsset(mockWebServer, 2)

createCollectionFromTab("testcollection_1")
createCollection(firstCollectionName)

homeScreen {
verifyExistingTabList()
Expand All @@ -62,24 +95,59 @@ class CollectionTest {
verifyPageContent(secondWebPage.content)
}.openThreeDotMenu {
clickBrowserViewSaveCollectionButton()
}.selectExistingCollection("testcollection_1") {
}.selectExistingCollection(firstCollectionName) {
verifySnackBarText("Tab saved!")
}.openHomeScreen {
verifyExistingTabList()
expandCollection(firstCollectionName)
verifyItemInCollectionExists(firstWebPage.title)
verifyItemInCollectionExists(secondWebPage.title)
}
}

@Test
fun collectionMenuAddTabButtonTest() {
val secondWebPage = TestAssetHelper.getGenericAsset(mockWebServer, 2)

createCollection(firstCollectionName)

homeScreen {
closeTab()
// On homeview, expand the collection and open the first saved page
expandCollection("testcollection_1")
verifyItemInCollectionExists("Test_Page_1")
verifyItemInCollectionExists("Test_Page_2")
}.openNavigationToolbar {
}.enterURLAndEnterToBrowser(secondWebPage.url) {
}.openHomeScreen {
expandCollection(firstCollectionName)
clickCollectionThreeDotButton()
selectAddTabToCollection()
verifyTabsSelectedCounterText(1)
saveTabsSelectedForCollection()
verifySnackBarText("Tab saved!")
verifyItemInCollectionExists(secondWebPage.title)
}
}

@Test
fun collectionMenuOpenAllTabsTest() {
val firstWebPage = TestAssetHelper.getGenericAsset(mockWebServer, 1)

createCollection(firstCollectionName)

homeScreen {
closeTab()
expandCollection(firstCollectionName)
clickCollectionThreeDotButton()
selectOpenTabs()
verifyExistingOpenTabs(firstWebPage.title)
}
}

@Test
fun renameCollectionTest() {
createCollectionFromTab("testcollection_1")
createCollection(firstCollectionName)

homeScreen {
// On homeview, tap the 3-dot button to expand, select rename, rename collection
expandCollection(firstCollectionName)
clickCollectionThreeDotButton()
selectRenameCollection()
typeCollectionName("renamed_collection")
Expand All @@ -89,10 +157,10 @@ class CollectionTest {

@Test
fun deleteCollectionTest() {
createCollectionFromTab("testcollection_1")
createCollection(firstCollectionName)

homeScreen {
// Choose delete collection from homeview, and confirm
expandCollection(firstCollectionName)
clickCollectionThreeDotButton()
selectDeleteCollection()
confirmDeleteCollection()
Expand All @@ -102,30 +170,168 @@ class CollectionTest {

@Test
fun createCollectionFromTabTest() {
createCollectionFromTab("testcollection_1")
createCollectionFromTab("testcollection_2", false)
val firstWebPage = TestAssetHelper.getGenericAsset(mockWebServer, 1)

createCollection(firstCollectionName)
homeScreen {
// swipe to bottom until the collections are shown
verifyHomeScreen()
verifyExistingOpenTabs(firstWebPage.title)
try {
verifyCollectionIsDisplayed("testcollection_1")
verifyCollectionIsDisplayed(firstCollectionName)
} catch (e: NoMatchingViewException) {
scrollToElementByText("testcollection_1")
scrollToElementByText(firstCollectionName)
}
verifyCollectionIsDisplayed("testcollection_2")
}
}

private fun createCollectionFromTab(collectionName: String, firstCollection: Boolean = true) {
@Test
fun verifyExpandedCollectionItemsTest() {
val firstWebPage = TestAssetHelper.getGenericAsset(mockWebServer, 1)

createCollection(firstCollectionName)

homeScreen {
verifyCollectionIsDisplayed(firstCollectionName)
verifyCollectionIcon()
expandCollection(firstCollectionName)
verifyItemInCollectionExists(firstWebPage.title)
verifyCollectionItemLogo()
verifyCollectionItemUrl()
verifyShareCollectionButtonIsVisible(true)
verifyCollectionMenuIsVisible(true)
verifyCollectionItemRemoveButtonIsVisible(firstWebPage.title, true)
collapseCollection(firstCollectionName)
verifyItemInCollectionExists(firstWebPage.title, false)
verifyShareCollectionButtonIsVisible(false)
verifyCollectionMenuIsVisible(false)
verifyCollectionItemRemoveButtonIsVisible(firstWebPage.title, false)
}
}

@Test
fun shareCollectionTest() {
createCollection(firstCollectionName)
homeScreen {
expandCollection(firstCollectionName)
clickShareCollectionButton()
verifyShareTabsOverlay()
}
}

@Test
fun removeTabFromCollectionTest() {
val webPage = TestAssetHelper.getGenericAsset(mockWebServer, 1)

createCollection(firstCollectionName)
homeScreen {
closeTab()
expandCollection(firstCollectionName)
removeTabFromCollection(webPage.title)
verifyItemInCollectionExists(webPage.title, false)
}

createCollection(firstCollectionName)
homeScreen {
closeTab()
expandCollection(firstCollectionName)
swipeCollectionItemLeft(webPage.title)
verifyItemInCollectionExists(webPage.title, false)
}

createCollection(firstCollectionName)
homeScreen {
closeTab()
expandCollection(firstCollectionName)
swipeCollectionItemRight(webPage.title)
verifyItemInCollectionExists(webPage.title, false)
}
}

@Test
fun selectTabOnLongTapTest() {
val firstWebPage = TestAssetHelper.getGenericAsset(mockWebServer, 1)
val secondWebPage = TestAssetHelper.getGenericAsset(mockWebServer, 2)

navigationToolbar {
}.enterURLAndEnterToBrowser(firstWebPage.url) {
}.openHomeScreen {
}.openNavigationToolbar {
}.enterURLAndEnterToBrowser(secondWebPage.url) {
}.openHomeScreen {
longTapSelectTab(firstWebPage.title)
verifySelectTabsView()
verifyTabsSelectedCounterText(1)
selectTabForCollection(secondWebPage.title)
verifyTabsSelectedCounterText(2)
saveTabsSelectedForCollection()
typeCollectionName(firstCollectionName)
verifySnackBarText("Tabs saved!")
closeTabViaXButton(firstWebPage.title)
closeTabViaXButton(secondWebPage.title)
expandCollection(firstCollectionName)
verifyItemInCollectionExists(firstWebPage.title)
verifyItemInCollectionExists(secondWebPage.title)
}
}

@Test
fun tabsOverflowMenuSaveCollectionTest() {
val firstWebPage = TestAssetHelper.getGenericAsset(mockWebServer, 1)
val secondWebPage = TestAssetHelper.getGenericAsset(mockWebServer, 2)

navigationToolbar {
}.enterURLAndEnterToBrowser(firstWebPage.url) {
}.openHomeScreen {
}.openNavigationToolbar {
}.enterURLAndEnterToBrowser(secondWebPage.url) {
}.openHomeScreen {
}.openTabsListThreeDotMenu {
verifySaveCollection()
}.clickOpenTabsMenuSaveCollection {
verifySelectTabsView()
verifyTabsSelectedCounterText(0)
selectAllTabsForCollection()
verifyTabsSelectedCounterText(2)
saveTabsSelectedForCollection()
typeCollectionName(firstCollectionName)
closeTabViaXButton(firstWebPage.title)
closeTabViaXButton(secondWebPage.title)
expandCollection(firstCollectionName)
verifyItemInCollectionExists(firstWebPage.title)
verifyItemInCollectionExists(secondWebPage.title)
}
}

@Test
fun navigateBackInCollectionFlowTest() {
val secondWebPage = TestAssetHelper.getGenericAsset(mockWebServer, 2)

createCollection(firstCollectionName)
navigationToolbar {
}.enterURLAndEnterToBrowser(secondWebPage.url) {
}.openHomeScreen {
longTapSelectTab(secondWebPage.title)
verifySelectTabsView()
saveTabsSelectedForCollection()
verifySelectCollectionView()
clickAddNewCollection()
verifyNameCollectionView()
goBackCollectionFlow()
verifySelectCollectionView()
goBackCollectionFlow()
verifySelectTabsView()
goBackCollectionFlow()
verifyHomeComponent()
}
}

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

// Open a webpage and save to collection "testcollection_1"
navigationToolbar {
}.enterURLAndEnterToBrowser(firstWebPage.url) {
verifyPageContent(firstWebPage.content)
}.openThreeDotMenu {
// click save to collection menu item, type collection name
clickBrowserViewSaveCollectionButton()
if (!firstCollection)
clickAddNewCollection()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,13 +237,6 @@ class BrowserRobot {
menuSaveImage.click()
}

fun waitForCollectionSavedPopup() {
mDevice.wait(
Until.findObject(text("Tab saved!")),
waitingTime
)
}

fun createBookmark(url: Uri) {
navigationToolbar {
}.enterURLAndEnterToBrowser(url) {
Expand Down
Loading

0 comments on commit f2c191d

Please sign in to comment.