Skip to content

Commit

Permalink
Merge pull request #16277 from wordpress-mobile/issue/15989-msd-dynam…
Browse files Browse the repository at this point in the history
…ic-cards

My Site Dashboard: Tabs - Show Dynamic Cards on either tab
  • Loading branch information
ashiagr authored Apr 8, 2022
2 parents 6f60df0 + 72edb6c commit 817be12
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -479,15 +479,15 @@ class MySiteViewModel @Inject constructor(
cardsResult.filterNot {
getCardTypeExclusionFiltersForTab(MySiteTabType.SITE_MENU).contains(it.type)
},
dynamicCards,
if (shouldIncludeDynamicCards(MySiteTabType.SITE_MENU)) { dynamicCards } else { listOf() },
siteItems
),
MySiteTabType.DASHBOARD to orderForDisplay(
infoItem,
cardsResult.filterNot {
getCardTypeExclusionFiltersForTab(MySiteTabType.DASHBOARD).contains(it.type)
},
listOf(),
if (shouldIncludeDynamicCards(MySiteTabType.DASHBOARD)) { dynamicCards } else { listOf() },
listOf()
)
)
Expand All @@ -504,17 +504,28 @@ class MySiteViewModel @Inject constructor(
private fun getCardTypeExclusionFiltersForTab(tabType: MySiteTabType) = when (tabType) {
MySiteTabType.SITE_MENU -> mutableListOf<Type>().apply {
add(Type.DASHBOARD_CARDS)
if (defaultABExperimentTab == MySiteTabType.DASHBOARD) add(Type.QUICK_START_CARD)
if (defaultABExperimentTab == MySiteTabType.DASHBOARD) {
add(Type.QUICK_START_CARD)
}
add(Type.QUICK_LINK_RIBBON)
}
MySiteTabType.DASHBOARD -> mutableListOf<Type>().apply {
if (defaultABExperimentTab == MySiteTabType.SITE_MENU) add(Type.QUICK_START_CARD)
if (defaultABExperimentTab == MySiteTabType.SITE_MENU) {
add(Type.QUICK_START_CARD)
}
add(Type.DOMAIN_REGISTRATION_CARD)
add(Type.QUICK_ACTIONS_CARD)
}
MySiteTabType.ALL -> emptyList()
}

private fun shouldIncludeDynamicCards(tabType: MySiteTabType) = when (tabType) {
MySiteTabType.SITE_MENU -> defaultABExperimentTab != MySiteTabType.DASHBOARD
MySiteTabType.DASHBOARD -> defaultABExperimentTab != MySiteTabType.SITE_MENU
MySiteTabType.ALL -> true
}

@Suppress("EmptyFunctionBlock")
private fun onGetMoreViewsClick() {
cardsTracker.trackTodaysStatsCardGetMoreViewsNudgeClicked()
_onNavigation.value = Event(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2059,6 +2059,74 @@ class MySiteViewModelTest : BaseUnitTest() {
assertThat(siteInfoHeaderCard).isTrue
}

@Test
fun `given tabs enabled + site menu initial screen, when site menu cards + items, then dynamic card exists`() {
whenever(mySiteDashboardPhase2FeatureConfig.isEnabled()).thenReturn(true)
setUpSiteItemBuilder()

initSelectedSite(
isMySiteDashboardTabsFeatureFlagEnabled = true,
isMySiteTabsBuildConfigEnabled = true,
initialScreen = SITE_MENU.label,
isQuickStartDynamicCardEnabled = true
)

val items = (uiModels.last().state as SiteSelected).siteMenuCardsAndItems

assertThat(items.filterIsInstance(DynamicCard::class.java)).isNotEmpty
}

@Test
fun `given tabs enabled + dashboard initial screen, when dashboard cards + items, then dynamic card exists`() {
whenever(mySiteDashboardPhase2FeatureConfig.isEnabled()).thenReturn(true)
setUpSiteItemBuilder()

initSelectedSite(
isMySiteDashboardTabsFeatureFlagEnabled = true,
isMySiteTabsBuildConfigEnabled = true,
initialScreen = home,
isQuickStartDynamicCardEnabled = true
)

val items = (uiModels.last().state as SiteSelected).dashboardCardsAndItems

assertThat(items.filterIsInstance(DynamicCard::class.java)).isNotEmpty
}

@Test
fun `given tabs enabled + site menu initial screen, when dashboard cards + items, then dynamic card not exists`() {
whenever(mySiteDashboardPhase2FeatureConfig.isEnabled()).thenReturn(true)
setUpSiteItemBuilder()

initSelectedSite(
isMySiteDashboardTabsFeatureFlagEnabled = true,
isMySiteTabsBuildConfigEnabled = true,
initialScreen = SITE_MENU.label,
isQuickStartDynamicCardEnabled = true
)

val items = (uiModels.last().state as SiteSelected).dashboardCardsAndItems

assertThat(items.filterIsInstance(DynamicCard::class.java)).isEmpty()
}

@Test
fun `given tabs enabled + dashboard initial screen, when site menu cards + items, then dynamic card not exists`() {
whenever(mySiteDashboardPhase2FeatureConfig.isEnabled()).thenReturn(true)
setUpSiteItemBuilder()

initSelectedSite(
isMySiteDashboardTabsFeatureFlagEnabled = true,
isMySiteTabsBuildConfigEnabled = true,
initialScreen = home,
isQuickStartDynamicCardEnabled = true
)

val items = (uiModels.last().state as SiteSelected).siteMenuCardsAndItems

assertThat(items.filterIsInstance(DynamicCard::class.java)).isEmpty()
}

/* TRACK WITH TAB SOURCE */
@Test
fun `given tabs are enabled, when pull to refresh invoked, then track with tab source is requested`() {
Expand Down

0 comments on commit 817be12

Please sign in to comment.