Updated on 2026-08-14

This commit is contained in:
Tangem 2026-06-25 20:08:49 +05:00
parent 0939f4b85e
commit 0e382ab739
3 changed files with 91 additions and 5 deletions

View file

@ -2,6 +2,13 @@ package com.tangem.feature.wallet.presentation.wallet.domain
import arrow.core.Either
import com.google.common.truth.Truth.assertThat
import com.tangem.domain.account.models.AccountStatusList
import com.tangem.domain.account.status.producer.SingleAccountStatusListProducer
import com.tangem.domain.account.status.supplier.SingleAccountStatusListSupplier
import com.tangem.domain.models.StatusSource
import com.tangem.domain.models.TokensGroupType
import com.tangem.domain.models.TokensSortType
import com.tangem.domain.models.TotalFiatBalance
import com.tangem.domain.models.wallet.UserWallet
import com.tangem.domain.models.wallet.UserWalletId
import com.tangem.domain.notifications.repository.NotificationsRepository
@ -25,6 +32,7 @@ import org.junit.jupiter.api.Test
import org.junit.jupiter.api.TestInstance
import org.junit.jupiter.params.ParameterizedTest
import org.junit.jupiter.params.provider.MethodSource
import java.math.BigDecimal
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
internal class GetWalletNotificationsCarouselFactoryTest {
@ -35,6 +43,7 @@ internal class GetWalletNotificationsCarouselFactoryTest {
private val shouldShowYieldBoostMainBannerUseCase: ShouldShowYieldBoostMainBannerUseCase = mockk()
private val yieldSupplyGetShouldShowMainPromoUseCase: YieldSupplyGetShouldShowMainPromoUseCase = mockk()
private val yieldSupplyFeatureToggles: YieldSupplyFeatureToggles = mockk()
private val singleAccountStatusListSupplier: SingleAccountStatusListSupplier = mockk(relaxed = true)
private val clickIntents: WalletClickIntents = mockk(relaxed = true)
private val userWallet: UserWallet.Hot = mockk(relaxed = true)
@ -45,6 +54,7 @@ internal class GetWalletNotificationsCarouselFactoryTest {
shouldShowYieldBoostMainBannerUseCase = shouldShowYieldBoostMainBannerUseCase,
yieldSupplyGetShouldShowMainPromoUseCase = yieldSupplyGetShouldShowMainPromoUseCase,
yieldSupplyFeatureToggles = yieldSupplyFeatureToggles,
singleAccountStatusListSupplier = singleAccountStatusListSupplier,
)
@BeforeEach
@ -56,6 +66,7 @@ internal class GetWalletNotificationsCarouselFactoryTest {
shouldShowYieldBoostMainBannerUseCase,
yieldSupplyGetShouldShowMainPromoUseCase,
yieldSupplyFeatureToggles,
singleAccountStatusListSupplier,
clickIntents,
userWallet,
)
@ -68,6 +79,10 @@ internal class GetWalletNotificationsCarouselFactoryTest {
every { yieldSupplyGetShouldShowMainPromoUseCase() } returns flowOf(true)
every { yieldSupplyFeatureToggles.isYieldPromoEnabled } returns true
coEvery { shouldShowYieldBoostMainBannerUseCase(any()) } returns Either.Right(true)
// Balance is loaded by default, so banners gated on balance are not suppressed.
every {
singleAccountStatusListSupplier(any<SingleAccountStatusListProducer.Params>())
} returns flowOf(accountStatusList(TotalFiatBalance.Loaded(BigDecimal.ZERO, StatusSource.ACTUAL)))
}
@ParameterizedTest
@ -85,6 +100,24 @@ internal class GetWalletNotificationsCarouselFactoryTest {
assertThat(result.any { it is WalletNotificationUM.YieldBoostPromo }).isEqualTo(model.expectedShown)
}
@ParameterizedTest
@MethodSource("provideRateAppTestModels")
fun `GIVEN ready to show rate app and balance state WHEN create THEN rate app banner visibility matches`(
model: RateAppModel,
) = runTest {
// Arrange
every { isReadyToShowRateAppUseCase() } returns flowOf(model.isReadyToShow)
every {
singleAccountStatusListSupplier(any<SingleAccountStatusListProducer.Params>())
} returns flowOf(accountStatusList(model.balance))
// Act
val result = factory.create(userWallet, clickIntents).first()
// Assert
assertThat(result.any { it is WalletNotificationUM.RateApp }).isEqualTo(model.expectedShown)
}
@Test
fun `GIVEN banner shown WHEN buttons clicked THEN routes to click intents`() = runTest {
// Arrange
@ -101,6 +134,16 @@ internal class GetWalletNotificationsCarouselFactoryTest {
verify { clickIntents.onDismissYieldBoostBanner(WALLET_ID) }
}
private fun accountStatusList(balance: TotalFiatBalance) = AccountStatusList(
userWalletId = WALLET_ID,
accountStatuses = emptyList(),
totalAccounts = 0,
totalArchivedAccounts = 0,
totalFiatBalance = balance,
sortType = TokensSortType.NONE,
groupType = TokensGroupType.NONE,
)
internal data class Model(
val toggleEnabled: Boolean,
val shouldShowLocal: Boolean,
@ -121,6 +164,31 @@ internal class GetWalletNotificationsCarouselFactoryTest {
),
)
internal data class RateAppModel(
val isReadyToShow: Boolean,
val balance: TotalFiatBalance,
val expectedShown: Boolean,
)
private fun provideRateAppTestModels() = listOf(
// Ready to show, but the balance is still loading — don't flash before Add Funds may appear.
RateAppModel(isReadyToShow = true, balance = TotalFiatBalance.Loading, expectedShown = false),
// Ready to show and the balance is loaded — the banner can appear.
RateAppModel(
isReadyToShow = true,
balance = TotalFiatBalance.Loaded(BigDecimal.ZERO, StatusSource.ACTUAL),
expectedShown = true,
),
// Ready to show and the balance failed — terminal state, only loading suppresses the banner.
RateAppModel(isReadyToShow = true, balance = TotalFiatBalance.Failed, expectedShown = true),
// Not ready to show — the banner stays hidden regardless of the balance state.
RateAppModel(
isReadyToShow = false,
balance = TotalFiatBalance.Loaded(BigDecimal.ZERO, StatusSource.ACTUAL),
expectedShown = false,
),
)
private companion object {
val WALLET_ID = UserWalletId("01")
}