@ -4,12 +4,19 @@
package org.mozilla.fenix.onboarding.view
import io.mockk.every
import io.mockk.mockk
import mozilla.components.service.nimbus.evalJexlSafe
import org.junit.Assert.assertEquals
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.mozilla.experiments.nimbus.GleanPlumbMessageHelper
import org.mozilla.experiments.nimbus.StringHolder
import org.mozilla.fenix.R
import org.mozilla.fenix.helpers.HomeActivityIntentTestRule
import org.mozilla.fenix.nimbus.FxNimbus
import org.mozilla.fenix.nimbus.JunoOnboarding
import org.mozilla.fenix.nimbus.OnboardingCardData
import org.mozilla.fenix.nimbus.OnboardingCardType
@ -19,28 +26,242 @@ class JunoOnboardingMapperTest {
val activityTestRule =
HomeActivityIntentTestRule . withDefaultSettingsOverrides ( skipOnboarding = true )
private lateinit var junoOnboardingFeature : JunoOnboarding
private lateinit var jexlConditions : Map < String , String >
private lateinit var jexlHelper : GleanPlumbMessageHelper
private lateinit var evalFunction : ( String ) -> Boolean
@Before
fun setup ( ) {
junoOnboardingFeature = FxNimbus . features . junoOnboarding . value ( )
jexlConditions = junoOnboardingFeature . conditions
jexlHelper = mockk ( relaxed = true )
evalFunction = { condition -> jexlHelper . evalJexlSafe ( condition ) }
every { evalFunction ( " true " ) } returns true
every { evalFunction ( " false " ) } returns false
}
@Test
fun showNotificationTrue _showAddWidgetFalse _pagesToDisplay _returnsSortedListOfAllConvertedPages _withoutAddWidgetPage ( ) {
val expected = listOf ( defaultBrowserPageUiData , syncPageUiData , notificationPageUiData )
assertEquals ( expected , unsortedAllKnownCardData . toPageUiData ( true , false ) )
assertEquals (
expected ,
unsortedAllKnownCardData . toPageUiData (
showNotificationPage = true ,
showAddWidgetPage = false ,
jexlConditions = jexlConditions ,
func = evalFunction ,
) ,
)
}
@Test
fun showNotificationFalse _showAddWidgetFalse _pagesToDisplay _returnsSortedListOfConvertedPages _withoutNotificationPage _and _addWidgetPage ( ) {
val expected = listOf ( defaultBrowserPageUiData , syncPageUiData )
assertEquals ( expected , unsortedAllKnownCardData . toPageUiData ( false , false ) )
assertEquals (
expected ,
unsortedAllKnownCardData . toPageUiData (
showNotificationPage = false ,
showAddWidgetPage = false ,
jexlConditions = jexlConditions ,
func = evalFunction ,
) ,
)
}
@Test
fun showNotificationFalse _showAddWidgetTrue _pagesToDisplay _returnsSortedListOfAllConvertedPages _withoutNotificationPage ( ) {
val expected = listOf ( defaultBrowserPageUiData , addSearchWidgetPageUiData , syncPageUiData )
assertEquals ( expected , unsortedAllKnownCardData . toPageUiData ( false , true ) )
assertEquals (
expected ,
unsortedAllKnownCardData . toPageUiData (
showNotificationPage = false ,
showAddWidgetPage = true ,
jexlConditions = jexlConditions ,
func = evalFunction ,
) ,
)
}
@Test
fun showNotificationTrue _and _showAddWidgetTrue _pagesToDisplay _returnsSortedListOfConvertedPages ( ) {
val expected = listOf ( defaultBrowserPageUiData , addSearchWidgetPageUiData , syncPageUiData , notificationPageUiData )
assertEquals ( expected , unsortedAllKnownCardData . toPageUiData ( true , true ) )
val expected = listOf (
defaultBrowserPageUiData ,
addSearchWidgetPageUiData ,
syncPageUiData ,
notificationPageUiData ,
)
assertEquals (
expected ,
unsortedAllKnownCardData . toPageUiData (
showNotificationPage = true ,
showAddWidgetPage = true ,
jexlConditions = jexlConditions ,
func = evalFunction ,
) ,
)
}
@Test
fun cardConditionsMatchJexlConditions _shouldDisplayCard _returnsConvertedPage ( ) {
val jexlConditions = mapOf ( " ALWAYS " to " true " , " NEVER " to " false " )
val expected = listOf ( defaultBrowserPageUiData )
assertEquals (
expected ,
listOf ( defaultBrowserCardData ) . toPageUiData (
showNotificationPage = false ,
showAddWidgetPage = false ,
jexlConditions = jexlConditions ,
func = evalFunction ,
) ,
)
}
@Test
fun noJexlConditionsAndNoCardConditions _shouldDisplayCard _returnsNoPage ( ) {
val jexlConditions = mapOf < String , String > ( )
val expected = emptyList < OnboardingPageUiData > ( )
assertEquals (
expected ,
listOf ( addSearchWidgetCardDataNoConditions ) . toPageUiData (
showNotificationPage = false ,
showAddWidgetPage = false ,
jexlConditions = jexlConditions ,
func = evalFunction ,
) ,
)
}
@Test
fun noJexlConditions _shouldDisplayCard _returnsNoPage ( ) {
val jexlConditions = mapOf < String , String > ( )
val expected = emptyList < OnboardingPageUiData > ( )
assertEquals (
expected ,
listOf ( defaultBrowserCardData ) . toPageUiData (
showNotificationPage = false ,
showAddWidgetPage = false ,
jexlConditions = jexlConditions ,
func = evalFunction ,
) ,
)
}
@Test
fun prerequisitesMatchJexlConditions _shouldDisplayCard _returnsConvertedPage ( ) {
val jexlConditions = mapOf ( " ALWAYS " to " true " )
val expected = listOf ( defaultBrowserPageUiData )
assertEquals (
expected ,
listOf ( defaultBrowserCardData ) . toPageUiData (
showNotificationPage = false ,
showAddWidgetPage = false ,
jexlConditions = jexlConditions ,
func = evalFunction ,
) ,
)
}
@Test
fun prerequisitesDontMatchJexlConditions _shouldDisplayCard _returnsNoPage ( ) {
val jexlConditions = mapOf ( " NEVER " to " false " )
val expected = emptyList < OnboardingPageUiData > ( )
assertEquals (
expected ,
listOf ( defaultBrowserCardData ) . toPageUiData (
showNotificationPage = false ,
showAddWidgetPage = false ,
jexlConditions = jexlConditions ,
func = evalFunction ,
) ,
)
}
@Test
fun noCardConditions _shouldDisplayCard _returnsNoPage ( ) {
val jexlConditions = mapOf ( " ALWAYS " to " true " , " NEVER " to " false " )
val expected = emptyList < OnboardingPageUiData > ( )
assertEquals (
expected ,
listOf ( addSearchWidgetCardDataNoConditions ) . toPageUiData (
showNotificationPage = false ,
showAddWidgetPage = false ,
jexlConditions = jexlConditions ,
func = evalFunction ,
) ,
)
}
@Test
fun noDisqualifiers _shouldDisplayCard _returnsConvertedPage ( ) {
val jexlConditions = mapOf ( " ALWAYS " to " true " , " NEVER " to " false " )
val expected = listOf ( defaultBrowserPageUiData )
assertEquals (
expected ,
listOf ( defaultBrowserCardDataNoDisqualifiers ) . toPageUiData (
showNotificationPage = false ,
showAddWidgetPage = false ,
jexlConditions = jexlConditions ,
func = evalFunction ,
) ,
)
}
@Test
fun disqualifiersMatchJexlConditions _shouldDisplayCard _returnsConvertedPage ( ) {
val jexlConditions = mapOf ( " NEVER " to " false " )
val expected = listOf ( syncPageUiData )
assertEquals (
expected ,
listOf ( syncCardData ) . toPageUiData (
showNotificationPage = false ,
showAddWidgetPage = false ,
jexlConditions = jexlConditions ,
func = evalFunction ,
) ,
)
}
@Test
fun disqualifiersDontMatchJexlConditions _shouldDisplayCard _returnsNoPage ( ) {
val jexlConditions = mapOf ( " NEVER " to " false " )
val expected = listOf < OnboardingPageUiData > ( )
assertEquals (
expected ,
listOf ( notificationCardData ) . toPageUiData (
showNotificationPage = false ,
showAddWidgetPage = false ,
jexlConditions = jexlConditions ,
func = evalFunction ,
) ,
)
}
@Test
fun noPrerequisites _shouldDisplayCard _returnsConvertedPage ( ) {
val jexlConditions = mapOf ( " ALWAYS " to " true " , " NEVER " to " false " )
val expected = listOf ( syncPageUiData )
assertEquals (
expected ,
listOf ( syncCardData ) . toPageUiData (
showNotificationPage = false ,
showAddWidgetPage = false ,
jexlConditions = jexlConditions ,
func = evalFunction ,
) ,
)
}
}
@ -88,7 +309,36 @@ private val defaultBrowserCardData = OnboardingCardData(
primaryButtonLabel = StringHolder ( null , " default browser primary button text " ) ,
secondaryButtonLabel = StringHolder ( null , " default browser secondary button text " ) ,
ordering = 10 ,
prerequisites = listOf ( " ALWAYS " ) ,
disqualifiers = listOf ( " NEVER " ) ,
)
private val defaultBrowserCardDataNoDisqualifiers = OnboardingCardData (
cardType = OnboardingCardType . DEFAULT _BROWSER ,
imageRes = R . drawable . ic _onboarding _welcome ,
title = StringHolder ( null , " default browser title " ) ,
body = StringHolder ( null , " default browser body with link text " ) ,
linkText = StringHolder ( null , " link text " ) ,
primaryButtonLabel = StringHolder ( null , " default browser primary button text " ) ,
secondaryButtonLabel = StringHolder ( null , " default browser secondary button text " ) ,
ordering = 10 ,
prerequisites = listOf ( " ALWAYS " ) ,
disqualifiers = listOf ( ) ,
)
private val addSearchWidgetCardDataNoConditions = OnboardingCardData (
cardType = OnboardingCardType . ADD _SEARCH _WIDGET ,
imageRes = R . drawable . ic _onboarding _search _widget ,
title = StringHolder ( null , " add search widget title " ) ,
body = StringHolder ( null , " add search widget body with link text " ) ,
linkText = StringHolder ( null , " link text " ) ,
primaryButtonLabel = StringHolder ( null , " add search widget primary button text " ) ,
secondaryButtonLabel = StringHolder ( null , " add search widget secondary button text " ) ,
ordering = 15 ,
prerequisites = listOf ( ) ,
disqualifiers = listOf ( ) ,
)
private val addSearchWidgetCardData = OnboardingCardData (
cardType = OnboardingCardType . ADD _SEARCH _WIDGET ,
imageRes = R . drawable . ic _onboarding _search _widget ,
@ -99,6 +349,7 @@ private val addSearchWidgetCardData = OnboardingCardData(
secondaryButtonLabel = StringHolder ( null , " add search widget secondary button text " ) ,
ordering = 15 ,
)
private val syncCardData = OnboardingCardData (
cardType = OnboardingCardType . SYNC _SIGN _IN ,
imageRes = R . drawable . ic _onboarding _sync ,
@ -107,7 +358,10 @@ private val syncCardData = OnboardingCardData(
primaryButtonLabel = StringHolder ( null , " sync primary button text " ) ,
secondaryButtonLabel = StringHolder ( null , " sync secondary button text " ) ,
ordering = 20 ,
prerequisites = listOf ( ) ,
disqualifiers = listOf ( " NEVER " ) ,
)
private val notificationCardData = OnboardingCardData (
cardType = OnboardingCardType . NOTIFICATION _PERMISSION ,
imageRes = R . drawable . ic _notification _permission ,
@ -116,6 +370,8 @@ private val notificationCardData = OnboardingCardData(
primaryButtonLabel = StringHolder ( null , " notification primary button text " ) ,
secondaryButtonLabel = StringHolder ( null , " notification secondary button text " ) ,
ordering = 30 ,
prerequisites = listOf ( ) ,
disqualifiers = listOf ( " NEVER " , " OTHER " ) ,
)
private val unsortedAllKnownCardData = listOf (