Skip to content

Commit

Permalink
Merge pull request #19387 from wordpress-mobile/Plans-in-site-creatio…
Browse files Browse the repository at this point in the history
…n-Update-RELEASE-NOTES

Plans in Site Creation: Update RELEASE-NOTES.txt
  • Loading branch information
irfano authored Oct 17, 2023
2 parents c16e2b7 + da18856 commit 24e0a19
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 21 deletions.
1 change: 1 addition & 0 deletions RELEASE-NOTES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
-----
* [*] Block Editor: Split formatted text on triple Enter [https://github.com/WordPress/gutenberg/pull/53354]
* [*] Block Editor: Quote block: Ensure border is visible with block-based themes in dark [https://github.com/WordPress/gutenberg/pull/54964]
* [***] [internal][Jetpack-only] [***] Added domain selection, plan selection, and checkout screens in site creation flow [https://github.com/wordpress-mobile/WordPress-Android/pull/19304]
* [**] [Jetpack-only] Reader: Improvement of core UI elements, including feed cards, tag and site headers, buttons and recommendation sections [https://github.com/wordpress-mobile/WordPress-Android/pull/19267]

23.4
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,18 +276,6 @@ class SiteCreationMainVM @Inject constructor(

fun onPlanSelection(plan: PlanModel) {
siteCreationState = siteCreationState.copy(plan = plan)
if (plan.productSlug == "free_plan") {
// if they select a paid domain, then choose a free plan, with free domain on plan selection screen
siteCreationState = siteCreationState.copy(
domain = DomainModel(
domainName = plan.productName.orEmpty(),
isFree = true,
cost = "",
productId = 0,
supportsPrivacy = false
)
)
}
wizardManager.showNextStep()
}

Expand Down Expand Up @@ -334,7 +322,7 @@ class SiteCreationMainVM @Inject constructor(

fun onFreeSiteCreated(site: SiteModel) {
siteCreationState = siteCreationState.copy(result = CreatedButNotFetched.NotInLocalDb(site))
if (checkNotNull(siteCreationState.domain).isFree) {
if (siteCreationState.plan?.productSlug == "free_plan") {
wizardManager.showNextStep()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import org.wordpress.android.ui.utils.UiString.UiStringRes
import org.wordpress.android.ui.utils.UiString.UiStringResWithParams
import org.wordpress.android.util.AppLog
import org.wordpress.android.util.AppLog.T
import org.wordpress.android.util.StringUtils
import org.wordpress.android.util.UrlUtilsWrapper
import org.wordpress.android.viewmodel.SingleLiveEvent
import javax.inject.Inject
Expand Down Expand Up @@ -84,7 +85,7 @@ class SitePreviewViewModel @Inject constructor(
siteDesign = siteCreationState.siteDesign
result = siteCreationState.result
isFree = requireNotNull(siteCreationState.domain).isFree
domainName = requireNotNull(siteCreationState.domain).domainName
domainName = getCleanUrl(result.site.url) ?: ""
startPreLoadingWebView()
if (result is CreatedButNotFetched) {
launch {
Expand Down Expand Up @@ -159,6 +160,8 @@ class SitePreviewViewModel @Inject constructor(
}
}

private fun getCleanUrl(url: String) = StringUtils.removeTrailingSlash(urlUtils.removeScheme(url))

private fun createSitePreviewData(): UrlData {
val url = domainName
val subDomain = urlUtils.extractSubDomain(url)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,12 @@ class SiteCreationProgressViewModel @Inject constructor(
IDLE, CREATE_SITE -> Unit
SUCCESS -> {
site = mapPayloadToSiteModel(event.payload)
_onFreeSiteCreated.postValue(site) // MainVM will navigate forward if the domain is free
if (!domain.isFree && siteCreationState.plan?.productId != 0) {

val isFreePlan = siteCreationState.plan?.productSlug == "free_plan"

if (isFreePlan) {
_onFreeSiteCreated.postValue(site) // MainVM will navigate forward if the domain is free
} else {
createCart()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,23 @@ const val URL_CUSTOM = "$SUB_DOMAIN.host.com"
const val SITE_SLUG = "${SUB_DOMAIN}host0.wordpress.com"
val FREE_DOMAIN = DomainModel(URL, true, "", 1, false)
val PAID_DOMAIN = DomainModel(URL_CUSTOM, false, "$1", 2, true)
val PLAN_MODEL = PlanModel(1009, "paid_plan", "Personal", isCurrentPlan = false, hasDomainCredit = false)
val PAID_PLAN = PlanModel(1009, "paid_plan", "Personal", isCurrentPlan = false, hasDomainCredit = false)
val FREE_PLAN = PlanModel(0, "free_plan", "", isCurrentPlan = false, hasDomainCredit = false)

const val SITE_REMOTE_ID = 1L

val SITE_CREATION_STATE = SiteCreationState(
segmentId = 1,
siteDesign = defaultTemplateSlug,
domain = PAID_DOMAIN,
plan = PAID_PLAN
)

val SITE_CREATION_STATE_FREE = SiteCreationState(
segmentId = 1,
siteDesign = defaultTemplateSlug,
domain = FREE_DOMAIN,
plan = PLAN_MODEL
plan = FREE_PLAN
)

val SITE_MODEL = SiteModel().apply { siteId = SITE_REMOTE_ID; url = SITE_SLUG }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ class SiteCreationMainVMTest : BaseUnitTest() {
@Test
fun `on site created updates result`() = test {
viewModel.onDomainsScreenFinished(FREE_DOMAIN)
viewModel.onPlanSelection(FREE_PLAN)
viewModel.onFreeSiteCreated(SITE_MODEL)
assertThat(currentWizardState(viewModel).result).isEqualTo(RESULT_NOT_IN_LOCAL_DB)
}
Expand All @@ -208,6 +209,7 @@ class SiteCreationMainVMTest : BaseUnitTest() {
fun `on site created for free domain shows next step`() {
viewModel.onDomainsScreenFinished(FREE_DOMAIN).run { clearInvocations(wizardManager) }
viewModel.onFreeSiteCreated(SITE_MODEL)
viewModel.onPlanSelection(FREE_PLAN)
verify(wizardManager).showNextStep()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import org.wordpress.android.ui.sitecreation.RESULT_IN_CART
import org.wordpress.android.ui.sitecreation.SERVICE_ERROR
import org.wordpress.android.ui.sitecreation.SERVICE_SUCCESS
import org.wordpress.android.ui.sitecreation.SITE_CREATION_STATE
import org.wordpress.android.ui.sitecreation.SITE_CREATION_STATE_FREE
import org.wordpress.android.ui.sitecreation.SITE_REMOTE_ID
import org.wordpress.android.ui.sitecreation.SITE_SLUG
import org.wordpress.android.ui.sitecreation.SiteCreationState
Expand Down Expand Up @@ -103,7 +104,7 @@ class SiteCreationProgressViewModelTest : BaseUnitTest() {

@Test
fun `on start emits service event for free domains with isFree true`() = test {
startViewModel(SITE_CREATION_STATE)
startViewModel(SITE_CREATION_STATE_FREE)
val request = assertNotNull(viewModel.startCreateSiteService.value).serviceData
assertTrue(request.isFree)
}
Expand Down Expand Up @@ -131,7 +132,7 @@ class SiteCreationProgressViewModelTest : BaseUnitTest() {

@Test
fun `on start changes the loading text with animation after delay`() = test {
startViewModel()
startViewModelFree()
advanceTimeBy(LOADING_STATE_TEXT_ANIMATION_DELAY)
verify(uiStateObserver).onChanged(check<Loading> { it.animate })
}
Expand Down Expand Up @@ -188,7 +189,7 @@ class SiteCreationProgressViewModelTest : BaseUnitTest() {

@Test
fun `on service success propagates site`() {
startViewModel()
startViewModelFree()
viewModel.onSiteCreationServiceStateUpdated(SERVICE_SUCCESS)
verify(onRemoteSiteCreatedObserver).onChanged(argThat {
assertEquals(SITE_REMOTE_ID, siteId)
Expand Down Expand Up @@ -308,5 +309,9 @@ class SiteCreationProgressViewModelTest : BaseUnitTest() {
viewModel.start(state)
}

private fun startViewModelFree(state: SiteCreationState = SITE_CREATION_STATE_FREE) {
viewModel.start(state)
}

// endregion
}

0 comments on commit 24e0a19

Please sign in to comment.