Bug 1826767 - Update app to use onboarding manifest cards and enum
parent
21a16fa586
commit
1c22b3cbee
@ -0,0 +1,87 @@
|
||||
package org.mozilla.fenix.onboarding.view
|
||||
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import org.mozilla.experiments.nimbus.StringHolder
|
||||
import org.mozilla.fenix.R
|
||||
import org.mozilla.fenix.helpers.HomeActivityIntentTestRule
|
||||
import org.mozilla.fenix.nimbus.OnboardingCardData
|
||||
import org.mozilla.fenix.nimbus.OnboardingCardType
|
||||
|
||||
class JunoOnboardingMapperTest {
|
||||
|
||||
@get:Rule
|
||||
val activityTestRule =
|
||||
HomeActivityIntentTestRule.withDefaultSettingsOverrides(skipOnboarding = true)
|
||||
|
||||
@Test
|
||||
fun showNotificationTrue_pagesToDisplay_returnsSortedListOfAllConvertedPages() {
|
||||
val expected = listOf(defaultBrowserPageUiData, syncPageUiData, notificationPageUiData)
|
||||
assertEquals(expected, unsortedAllKnownCardData.toPageUiData(true))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun showNotificationFalse_pagesToDisplay_returnsSortedListOfConvertedPagesWithoutNotificationPage() {
|
||||
val expected = listOf(defaultBrowserPageUiData, syncPageUiData)
|
||||
assertEquals(expected, unsortedAllKnownCardData.toPageUiData(false))
|
||||
}
|
||||
}
|
||||
|
||||
private val defaultBrowserPageUiData = OnboardingPageUiData(
|
||||
type = OnboardingPageUiData.Type.DEFAULT_BROWSER,
|
||||
imageRes = R.drawable.ic_onboarding_welcome,
|
||||
title = "default browser title",
|
||||
description = "default browser body with link text",
|
||||
linkText = "link text",
|
||||
primaryButtonLabel = "default browser primary button text",
|
||||
secondaryButtonLabel = "default browser secondary button text",
|
||||
)
|
||||
private val syncPageUiData = OnboardingPageUiData(
|
||||
type = OnboardingPageUiData.Type.SYNC_SIGN_IN,
|
||||
imageRes = R.drawable.ic_onboarding_sync,
|
||||
title = "sync title",
|
||||
description = "sync body",
|
||||
primaryButtonLabel = "sync primary button text",
|
||||
secondaryButtonLabel = "sync secondary button text",
|
||||
)
|
||||
private val notificationPageUiData = OnboardingPageUiData(
|
||||
type = OnboardingPageUiData.Type.NOTIFICATION_PERMISSION,
|
||||
imageRes = R.drawable.ic_notification_permission,
|
||||
title = "notification title",
|
||||
description = "notification body",
|
||||
primaryButtonLabel = "notification primary button text",
|
||||
secondaryButtonLabel = "notification secondary button text",
|
||||
)
|
||||
|
||||
private val defaultBrowserCardData = OnboardingCardData(
|
||||
cardType = OnboardingCardType.DEFAULT_BROWSER,
|
||||
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,
|
||||
)
|
||||
private val syncCardData = OnboardingCardData(
|
||||
cardType = OnboardingCardType.SYNC_SIGN_IN,
|
||||
title = StringHolder(null, "sync title"),
|
||||
body = StringHolder(null, "sync body"),
|
||||
primaryButtonLabel = StringHolder(null, "sync primary button text"),
|
||||
secondaryButtonLabel = StringHolder(null, "sync secondary button text"),
|
||||
ordering = 20,
|
||||
)
|
||||
private val notificationCardData = OnboardingCardData(
|
||||
cardType = OnboardingCardType.NOTIFICATION_PERMISSION,
|
||||
title = StringHolder(null, "notification title"),
|
||||
body = StringHolder(null, "notification body"),
|
||||
primaryButtonLabel = StringHolder(null, "notification primary button text"),
|
||||
secondaryButtonLabel = StringHolder(null, "notification secondary button text"),
|
||||
ordering = 30,
|
||||
)
|
||||
|
||||
private val unsortedAllKnownCardData = listOf(
|
||||
syncCardData,
|
||||
notificationCardData,
|
||||
defaultBrowserCardData,
|
||||
)
|
@ -1,36 +0,0 @@
|
||||
/* 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.onboarding.view
|
||||
|
||||
/**
|
||||
* Model for different types of Onboarding Pages.
|
||||
* @param sequencePosition Position of the page in the onboarding flow, used in telemetry.
|
||||
* @param id Identifier for the page, used in telemetry.
|
||||
*/
|
||||
enum class JunoOnboardingPageType(
|
||||
val sequencePosition: String,
|
||||
val id: String,
|
||||
) {
|
||||
DEFAULT_BROWSER(
|
||||
sequencePosition = "1",
|
||||
id = "default",
|
||||
),
|
||||
SYNC_SIGN_IN(
|
||||
sequencePosition = "2",
|
||||
id = "sync",
|
||||
),
|
||||
NOTIFICATION_PERMISSION(
|
||||
sequencePosition = "3",
|
||||
id = "notification",
|
||||
),
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function for telemetry that maps List<JunoOnboardingPageType> to a string of page names
|
||||
* separated by an underscore.
|
||||
* e.g. [DEFAULT_BROWSER, SYNC_SIGN_IN] will be mapped to "default_sync".
|
||||
*/
|
||||
fun List<JunoOnboardingPageType>.telemetrySequenceId(): String =
|
||||
joinToString(separator = "_") { it.id }
|
@ -0,0 +1,53 @@
|
||||
/* 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.onboarding.view
|
||||
|
||||
import androidx.annotation.DrawableRes
|
||||
import org.mozilla.fenix.nimbus.OnboardingCardData
|
||||
|
||||
/**
|
||||
* Model containing the required data from a raw [OnboardingCardData] object in a UI state.
|
||||
*/
|
||||
data class OnboardingPageUiData(
|
||||
val type: Type,
|
||||
@DrawableRes val imageRes: Int,
|
||||
val title: String,
|
||||
val description: String,
|
||||
val linkText: String? = null,
|
||||
val primaryButtonLabel: String,
|
||||
val secondaryButtonLabel: String,
|
||||
) {
|
||||
/**
|
||||
* Model for different types of Onboarding Pages.
|
||||
* @param telemetryId Identifier for the page, used in telemetry.
|
||||
*/
|
||||
enum class Type(
|
||||
val telemetryId: String,
|
||||
) {
|
||||
DEFAULT_BROWSER(
|
||||
telemetryId = "default",
|
||||
),
|
||||
SYNC_SIGN_IN(
|
||||
telemetryId = "sync",
|
||||
),
|
||||
NOTIFICATION_PERMISSION(
|
||||
telemetryId = "notification",
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the sequence position for the given [OnboardingPageUiData.Type].
|
||||
*/
|
||||
fun List<OnboardingPageUiData>.sequencePosition(type: OnboardingPageUiData.Type): String =
|
||||
indexOfFirst { it.type == type }.inc().toString()
|
||||
|
||||
/**
|
||||
* Helper function for telemetry that maps List<OnboardingPageUiData> to a string of page names
|
||||
* separated by an underscore.
|
||||
* e.g. [DEFAULT_BROWSER, SYNC_SIGN_IN] will be mapped to "default_sync".
|
||||
*/
|
||||
fun List<OnboardingPageUiData>.telemetrySequenceId(): String =
|
||||
joinToString(separator = "_") { it.type.telemetryId }
|
@ -0,0 +1,126 @@
|
||||
/* 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.onboarding.view
|
||||
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Test
|
||||
import org.mozilla.fenix.R
|
||||
import org.mozilla.fenix.settings.SupportUtils
|
||||
|
||||
class JunoOnboardingMapperTest {
|
||||
|
||||
@Test
|
||||
fun `GIVEN a default browser page WHEN mapToOnboardingPageState is called THEN creates the expected OnboardingPageState`() {
|
||||
val expected = OnboardingPageState(
|
||||
image = R.drawable.ic_onboarding_welcome,
|
||||
title = "default browser title",
|
||||
description = "default browser body with link text",
|
||||
linkTextState = LinkTextState(
|
||||
text = "link text",
|
||||
url = SupportUtils.getMozillaPageUrl(SupportUtils.MozillaPage.PRIVATE_NOTICE),
|
||||
onClick = stringLambda,
|
||||
),
|
||||
primaryButton = Action("default browser primary button text", unitLambda),
|
||||
secondaryButton = Action("default browser secondary button text", unitLambda),
|
||||
)
|
||||
|
||||
val onboardingPageUiData = OnboardingPageUiData(
|
||||
type = OnboardingPageUiData.Type.DEFAULT_BROWSER,
|
||||
imageRes = R.drawable.ic_onboarding_welcome,
|
||||
title = "default browser title",
|
||||
description = "default browser body with link text",
|
||||
linkText = "link text",
|
||||
primaryButtonLabel = "default browser primary button text",
|
||||
secondaryButtonLabel = "default browser secondary button text",
|
||||
)
|
||||
val actual = mapToOnboardingPageState(
|
||||
onboardingPageUiData = onboardingPageUiData,
|
||||
onMakeFirefoxDefaultClick = unitLambda,
|
||||
onMakeFirefoxDefaultSkipClick = unitLambda,
|
||||
onPrivacyPolicyClick = stringLambda,
|
||||
onSignInButtonClick = {},
|
||||
onSignInSkipClick = {},
|
||||
onNotificationPermissionButtonClick = {},
|
||||
onNotificationPermissionSkipClick = {},
|
||||
)
|
||||
|
||||
assertEquals(expected, actual)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `GIVEN a sync page WHEN mapToOnboardingPageState is called THEN creates the expected OnboardingPageState`() {
|
||||
val expected = OnboardingPageState(
|
||||
image = R.drawable.ic_onboarding_sync,
|
||||
title = "sync title",
|
||||
description = "sync body",
|
||||
primaryButton = Action("sync primary button text", unitLambda),
|
||||
secondaryButton = Action("sync secondary button text", unitLambda),
|
||||
)
|
||||
|
||||
val onboardingPageUiData = OnboardingPageUiData(
|
||||
type = OnboardingPageUiData.Type.SYNC_SIGN_IN,
|
||||
imageRes = R.drawable.ic_onboarding_sync,
|
||||
title = "sync title",
|
||||
description = "sync body",
|
||||
linkText = null,
|
||||
primaryButtonLabel = "sync primary button text",
|
||||
secondaryButtonLabel = "sync secondary button text",
|
||||
)
|
||||
val actual = mapToOnboardingPageState(
|
||||
onboardingPageUiData = onboardingPageUiData,
|
||||
onMakeFirefoxDefaultClick = {},
|
||||
onMakeFirefoxDefaultSkipClick = {},
|
||||
onPrivacyPolicyClick = {},
|
||||
onSignInButtonClick = unitLambda,
|
||||
onSignInSkipClick = unitLambda,
|
||||
onNotificationPermissionButtonClick = {},
|
||||
onNotificationPermissionSkipClick = {},
|
||||
)
|
||||
|
||||
assertEquals(expected, actual)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `GIVEN a notification page WHEN mapToOnboardingPageState is called THEN creates the expected OnboardingPageState`() {
|
||||
val expected = OnboardingPageState(
|
||||
image = R.drawable.ic_notification_permission,
|
||||
title = "notification title",
|
||||
description = "notification body",
|
||||
primaryButton = Action("notification primary button text", unitLambda),
|
||||
secondaryButton = Action("notification secondary button text", unitLambda),
|
||||
)
|
||||
|
||||
val onboardingPageUiData = OnboardingPageUiData(
|
||||
type = OnboardingPageUiData.Type.NOTIFICATION_PERMISSION,
|
||||
imageRes = R.drawable.ic_notification_permission,
|
||||
title = "notification title",
|
||||
description = "notification body",
|
||||
linkText = null,
|
||||
primaryButtonLabel = "notification primary button text",
|
||||
secondaryButtonLabel = "notification secondary button text",
|
||||
)
|
||||
val actual = mapToOnboardingPageState(
|
||||
onboardingPageUiData = onboardingPageUiData,
|
||||
onMakeFirefoxDefaultClick = {},
|
||||
onMakeFirefoxDefaultSkipClick = {},
|
||||
onPrivacyPolicyClick = {},
|
||||
onSignInButtonClick = {},
|
||||
onSignInSkipClick = {},
|
||||
onNotificationPermissionButtonClick = unitLambda,
|
||||
onNotificationPermissionSkipClick = unitLambda,
|
||||
)
|
||||
|
||||
assertEquals(expected, actual)
|
||||
}
|
||||
}
|
||||
|
||||
private val unitLambda = { dummyUnitFunc() }
|
||||
private val stringLambda = { s: String -> dummyStringArgFunc(s) }
|
||||
|
||||
private fun dummyUnitFunc() {}
|
||||
|
||||
private fun dummyStringArgFunc(string: String) {
|
||||
print(string)
|
||||
}
|
@ -1,44 +0,0 @@
|
||||
package org.mozilla.fenix.onboarding.view
|
||||
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Test
|
||||
|
||||
class JunoOnboardingPageTypeTest {
|
||||
|
||||
@Test
|
||||
fun `GIVEN a list of JunoOnboardingPageType sequenceId() should map to the correct sequence id - 1`() {
|
||||
val list = listOf(
|
||||
JunoOnboardingPageType.DEFAULT_BROWSER,
|
||||
JunoOnboardingPageType.SYNC_SIGN_IN,
|
||||
JunoOnboardingPageType.NOTIFICATION_PERMISSION,
|
||||
)
|
||||
|
||||
val expected = "default_sync_notification"
|
||||
val actual = list.telemetrySequenceId()
|
||||
|
||||
assertEquals(expected, actual)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `GIVEN a list of JunoOnboardingPageType sequenceId() should map to the correct sequence id - 2`() {
|
||||
val list = listOf(
|
||||
JunoOnboardingPageType.DEFAULT_BROWSER,
|
||||
JunoOnboardingPageType.SYNC_SIGN_IN,
|
||||
)
|
||||
|
||||
val expected = "default_sync"
|
||||
val actual = list.telemetrySequenceId()
|
||||
|
||||
assertEquals(expected, actual)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `GIVEN a list of JunoOnboardingPageType sequenceId() should map to the correct sequence id - 3`() {
|
||||
val list = listOf(JunoOnboardingPageType.DEFAULT_BROWSER)
|
||||
|
||||
val expected = "default"
|
||||
val actual = list.telemetrySequenceId()
|
||||
|
||||
assertEquals(expected, actual)
|
||||
}
|
||||
}
|
@ -0,0 +1,86 @@
|
||||
/* 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.onboarding.view
|
||||
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Test
|
||||
import org.mozilla.fenix.R
|
||||
|
||||
class OnboardingPageUiDataTest {
|
||||
|
||||
@Test
|
||||
fun `GIVEN first page in the list WHEN sequencePosition called THEN returns the index plus 1`() {
|
||||
val expected = "1"
|
||||
val actual = allKnownPages.sequencePosition(defaultBrowserPageUiData.type)
|
||||
|
||||
assertEquals(expected, actual)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `GIVEN last page in the list WHEN sequencePosition called THEN returns the index plus 1`() {
|
||||
val expected = "3"
|
||||
val actual = allKnownPages.sequencePosition(notificationPageUiData.type)
|
||||
|
||||
assertEquals(expected, actual)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `GIVEN all known pages of WHEN sequenceId() called THEN should map to the correct sequence id`() {
|
||||
val expected = "default_sync_notification"
|
||||
val actual = allKnownPages.telemetrySequenceId()
|
||||
|
||||
assertEquals(expected, actual)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `GIVEN some of the known pages WHEN sequenceId() called THEN should map to the correct sequence id`() {
|
||||
val expected = "default_sync"
|
||||
val actual = listOf(defaultBrowserPageUiData, syncPageUiData).telemetrySequenceId()
|
||||
|
||||
assertEquals(expected, actual)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `GIVEN a single known page WHEN sequenceId() called THEN should map to the correct sequence id`() {
|
||||
val expected = "default"
|
||||
val actual = listOf(defaultBrowserPageUiData).telemetrySequenceId()
|
||||
|
||||
assertEquals(expected, actual)
|
||||
}
|
||||
}
|
||||
|
||||
private val defaultBrowserPageUiData = OnboardingPageUiData(
|
||||
type = OnboardingPageUiData.Type.DEFAULT_BROWSER,
|
||||
imageRes = R.drawable.ic_onboarding_welcome,
|
||||
title = "default browser title",
|
||||
description = "default browser body with link text",
|
||||
linkText = "link text",
|
||||
primaryButtonLabel = "default browser primary button text",
|
||||
secondaryButtonLabel = "default browser secondary button text",
|
||||
)
|
||||
|
||||
private val syncPageUiData = OnboardingPageUiData(
|
||||
type = OnboardingPageUiData.Type.SYNC_SIGN_IN,
|
||||
imageRes = R.drawable.ic_onboarding_sync,
|
||||
title = "sync title",
|
||||
description = "sync body",
|
||||
primaryButtonLabel = "sync primary button text",
|
||||
secondaryButtonLabel = "sync secondary button text",
|
||||
)
|
||||
|
||||
private val notificationPageUiData = OnboardingPageUiData(
|
||||
type = OnboardingPageUiData.Type.NOTIFICATION_PERMISSION,
|
||||
imageRes = R.drawable.ic_notification_permission,
|
||||
title = "notification title",
|
||||
description = "notification body",
|
||||
primaryButtonLabel = "notification primary button text",
|
||||
secondaryButtonLabel = "notification secondary button text",
|
||||
)
|
||||
|
||||
private val allKnownPages = listOf(
|
||||
defaultBrowserPageUiData,
|
||||
syncPageUiData,
|
||||
notificationPageUiData,
|
||||
)
|
Loading…
Reference in New Issue