mirror of
https://github.com/anyproto/anytype-kotlin.git
synced 2025-06-08 05:47:05 +09:00
DROID-3629 Onboarding | Local mode status (#2400)
This commit is contained in:
parent
a52bd6f4ae
commit
9da4bc43b7
12 changed files with 212 additions and 20 deletions
|
@ -5,11 +5,14 @@ import androidx.lifecycle.ViewModelProvider
|
|||
import androidx.lifecycle.viewModelScope
|
||||
import com.anytypeio.anytype.analytics.base.Analytics
|
||||
import com.anytypeio.anytype.analytics.base.EventsDictionary
|
||||
import com.anytypeio.anytype.core_models.DeviceNetworkType
|
||||
import com.anytypeio.anytype.core_models.Id
|
||||
import com.anytypeio.anytype.core_models.NetworkModeConfig
|
||||
import com.anytypeio.anytype.core_models.NetworkMode
|
||||
import com.anytypeio.anytype.core_models.primitives.SpaceId
|
||||
import com.anytypeio.anytype.domain.auth.interactor.GetMnemonic
|
||||
import com.anytypeio.anytype.domain.config.ConfigStorage
|
||||
import com.anytypeio.anytype.domain.device.NetworkConnectionStatus
|
||||
import com.anytypeio.anytype.domain.network.NetworkModeProvider
|
||||
import com.anytypeio.anytype.presentation.extension.sendAnalyticsOnboardingClickEvent
|
||||
import com.anytypeio.anytype.presentation.extension.sendAnalyticsOnboardingScreenEvent
|
||||
import com.anytypeio.anytype.presentation.extension.sendOpenAccountEvent
|
||||
|
@ -22,7 +25,9 @@ import timber.log.Timber
|
|||
class OnboardingMnemonicViewModel @Inject constructor(
|
||||
private val getMnemonic: GetMnemonic,
|
||||
private val analytics: Analytics,
|
||||
private val configStorage: ConfigStorage
|
||||
private val configStorage: ConfigStorage,
|
||||
private val networkModeProvider: NetworkModeProvider,
|
||||
private val networkConnectionStatus: NetworkConnectionStatus
|
||||
) : ViewModel() {
|
||||
|
||||
val state = MutableStateFlow<State>(State.Idle(""))
|
||||
|
@ -128,9 +133,13 @@ class OnboardingMnemonicViewModel @Inject constructor(
|
|||
}
|
||||
}
|
||||
|
||||
private fun shouldShowEmail(): Boolean {
|
||||
//todo: update with Local Only config
|
||||
return true
|
||||
fun shouldShowEmail(): Boolean {
|
||||
val networkStatus = networkConnectionStatus.getCurrentNetworkType()
|
||||
if (networkStatus == DeviceNetworkType.NOT_CONNECTED) {
|
||||
Timber.i("Network is not connected, skipping email screen")
|
||||
return false
|
||||
}
|
||||
return networkModeProvider.get().networkMode != NetworkMode.LOCAL
|
||||
}
|
||||
|
||||
private suspend fun proceedWithMnemonicPhrase() {
|
||||
|
@ -156,13 +165,17 @@ class OnboardingMnemonicViewModel @Inject constructor(
|
|||
private val getMnemonic: GetMnemonic,
|
||||
private val analytics: Analytics,
|
||||
private val configStorage: ConfigStorage,
|
||||
private val networkModeProvider: NetworkModeProvider,
|
||||
private val networkConnectionStatus: NetworkConnectionStatus
|
||||
) : ViewModelProvider.Factory {
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
override fun <T : ViewModel> create(modelClass: Class<T>): T {
|
||||
return OnboardingMnemonicViewModel(
|
||||
getMnemonic = getMnemonic,
|
||||
analytics = analytics,
|
||||
configStorage = configStorage
|
||||
configStorage = configStorage,
|
||||
networkModeProvider = networkModeProvider,
|
||||
networkConnectionStatus = networkConnectionStatus
|
||||
) as T
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,145 @@
|
|||
package com.anytypeio.anytype.presentation.onboarding.signup
|
||||
|
||||
import com.anytypeio.anytype.analytics.base.Analytics
|
||||
import com.anytypeio.anytype.core_models.DeviceNetworkType
|
||||
import com.anytypeio.anytype.core_models.NetworkMode
|
||||
import com.anytypeio.anytype.core_models.NetworkModeConfig
|
||||
import com.anytypeio.anytype.domain.auth.interactor.GetMnemonic
|
||||
import com.anytypeio.anytype.domain.config.ConfigStorage
|
||||
import com.anytypeio.anytype.domain.device.NetworkConnectionStatus
|
||||
import com.anytypeio.anytype.domain.network.NetworkModeProvider
|
||||
import com.anytypeio.anytype.presentation.util.DefaultCoroutineTestRule
|
||||
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
||||
import org.junit.Assert.assertFalse
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Before
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import org.mockito.Mock
|
||||
import org.mockito.MockitoAnnotations
|
||||
import org.mockito.kotlin.stub
|
||||
|
||||
class OnboardingMnemonicViewModelTest {
|
||||
|
||||
@OptIn(ExperimentalCoroutinesApi::class)
|
||||
@get:Rule
|
||||
val coroutineTestRule = DefaultCoroutineTestRule()
|
||||
|
||||
@Mock
|
||||
private lateinit var getMnemonic: GetMnemonic
|
||||
|
||||
@Mock
|
||||
private lateinit var analytics: Analytics
|
||||
|
||||
@Mock
|
||||
private lateinit var configStorage: ConfigStorage
|
||||
|
||||
@Mock
|
||||
private lateinit var networkConnectionStatus: NetworkConnectionStatus
|
||||
|
||||
@Mock
|
||||
private lateinit var networkModeProvider: NetworkModeProvider
|
||||
|
||||
@Before
|
||||
fun setup() {
|
||||
MockitoAnnotations.openMocks(this)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `shouldShowEmail returns false when network is not connected`() {
|
||||
// Given
|
||||
networkConnectionStatus.stub {
|
||||
on { getCurrentNetworkType() }.thenReturn(DeviceNetworkType.NOT_CONNECTED)
|
||||
}
|
||||
networkModeProvider.stub {
|
||||
on { get() }.thenReturn(
|
||||
NetworkModeConfig(
|
||||
networkMode = NetworkMode.DEFAULT
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
// When
|
||||
val viewModel = createViewModel()
|
||||
val result = viewModel.shouldShowEmail()
|
||||
|
||||
// Then
|
||||
assertFalse(result)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `shouldShowEmail returns false when network mode is LOCAL`() {
|
||||
// Given
|
||||
networkConnectionStatus.stub {
|
||||
on { getCurrentNetworkType() }.thenReturn(DeviceNetworkType.WIFI)
|
||||
}
|
||||
networkModeProvider.stub {
|
||||
on { get() }.thenReturn(
|
||||
NetworkModeConfig(
|
||||
networkMode = NetworkMode.LOCAL
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
// When
|
||||
val viewModel = createViewModel()
|
||||
val result = viewModel.shouldShowEmail()
|
||||
|
||||
// Then
|
||||
assertFalse(result)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `shouldShowEmail returns true when connected to network and network mode is not LOCAL`() {
|
||||
// Given
|
||||
networkConnectionStatus.stub {
|
||||
on { getCurrentNetworkType() }.thenReturn(DeviceNetworkType.WIFI)
|
||||
}
|
||||
networkModeProvider.stub {
|
||||
on { get() }.thenReturn(
|
||||
NetworkModeConfig(
|
||||
networkMode = NetworkMode.DEFAULT
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
// When
|
||||
val viewModel = createViewModel()
|
||||
val result = viewModel.shouldShowEmail()
|
||||
|
||||
// Then
|
||||
assertTrue(result)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `shouldShowEmail returns true with cellular network and non-LOCAL mode`() {
|
||||
// Given
|
||||
networkConnectionStatus.stub {
|
||||
on { getCurrentNetworkType() }.thenReturn(DeviceNetworkType.CELLULAR)
|
||||
}
|
||||
networkModeProvider.stub {
|
||||
on { get() }.thenReturn(
|
||||
NetworkModeConfig(
|
||||
networkMode = NetworkMode.DEFAULT
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
// When
|
||||
val viewModel = createViewModel()
|
||||
val result = viewModel.shouldShowEmail()
|
||||
|
||||
// Then
|
||||
assertTrue(result)
|
||||
}
|
||||
|
||||
private fun createViewModel(): OnboardingMnemonicViewModel {
|
||||
return OnboardingMnemonicViewModel(
|
||||
getMnemonic = getMnemonic,
|
||||
analytics = analytics,
|
||||
configStorage = configStorage,
|
||||
networkModeProvider = networkModeProvider,
|
||||
networkConnectionStatus = networkConnectionStatus
|
||||
)
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue