mirror of
https://github.com/fork-maintainers/iceraven-browser
synced 2024-11-03 23:15:31 +00:00
Bug 1819727 - Create basic nimbus message UI test (#1057)
* Bug 1819727 - Create basic nimbus message UI test * Fix linting errors. * Bug 1819727 - Updates based on review. * Bug 1819727 - Added license and test file notes. * Bug 1819727 - Fix lint errors. --------- Co-authored-by: Ryan VanderMeulen <rvandermeulen@mozilla.com> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
This commit is contained in:
parent
63320e4fd6
commit
862d8aa02d
@ -0,0 +1,120 @@
|
||||
/* 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/. */
|
||||
|
||||
package org.mozilla.fenix.ui
|
||||
|
||||
import android.content.Intent
|
||||
import androidx.test.platform.app.InstrumentationRegistry
|
||||
import androidx.test.uiautomator.UiDevice
|
||||
import okhttp3.mockwebserver.MockWebServer
|
||||
import org.junit.After
|
||||
import org.junit.Before
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import org.mozilla.experiments.nimbus.Res
|
||||
import org.mozilla.fenix.FenixApplication
|
||||
import org.mozilla.fenix.helpers.AndroidAssetDispatcher
|
||||
import org.mozilla.fenix.helpers.HomeActivityIntentTestRule
|
||||
import org.mozilla.fenix.helpers.RetryTestRule
|
||||
import org.mozilla.fenix.nimbus.FxNimbus
|
||||
import org.mozilla.fenix.nimbus.HomeScreenSection
|
||||
import org.mozilla.fenix.nimbus.Homescreen
|
||||
import org.mozilla.fenix.nimbus.MessageData
|
||||
import org.mozilla.fenix.nimbus.Messaging
|
||||
import org.mozilla.fenix.nimbus.StyleData
|
||||
import org.mozilla.fenix.ui.robots.homeScreen
|
||||
|
||||
/**
|
||||
* Tests for verifying basic functionality of the Nimbus Home Screen message
|
||||
*
|
||||
* Verifies a message can be displayed with all of the correct components
|
||||
**/
|
||||
|
||||
class NimbusMessagingHomescreenTest {
|
||||
private lateinit var mDevice: UiDevice
|
||||
private lateinit var mockWebServer: MockWebServer
|
||||
|
||||
private var messageButtonLabel = "CLICK ME"
|
||||
private var messageText = "Some Nimbus Messaging text"
|
||||
private var messageTitle = "A Nimbus title"
|
||||
|
||||
@get:Rule
|
||||
val homeActivityTestRule = HomeActivityIntentTestRule.withDefaultSettingsOverrides(
|
||||
skipOnboarding = true,
|
||||
).withIntent(
|
||||
Intent().apply {
|
||||
action = Intent.ACTION_VIEW
|
||||
},
|
||||
)
|
||||
|
||||
@Rule
|
||||
@JvmField
|
||||
val retryTestRule = RetryTestRule(3)
|
||||
|
||||
@Before
|
||||
fun setUp() {
|
||||
// Set up nimbus message
|
||||
FxNimbus.features.messaging.withInitializer {
|
||||
// FML generated objects.
|
||||
Messaging(
|
||||
messages = mapOf(
|
||||
"test-message" to MessageData(
|
||||
action = Res.string("TEST ACTION"),
|
||||
style = "TEST STYLE",
|
||||
buttonLabel = Res.string(messageButtonLabel),
|
||||
text = Res.string(messageText),
|
||||
title = Res.string(messageTitle),
|
||||
trigger = listOf("ALWAYS"),
|
||||
),
|
||||
),
|
||||
styles = mapOf(
|
||||
"TEST STYLE" to StyleData(),
|
||||
),
|
||||
actions = mapOf(
|
||||
"TEST ACTION" to "https://example.com",
|
||||
),
|
||||
triggers = mapOf(
|
||||
"ALWAYS" to "true",
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
// Remove some homescreen features not needed for testing
|
||||
FxNimbus.features.homescreen.withInitializer {
|
||||
// These are FML generated objects and enums
|
||||
Homescreen(
|
||||
sectionsEnabled = mapOf(
|
||||
HomeScreenSection.JUMP_BACK_IN to false,
|
||||
HomeScreenSection.POCKET to false,
|
||||
HomeScreenSection.POCKET_SPONSORED_STORIES to false,
|
||||
HomeScreenSection.RECENT_EXPLORATIONS to false,
|
||||
HomeScreenSection.RECENTLY_SAVED to false,
|
||||
HomeScreenSection.TOP_SITES to false,
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())
|
||||
mockWebServer = MockWebServer().apply {
|
||||
dispatcher = AndroidAssetDispatcher()
|
||||
start()
|
||||
}
|
||||
// refresh message store
|
||||
val application = (homeActivityTestRule.activity.application as FenixApplication)
|
||||
application.restoreMessaging()
|
||||
}
|
||||
|
||||
@After
|
||||
fun tearDown() {
|
||||
mockWebServer.shutdown()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testNimbusMessageIsDisplayed() {
|
||||
// Checks the home screen card message is displayed correctly
|
||||
homeScreen {
|
||||
verifyNimbusMessageCard(messageTitle, messageText, messageButtonLabel)
|
||||
}
|
||||
}
|
||||
}
|
@ -7,7 +7,10 @@
|
||||
package org.mozilla.fenix.ui.robots
|
||||
|
||||
import android.graphics.Bitmap
|
||||
import android.view.View
|
||||
import android.widget.EditText
|
||||
import android.widget.TextView
|
||||
import androidx.compose.ui.platform.ComposeView
|
||||
import androidx.compose.ui.test.assert
|
||||
import androidx.compose.ui.test.assertIsDisplayed
|
||||
import androidx.compose.ui.test.assertIsNotSelected
|
||||
@ -519,6 +522,21 @@ class HomeScreenRobot {
|
||||
},
|
||||
)
|
||||
}
|
||||
fun verifyNimbusMessageCard(title: String, text: String, action: String) {
|
||||
val textView = UiSelector()
|
||||
.className(ComposeView::class.java)
|
||||
.className(View::class.java)
|
||||
.className(TextView::class.java)
|
||||
assertTrue(
|
||||
mDevice.findObject(textView.textContains(title)).waitForExists(waitingTime),
|
||||
)
|
||||
assertTrue(
|
||||
mDevice.findObject(textView.textContains(text)).waitForExists(waitingTime),
|
||||
)
|
||||
assertTrue(
|
||||
mDevice.findObject(textView.textContains(action)).waitForExists(waitingTime),
|
||||
)
|
||||
}
|
||||
|
||||
class Transition {
|
||||
|
||||
|
@ -510,7 +510,8 @@ open class FenixApplication : LocaleAwareApplication(), Provider {
|
||||
}
|
||||
}
|
||||
|
||||
private fun restoreMessaging() {
|
||||
@VisibleForTesting
|
||||
internal fun restoreMessaging() {
|
||||
if (settings().isExperimentationEnabled) {
|
||||
components.appStore.dispatch(AppAction.MessagingAction.Restore)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user