Updated on 2026-08-14

This commit is contained in:
Tangem 2026-07-14 10:03:41 +02:00
parent 6de57d6545
commit 65d2e84c6e
4 changed files with 37 additions and 33 deletions

View file

@ -3,7 +3,7 @@ package com.tangem.features.addressbook.block.model
import com.tangem.core.decompose.di.ModelScoped
import com.tangem.core.decompose.model.Model
import com.tangem.core.decompose.model.ParamsContainer
import com.tangem.domain.addressbook.usecase.GetContactsUseCase
import com.tangem.domain.addressbook.interactor.GetVerifiedContactsInteractor
import com.tangem.domain.addressbook.usecase.SyncAddressBooksUseCase
import com.tangem.domain.wallets.usecase.GetWalletsUseCase
import com.tangem.features.addressbook.AddressBookContactsBlockComponent
@ -28,7 +28,7 @@ internal class ContactsBlockModel @Inject constructor(
private val stateController: ContactsBlockStateController,
private val analyticsSender: AddressBookAnalyticsSender,
private val syncAddressBooksUseCase: SyncAddressBooksUseCase,
getContactsUseCase: GetContactsUseCase,
getVerifiedContactsInteractor: GetVerifiedContactsInteractor,
getWalletsUseCase: GetWalletsUseCase,
) : Model() {
@ -41,7 +41,8 @@ internal class ContactsBlockModel @Inject constructor(
combine(
params.queryFlow.flatMapLatest { query ->
getContactsUseCase(query = query, userWalletId = null)
getVerifiedContactsInteractor.getVerifiedContacts(query = query, userWalletId = null)
.map { verified -> verified.map { it.contact } }
},
getWalletsUseCase.invokeAsMap(isOnlyMultiCurrency = false, filterLocked = true),
) { contacts, wallets -> contacts to wallets.values.toList() }

View file

@ -2,8 +2,8 @@ package com.tangem.features.addressbook.block.model
import com.google.common.truth.Truth.assertThat
import com.tangem.core.decompose.model.MutableParamsContainer
import com.tangem.domain.addressbook.interactor.GetVerifiedContactsInteractor
import com.tangem.domain.addressbook.model.*
import com.tangem.domain.addressbook.usecase.GetContactsUseCase
import com.tangem.domain.addressbook.usecase.SyncAddressBooksUseCase
import com.tangem.domain.models.account.CryptoPortfolioIcon
import com.tangem.domain.models.network.Network
@ -36,7 +36,7 @@ import org.junit.jupiter.api.TestInstance
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
internal class ContactsBlockModelTest {
private val getContactsUseCase: GetContactsUseCase = mockk()
private val getVerifiedContactsInteractor: GetVerifiedContactsInteractor = mockk()
private val getWalletsUseCase: GetWalletsUseCase = mockk()
private val syncAddressBooksUseCase: SyncAddressBooksUseCase = mockk(relaxed = true)
private val analyticsSender: AddressBookAnalyticsSender = mockk(relaxed = true)
@ -46,7 +46,7 @@ internal class ContactsBlockModelTest {
@BeforeEach
fun resetMocks() {
clearMocks(getContactsUseCase, getWalletsUseCase, analyticsSender)
clearMocks(getVerifiedContactsInteractor, getWalletsUseCase, analyticsSender)
every { getWalletsUseCase.invokeAsMap(isOnlyMultiCurrency = false, filterLocked = true) } returns
flowOf(linkedMapOf<UserWalletId, UserWallet>())
}
@ -60,8 +60,8 @@ internal class ContactsBlockModelTest {
@Test
fun `GIVEN matching contacts WHEN block populated THEN SendFlowWidgetShown sent once`() = runTest {
// Arrange
every { getContactsUseCase(query = any(), userWalletId = null) } returns
flowOf(listOf(contact(id = "1"), contact(id = "2")))
every { getVerifiedContactsInteractor.getVerifiedContacts(query = any(), userWalletId = null) } returns
flowOf(listOf(verified(id = "1"), verified(id = "2")))
// Act
createModel(testScope = this)
@ -74,7 +74,8 @@ internal class ContactsBlockModelTest {
@Test
fun `GIVEN no matching contacts WHEN block empty THEN SendFlowWidgetShown not sent`() = runTest {
// Arrange
every { getContactsUseCase(query = any(), userWalletId = null) } returns flowOf(emptyList())
every { getVerifiedContactsInteractor.getVerifiedContacts(query = any(), userWalletId = null) } returns
flowOf(emptyList())
// Act
val model = createModel(testScope = this)
@ -89,7 +90,8 @@ internal class ContactsBlockModelTest {
fun `GIVEN populated block WHEN contact tapped THEN ContactSelectedInSend sent AND click propagated`() = runTest {
// Arrange
var clicked: MatchedContact? = null
every { getContactsUseCase(query = any(), userWalletId = null) } returns flowOf(listOf(contact(id = "42")))
every { getVerifiedContactsInteractor.getVerifiedContacts(query = any(), userWalletId = null) } returns
flowOf(listOf(verified(id = "42")))
val model = createModel(testScope = this, onContactClick = { clicked = it })
advanceUntilIdle()
@ -101,6 +103,9 @@ internal class ContactsBlockModelTest {
assertThat(clicked?.contactId).isEqualTo("42")
}
private fun verified(id: String): VerifiedContact =
VerifiedContact(contact = contact(id = id), invalidEntries = emptyList())
private fun contact(id: String): Contact = Contact(
id = ContactId(id),
walletId = UserWalletId("a"),
@ -137,7 +142,7 @@ internal class ContactsBlockModelTest {
stateController = ContactsBlockStateController(),
analyticsSender = analyticsSender,
syncAddressBooksUseCase = syncAddressBooksUseCase,
getContactsUseCase = getContactsUseCase,
getVerifiedContactsInteractor = getVerifiedContactsInteractor,
getWalletsUseCase = getWalletsUseCase,
).also { model = it }
}