Skip to content

Commit

Permalink
Merge pull request #15928 from wordpress-mobile/issue/15922-allow-acc…
Browse files Browse the repository at this point in the history
…ount-creation-jetpack-app

Jetpack app: Enable account creation
ashiagr authored Feb 11, 2022

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
2 parents 08c3a64 + c7b5e42 commit 9100652
Showing 5 changed files with 42 additions and 7 deletions.
2 changes: 2 additions & 0 deletions WordPress/build.gradle
Original file line number Diff line number Diff line change
@@ -120,6 +120,7 @@ android {
// Override these constants in jetpack product flavor to enable/ disable features
buildConfigField "boolean", "ENABLE_SITE_CREATION", "true"
buildConfigField "boolean", "ENABLE_ADD_SELF_HOSTED_SITE", "true"
buildConfigField "boolean", "ENABLE_SIGNUP", "true"

manifestPlaceholders = [magicLinkScheme:"wordpress"]
}
@@ -157,6 +158,7 @@ android {
buildConfigField "boolean", "IS_JETPACK_APP", "true"
buildConfigField "boolean", "ENABLE_SITE_CREATION", "true"
buildConfigField "boolean", "ENABLE_ADD_SELF_HOSTED_SITE", "false"
buildConfigField "boolean", "ENABLE_SIGNUP", "true"
buildConfigField "String", "TRACKS_EVENT_PREFIX", '"jpandroid_"'
buildConfigField "String", "PUSH_NOTIFICATIONS_APP_KEY", '"com.jetpack.android"'

Original file line number Diff line number Diff line change
@@ -17,6 +17,7 @@ import org.wordpress.android.ui.accounts.UnifiedLoginTracker.Flow
import org.wordpress.android.ui.accounts.UnifiedLoginTracker.Step.PROLOGUE
import org.wordpress.android.ui.accounts.login.LoginPrologueViewModel.ButtonUiState.ContinueWithWpcomButtonState
import org.wordpress.android.ui.accounts.login.LoginPrologueViewModel.ButtonUiState.EnterYourSiteAddressButtonState
import org.wordpress.android.util.BuildConfigWrapper
import org.wordpress.android.util.analytics.AnalyticsTrackerWrapper
import org.wordpress.android.viewmodel.Event
import org.wordpress.android.viewmodel.ScopedViewModel
@@ -26,6 +27,7 @@ import javax.inject.Named
class LoginPrologueViewModel @Inject constructor(
private val unifiedLoginTracker: UnifiedLoginTracker,
private val analyticsTrackerWrapper: AnalyticsTrackerWrapper,
private val buildConfigWrapper: BuildConfigWrapper,
@Named(UI_THREAD) mainDispatcher: CoroutineDispatcher
) : ScopedViewModel(mainDispatcher) {
private val _navigationEvents = MediatorLiveData<Event<LoginNavigationEvents>>()
@@ -44,7 +46,14 @@ class LoginPrologueViewModel @Inject constructor(

_uiState.value = UiState(
enterYourSiteAddressButtonState = EnterYourSiteAddressButtonState(::onEnterYourSiteAddressButtonClick),
continueWithWpcomButtonState = ContinueWithWpcomButtonState(::onContinueWithWpcomButtonClick)
continueWithWpcomButtonState = ContinueWithWpcomButtonState(
title = if (buildConfigWrapper.isSignupEnabled) {
R.string.continue_with_wpcom
} else {
R.string.continue_with_wpcom_no_signup
},
onClick = ::onContinueWithWpcomButtonClick
)
)
}

@@ -71,9 +80,10 @@ class LoginPrologueViewModel @Inject constructor(
abstract val title: Int
abstract val onClick: (() -> Unit)

data class ContinueWithWpcomButtonState(override val onClick: () -> Unit) : ButtonUiState() {
override val title = R.string.continue_with_wpcom_no_signup
}
data class ContinueWithWpcomButtonState(
override val title: Int,
override val onClick: () -> Unit
) : ButtonUiState()

data class EnterYourSiteAddressButtonState(override val onClick: () -> Unit) : ButtonUiState() {
override val title = R.string.enter_your_site_address
Original file line number Diff line number Diff line change
@@ -70,6 +70,7 @@
import org.wordpress.android.ui.reader.services.update.ReaderUpdateServiceStarter;
import org.wordpress.android.util.AppLog;
import org.wordpress.android.util.AppLog.T;
import org.wordpress.android.util.BuildConfigWrapper;
import org.wordpress.android.util.SelfSignedSSLUtils;
import org.wordpress.android.util.StringUtils;
import org.wordpress.android.util.ToastUtils;
@@ -132,6 +133,7 @@ private enum SmartLockHelperState {
@Inject UnifiedLoginTracker mUnifiedLoginTracker;
@Inject protected SiteStore mSiteStore;
@Inject protected ViewModelProvider.Factory mViewModelFactory;
@Inject BuildConfigWrapper mBuildConfigWrapper;

@Override
protected void onCreate(Bundle savedInstanceState) {
@@ -158,7 +160,7 @@ protected void onCreate(Bundle savedInstanceState) {
break;
case JETPACK_LOGIN_ONLY:
mUnifiedLoginTracker.setSource(Source.DEFAULT);
mIsSignupFromLoginEnabled = false;
mIsSignupFromLoginEnabled = mBuildConfigWrapper.isSignupEnabled();
loginFromPrologue();
break;
case WPCOM_LOGIN_ONLY:
Original file line number Diff line number Diff line change
@@ -21,4 +21,6 @@ class BuildConfigWrapper @Inject constructor() {
val isJetpackApp = BuildConfig.IS_JETPACK_APP

val isSiteCreationEnabled = BuildConfig.ENABLE_SITE_CREATION

val isSignupEnabled = BuildConfig.ENABLE_SIGNUP
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.wordpress.android.ui.accounts.login

import com.nhaarman.mockitokotlin2.whenever
import kotlinx.coroutines.InternalCoroutinesApi
import org.assertj.core.api.Assertions.assertThat
import org.junit.Before
@@ -13,28 +14,46 @@ import org.wordpress.android.ui.accounts.LoginNavigationEvents.ShowEmailLoginScr
import org.wordpress.android.ui.accounts.LoginNavigationEvents.ShowLoginViaSiteAddressScreen
import org.wordpress.android.ui.accounts.UnifiedLoginTracker
import org.wordpress.android.ui.accounts.login.LoginPrologueViewModel.UiState
import org.wordpress.android.util.BuildConfigWrapper
import org.wordpress.android.util.analytics.AnalyticsTrackerWrapper
import org.wordpress.android.viewmodel.Event

@InternalCoroutinesApi
class LoginPrologueViewModelTest : BaseUnitTest() {
@Mock lateinit var unifiedLoginTracker: UnifiedLoginTracker
@Mock lateinit var analyticsTrackerWrapper: AnalyticsTrackerWrapper
@Mock lateinit var buildConfigWrapper: BuildConfigWrapper
private lateinit var viewModel: LoginPrologueViewModel

@Before
fun setUp() {
viewModel = LoginPrologueViewModel(unifiedLoginTracker, analyticsTrackerWrapper, TEST_DISPATCHER)
viewModel = LoginPrologueViewModel(
unifiedLoginTracker,
analyticsTrackerWrapper,
buildConfigWrapper,
TEST_DISPATCHER
)
}

@Test
fun `when view starts, then continue with wpcom button is displayed with correct title`() {
fun `given signup disabled, when view starts, then continue with wpcom button is displayed with correct title`() {
whenever(buildConfigWrapper.isSignupEnabled).thenReturn(false)
val observers = init()

assertThat(observers.uiStates.last().continueWithWpcomButtonState.title)
.isEqualTo(R.string.continue_with_wpcom_no_signup)
}

@Test
fun `given signup enabled, when view starts, then continue with wpcom button is displayed with correct title`() {
whenever(buildConfigWrapper.isSignupEnabled).thenReturn(true)

val observers = init()

assertThat(observers.uiStates.last().continueWithWpcomButtonState.title)
.isEqualTo(R.string.continue_with_wpcom)
}

@Test
fun `when view starts, enter your site address button is displayed with correct title`() {
val observers = init()

0 comments on commit 9100652

Please sign in to comment.