2019-04-10 18:59:38 +02:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
@file:Suppress("TooManyFunctions")
|
|
|
|
|
|
|
|
package org.mozilla.fenix.ui.robots
|
|
|
|
|
|
|
|
import androidx.test.espresso.Espresso.onView
|
2019-05-16 02:32:25 +02:00
|
|
|
import androidx.test.espresso.action.ViewActions.click
|
2019-04-10 18:59:38 +02:00
|
|
|
import androidx.test.espresso.assertion.ViewAssertions.matches
|
|
|
|
import androidx.test.espresso.matcher.ViewMatchers
|
|
|
|
import androidx.test.espresso.matcher.ViewMatchers.Visibility
|
2019-05-16 02:32:25 +02:00
|
|
|
import androidx.test.espresso.matcher.ViewMatchers.withEffectiveVisibility
|
|
|
|
import androidx.test.platform.app.InstrumentationRegistry
|
|
|
|
import androidx.test.uiautomator.UiDevice
|
|
|
|
import org.hamcrest.Matchers.allOf
|
|
|
|
import org.mozilla.fenix.R
|
2019-04-10 18:59:38 +02:00
|
|
|
|
2019-05-16 02:32:25 +02:00
|
|
|
/**
|
|
|
|
* Implementation of Robot Pattern for the home screen menu.
|
|
|
|
*/
|
2019-04-10 18:59:38 +02:00
|
|
|
class HomeScreenRobot {
|
2019-05-16 02:32:25 +02:00
|
|
|
fun verifyHomeScreen() = assertHomeScreen()
|
|
|
|
fun verifyHomePrivateBrowsingButton() = assertHomePrivateBrowsingButton()
|
|
|
|
fun verifyHomeMenu() = assertHomeMenu()
|
|
|
|
fun verifyHomeWordmark() = assertHomeWordmark()
|
|
|
|
fun verifyHomeToolbar() = assertHomeToolbar()
|
|
|
|
fun verifyHomeComponent() = assertHomeComponent()
|
|
|
|
|
|
|
|
class Transition {
|
|
|
|
|
|
|
|
val mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())
|
|
|
|
|
|
|
|
fun openThreeDotMenu(interact: ThreeDotMenuRobot.() -> Unit): ThreeDotMenuRobot.Transition {
|
|
|
|
|
|
|
|
mDevice.waitForIdle()
|
|
|
|
threeDotButton().perform(click())
|
|
|
|
|
|
|
|
ThreeDotMenuRobot().interact()
|
|
|
|
return ThreeDotMenuRobot.Transition()
|
|
|
|
}
|
|
|
|
}
|
2019-04-10 18:59:38 +02:00
|
|
|
}
|
|
|
|
|
2019-05-16 02:32:25 +02:00
|
|
|
fun homeScreen(interact: HomeScreenRobot.() -> Unit): HomeScreenRobot.Transition {
|
2019-04-10 18:59:38 +02:00
|
|
|
HomeScreenRobot().interact()
|
2019-05-16 02:32:25 +02:00
|
|
|
return HomeScreenRobot.Transition()
|
2019-04-10 18:59:38 +02:00
|
|
|
}
|
|
|
|
|
2019-05-16 02:32:25 +02:00
|
|
|
private fun assertHomeScreen() = onView(ViewMatchers.withResourceName("homeLayout"))
|
2019-04-10 18:59:38 +02:00
|
|
|
.check(matches(withEffectiveVisibility(Visibility.VISIBLE)))
|
2019-05-16 02:32:25 +02:00
|
|
|
private fun assertHomeMenu() = onView(ViewMatchers.withResourceName("menuButton"))
|
2019-04-10 18:59:38 +02:00
|
|
|
.check(matches(withEffectiveVisibility(Visibility.VISIBLE)))
|
2019-05-16 02:32:25 +02:00
|
|
|
private fun assertHomePrivateBrowsingButton() = onView(ViewMatchers.withResourceName("privateBrowsingButton"))
|
2019-04-10 18:59:38 +02:00
|
|
|
.check(matches(withEffectiveVisibility(Visibility.VISIBLE)))
|
2019-05-16 02:32:25 +02:00
|
|
|
private fun assertHomeWordmark() = onView(ViewMatchers.withResourceName("wordmark"))
|
2019-04-10 18:59:38 +02:00
|
|
|
.check(matches(withEffectiveVisibility(Visibility.VISIBLE)))
|
2019-05-16 02:32:25 +02:00
|
|
|
private fun assertHomeToolbar() = onView(ViewMatchers.withResourceName("toolbar"))
|
2019-04-10 18:59:38 +02:00
|
|
|
.check(matches(withEffectiveVisibility(Visibility.VISIBLE)))
|
2019-05-16 02:32:25 +02:00
|
|
|
private fun assertHomeComponent() = onView(ViewMatchers.withResourceName("home_component"))
|
2019-04-10 18:59:38 +02:00
|
|
|
.check(matches(withEffectiveVisibility(Visibility.VISIBLE)))
|
2019-05-16 02:32:25 +02:00
|
|
|
|
|
|
|
private fun threeDotButton() = onView(allOf(ViewMatchers.withId(R.id.menuButton)))
|