68 lines
2.5 KiB
Kotlin
68 lines
2.5 KiB
Kotlin
|
/* 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
|
||
|
import androidx.test.espresso.assertion.ViewAssertions
|
||
|
import androidx.test.espresso.matcher.ViewMatchers
|
||
|
import androidx.test.espresso.matcher.ViewMatchers.withText
|
||
|
import androidx.test.platform.app.InstrumentationRegistry
|
||
|
import androidx.test.uiautomator.UiDevice
|
||
|
import org.hamcrest.Matchers.allOf
|
||
|
import org.mozilla.fenix.R
|
||
|
import org.mozilla.fenix.helpers.click
|
||
|
|
||
|
/**
|
||
|
* Implementation of Robot Pattern for the three dot (main) menu.
|
||
|
*/
|
||
|
class ThreeDotMenuRobot {
|
||
|
fun verifySettingsButton() = assertSettingsButton()
|
||
|
fun verifyLibraryButton() = assertLibraryButton()
|
||
|
fun verifyHelpButton() = assertHelpButton()
|
||
|
|
||
|
class Transition {
|
||
|
|
||
|
val mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())
|
||
|
|
||
|
fun openSettings(interact: SettingsRobot.() -> Unit): SettingsRobot.Transition {
|
||
|
mDevice.waitForIdle()
|
||
|
settingsButton().click()
|
||
|
|
||
|
SettingsRobot().interact()
|
||
|
return SettingsRobot.Transition()
|
||
|
}
|
||
|
|
||
|
fun openLibrary(interact: LibraryRobot.() -> Unit): LibraryRobot.Transition {
|
||
|
mDevice.waitForIdle()
|
||
|
libraryButton().click()
|
||
|
|
||
|
LibraryRobot().interact()
|
||
|
return LibraryRobot.Transition()
|
||
|
}
|
||
|
|
||
|
fun openHelp(interact: BrowserRobot.() -> Unit): BrowserRobot.Transition {
|
||
|
mDevice.waitForIdle()
|
||
|
helpButton().click()
|
||
|
|
||
|
BrowserRobot().interact()
|
||
|
return BrowserRobot.Transition()
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
private fun settingsButton() = onView(allOf(withText("Settings")))
|
||
|
private fun assertSettingsButton() = settingsButton()
|
||
|
.check(ViewAssertions.matches(ViewMatchers.withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)))
|
||
|
|
||
|
private fun libraryButton() = onView(allOf(withText(R.string.browser_menu_your_library)))
|
||
|
private fun assertLibraryButton() = libraryButton()
|
||
|
.check(ViewAssertions.matches(ViewMatchers.withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)))
|
||
|
|
||
|
private fun helpButton() = onView(allOf(withText(R.string.browser_menu_help)))
|
||
|
private fun assertHelpButton() = helpButton()
|
||
|
.check(ViewAssertions.matches(ViewMatchers.withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)))
|