1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 package org.mozilla.fenix.ui.robots
7 import androidx.test.espresso.Espresso
8 import androidx.test.espresso.Espresso.onView
9 import androidx.test.espresso.action.ViewActions
10 import androidx.test.espresso.assertion.ViewAssertions
11 import androidx.test.espresso.assertion.ViewAssertions.matches
12 import androidx.test.espresso.matcher.ViewMatchers
13 import androidx.test.espresso.matcher.ViewMatchers.isDisplayed
14 import androidx.test.espresso.matcher.ViewMatchers.withId
15 import androidx.test.espresso.matcher.ViewMatchers.withParent
16 import androidx.test.espresso.matcher.ViewMatchers.withText
17 import androidx.test.platform.app.InstrumentationRegistry
18 import androidx.test.uiautomator.UiDevice
19 import org.hamcrest.CoreMatchers
20 import org.hamcrest.Matchers.allOf
21 import org.mozilla.fenix.R
22 import org.mozilla.fenix.helpers.click
25 * Implementation of Robot Pattern for the settings turn on sync option.
27 class SettingsTurnOnSyncRobot {
28 fun verifyUseEmailOption() = assertUseEmailField()
30 fun verifyReadyToScanOption() = assertReadyToScan()
32 fun tapOnUseEmailToSignIn() = useEmailButton().click()
34 fun verifyTurnOnSyncToolbarTitle() = assertTurnOnSyncToolbarTitle()
37 val mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())
39 fun goBack(interact: SettingsSubMenuLoginsAndPasswordRobot.() -> Unit): SettingsSubMenuLoginsAndPasswordRobot.Transition {
40 goBackButton().perform(ViewActions.click())
42 SettingsSubMenuLoginsAndPasswordRobot().interact()
43 return SettingsSubMenuLoginsAndPasswordRobot.Transition()
48 private fun goBackButton() =
49 Espresso.onView(CoreMatchers.allOf(ViewMatchers.withContentDescription("Navigate up")))
51 private fun assertUseEmailField() = Espresso.onView(ViewMatchers.withText("Use email instead"))
52 .check(ViewAssertions.matches(ViewMatchers.withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)))
54 private fun assertReadyToScan() = Espresso.onView(ViewMatchers.withText("Ready to scan"))
55 .check(ViewAssertions.matches(ViewMatchers.withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)))
57 private fun useEmailButton() = Espresso.onView(ViewMatchers.withText("Use email instead"))
59 private fun assertTurnOnSyncToolbarTitle() =
62 withParent(withId(R.id.navigationToolbar)),
63 withText("Turn on Sync")
65 ).check(matches(isDisplayed()))