Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dashboard domain card UI #18240

Merged
merged 9 commits into from
Apr 13, 2023
Prev Previous commit
Next Next commit
Update CardsBuilderTest.kt
  • Loading branch information
ravishanker committed Apr 6, 2023
commit 76507871d6317fad4da1aae260839744c346a46d
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import org.wordpress.android.BaseUnitTest
import org.wordpress.android.ui.mysite.MySiteCardAndItem.Card.DashboardCards
import org.wordpress.android.ui.mysite.MySiteCardAndItem.Card.DashboardCards.DashboardCard.BloggingPromptCard
import org.wordpress.android.ui.mysite.MySiteCardAndItem.Card.DashboardCards.DashboardCard.BloggingPromptCard.BloggingPromptCardWithData
import org.wordpress.android.ui.mysite.MySiteCardAndItem.Card.DashboardCards.DashboardCard.DashboardDomainCard
import org.wordpress.android.ui.mysite.MySiteCardAndItem.Card.DashboardCards.DashboardCard.ErrorCard
import org.wordpress.android.ui.mysite.MySiteCardAndItem.Card.DashboardCards.DashboardCard.PostCard.FooterLink
import org.wordpress.android.ui.mysite.MySiteCardAndItem.Card.DashboardCards.DashboardCard.PostCard.PostCardWithPostItems
Expand All @@ -33,6 +34,7 @@ import org.wordpress.android.ui.mysite.cards.dashboard.posts.PostCardBuilder
import org.wordpress.android.ui.mysite.cards.dashboard.posts.PostCardType.CREATE_FIRST
import org.wordpress.android.ui.mysite.cards.dashboard.posts.PostCardType.DRAFT
import org.wordpress.android.ui.mysite.cards.dashboard.todaysstats.TodaysStatsCardBuilder
import org.wordpress.android.ui.mysite.cards.domain.DashboardDomainCardBuilder
import org.wordpress.android.ui.utils.UiString.UiStringText

@ExperimentalCoroutinesApi
Expand All @@ -49,6 +51,10 @@ class CardsBuilderTest : BaseUnitTest() {

@Mock
lateinit var promoteWithBlazeCardBuilder: PromoteWithBlazeCardBuilder

@Mock
lateinit var dashboardDomainCardBuilder: DashboardDomainCardBuilder

private lateinit var cardsBuilder: CardsBuilder

@Before
Expand All @@ -57,7 +63,8 @@ class CardsBuilderTest : BaseUnitTest() {
todaysStatsCardBuilder,
postCardBuilder,
bloggingPromptCardsBuilder,
promoteWithBlazeCardBuilder
promoteWithBlazeCardBuilder,
dashboardDomainCardBuilder
)
}

Expand Down Expand Up @@ -174,6 +181,20 @@ class CardsBuilderTest : BaseUnitTest() {
assertThat(cards.findPromoteWithBlazeCard()).isNotNull
}

@Test
fun `given is not eligible for domain, when cards are built, then domain card is not built`() {
val cards = buildDashboardCards(isEligibleForDomainCard = false)

assertThat(cards.findDashboardDomainCard()).isNull()
}

@Test
fun `given is eligible for domain, when cards are built, then domain card is built`() {
val cards = buildDashboardCards(isEligibleForDomainCard = true)

assertThat(cards.findDashboardDomainCard()).isNotNull
}

private fun DashboardCards.findTodaysStatsCard() =
this.cards.find { it is TodaysStatsCardWithData } as? TodaysStatsCardWithData

Expand All @@ -189,6 +210,9 @@ class CardsBuilderTest : BaseUnitTest() {
private fun DashboardCards.findPromoteWithBlazeCard() =
this.cards.find { it is PromoteWithBlazeCard } as? PromoteWithBlazeCard

private fun DashboardCards.findDashboardDomainCard() =
this.cards.find { it is DashboardDomainCard } as? DashboardDomainCard

private fun DashboardCards.findErrorCard() = this.cards.find { it is ErrorCard } as? ErrorCard

private val todaysStatsCard = mock<TodaysStatsCardWithData>()
Expand All @@ -197,6 +221,8 @@ class CardsBuilderTest : BaseUnitTest() {

private val promoteWithBlazeCard = mock<PromoteWithBlazeCard>()

private val dashboardDomainCard = mock<DashboardDomainCard>()

private fun createPostCards() = listOf(
PostCardWithPostItems(
postCardType = DRAFT,
Expand Down Expand Up @@ -231,6 +257,8 @@ class CardsBuilderTest : BaseUnitTest() {
doAnswer { if (hasBlogginPrompt) blogingPromptCard else null }.whenever(bloggingPromptCardsBuilder).build(any())
doAnswer { if (isEligibleForBlaze) promoteWithBlazeCard else null }.whenever(promoteWithBlazeCardBuilder)
.build(any())
doAnswer { if (isEligibleForDomainCard) dashboardDomainCard else null }.whenever(dashboardDomainCardBuilder)
.build(any())
return cardsBuilder.build(
dashboardCardsBuilderParams = DashboardCardsBuilderParams(
showErrorCard = showErrorCard,
Expand All @@ -249,7 +277,6 @@ class CardsBuilderTest : BaseUnitTest() {
dashboardCardDomainBuilderParams = DashboardCardDomainBuilderParams(
isEligibleForDomainCard, mock(), mock(), mock()
)

)
)
}
Expand Down