From 324f3a07183e806dd44d11451a6f8b47caab6570 Mon Sep 17 00:00:00 2001 From: ashiagr Date: Thu, 10 Feb 2022 12:06:34 +0530 Subject: [PATCH 1/2] Add build constant to enable signup in Jetpack app --- WordPress/build.gradle | 2 ++ .../main/java/org/wordpress/android/util/BuildConfigWrapper.kt | 2 ++ 2 files changed, 4 insertions(+) diff --git a/WordPress/build.gradle b/WordPress/build.gradle index 91435b5038da..92078f831180 100644 --- a/WordPress/build.gradle +++ b/WordPress/build.gradle @@ -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"' diff --git a/WordPress/src/main/java/org/wordpress/android/util/BuildConfigWrapper.kt b/WordPress/src/main/java/org/wordpress/android/util/BuildConfigWrapper.kt index 685152a2b7ce..ae938c104324 100644 --- a/WordPress/src/main/java/org/wordpress/android/util/BuildConfigWrapper.kt +++ b/WordPress/src/main/java/org/wordpress/android/util/BuildConfigWrapper.kt @@ -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 } From c7b5e42f9591976e41b950e2405c858be13931a2 Mon Sep 17 00:00:00 2001 From: ashiagr Date: Thu, 10 Feb 2022 12:10:05 +0530 Subject: [PATCH 2/2] Enable signup using build config constant --- .../accounts/login/LoginPrologueViewModel.kt | 18 +++++++++++---- .../android/ui/accounts/LoginActivity.java | 4 +++- .../LoginPrologueViewModelTest.kt | 23 +++++++++++++++++-- 3 files changed, 38 insertions(+), 7 deletions(-) diff --git a/WordPress/src/jetpack/java/org/wordpress/android/ui/accounts/login/LoginPrologueViewModel.kt b/WordPress/src/jetpack/java/org/wordpress/android/ui/accounts/login/LoginPrologueViewModel.kt index 4a2e98d759c4..981a6b035965 100644 --- a/WordPress/src/jetpack/java/org/wordpress/android/ui/accounts/login/LoginPrologueViewModel.kt +++ b/WordPress/src/jetpack/java/org/wordpress/android/ui/accounts/login/LoginPrologueViewModel.kt @@ -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>() @@ -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 diff --git a/WordPress/src/main/java/org/wordpress/android/ui/accounts/LoginActivity.java b/WordPress/src/main/java/org/wordpress/android/ui/accounts/LoginActivity.java index 7696cdd25e6b..8c95d437c268 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/accounts/LoginActivity.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/accounts/LoginActivity.java @@ -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: diff --git a/WordPress/src/testJetpack/java/org.wordpress.android/ui.accounts.login/LoginPrologueViewModelTest.kt b/WordPress/src/testJetpack/java/org.wordpress.android/ui.accounts.login/LoginPrologueViewModelTest.kt index 8f853fe70ddf..b93ad5a44837 100644 --- a/WordPress/src/testJetpack/java/org.wordpress.android/ui.accounts.login/LoginPrologueViewModelTest.kt +++ b/WordPress/src/testJetpack/java/org.wordpress.android/ui.accounts.login/LoginPrologueViewModelTest.kt @@ -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,6 +14,7 @@ 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 @@ -20,21 +22,38 @@ import org.wordpress.android.viewmodel.Event 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()