Skip to content

Commit

Permalink
Merge pull request #2 from openMF/development
Browse files Browse the repository at this point in the history
Refactor registration module (openMF#2633)
  • Loading branch information
Shermine237 authored Jul 1, 2024
2 parents bf62141 + 33ab709 commit 887864e
Show file tree
Hide file tree
Showing 30 changed files with 357 additions and 142 deletions.
8 changes: 3 additions & 5 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ dependencies {
implementation(projects.core.datastore)
implementation(projects.ui)
implementation(projects.feature.loan)

implementation(projects.feature.registration)
implementation(projects.feature.beneficiary)
implementation(projects.feature.guarantor)

Expand Down Expand Up @@ -150,7 +150,7 @@ dependencies {
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.4")
testImplementation("org.jetbrains.kotlinx:kotlinx-coroutines-test:1.7.3")

// Unit tests dependencies
// Unit tests dependencies
testImplementation(libs.junit)
testImplementation("org.mockito:mockito-core:5.4.0")
implementation("org.mockito:mockito-core:5.4.0")
Expand Down Expand Up @@ -200,6 +200,4 @@ dependencies {
implementation(libs.androidx.camera.lifecycle)
implementation(libs.androidx.camera.view)
implementation(libs.androidx.camera.core)
}


}
Original file line number Diff line number Diff line change
@@ -1,19 +1,36 @@
package org.mifos.mobile.ui.registration

import android.content.Intent
import android.os.Bundle
import org.mifos.mobile.R
import org.mifos.mobile.databinding.ActivityRegistrationBinding
import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
import androidx.navigation.compose.rememberNavController
import org.mifos.mobile.core.ui.theme.MifosMobileTheme
import org.mifos.mobile.feature.registration.navigation.RegistrationNavGraph
import org.mifos.mobile.feature.registration.navigation.RegistrationScreen
import org.mifos.mobile.ui.activities.base.BaseActivity
import org.mifos.mobile.ui.login.LoginActivity

class RegistrationActivity : BaseActivity() {

private lateinit var binding: ActivityRegistrationBinding

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = ActivityRegistrationBinding.inflate(layoutInflater)
setContentView(binding.root)
replaceFragment(RegistrationComposeFragment.newInstance(), false, R.id.container)
enableEdgeToEdge()
setContent {
MifosMobileTheme {
val navController = rememberNavController()
RegistrationNavGraph(
startDestination = RegistrationScreen.Registration.route,
navController = navController,
navigateBack = { this.finish() },
startLoginActivity = { startLoginActivity() }
)
}
}
}

private fun startLoginActivity()
{
this.startActivity(Intent(this, LoginActivity::class.java))
this.finish()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import org.mifos.mobile.core.ui.component.mifosComposeView
import org.mifos.mobile.ui.activities.base.BaseActivity
import org.mifos.mobile.ui.fragments.base.BaseFragment

/*
/**
* Created by dilpreet on 31/7/17.
*/
Expand All @@ -22,7 +23,7 @@ class RegistrationComposeFragment : BaseFragment() {
savedInstanceState: Bundle?,
): View {
return mifosComposeView(requireContext()) {
RegistrationScreen(
org.mifos.mobile.feature.registration.screens.RegistrationScreen(
onVerified = { showRegisteredSuccessfully() },
navigateBack = { activity?.onBackPressed() },
)
Expand All @@ -43,3 +44,4 @@ class RegistrationComposeFragment : BaseFragment() {
}
}
}
*/
Original file line number Diff line number Diff line change
@@ -1,25 +1,5 @@
package org.mifos.mobile.ui.registration

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.compose.ui.platform.ComposeView
import androidx.compose.ui.platform.ViewCompositionStrategy
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.lifecycleScope
import androidx.lifecycle.repeatOnLifecycle
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.launch
import org.mifos.mobile.R
import org.mifos.mobile.core.ui.theme.MifosMobileTheme
import org.mifos.mobile.ui.activities.base.BaseActivity
import org.mifos.mobile.ui.fragments.base.BaseFragment
import org.mifos.mobile.utils.PasswordStrength
import org.mifos.mobile.utils.RegistrationUiState
import org.mifos.mobile.utils.Toaster

/*
/**
* Created by dilpreet on 31/7/17.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.mifos.mobile.ui.registration

/*
import android.content.Intent
import android.os.Bundle
import android.view.LayoutInflater
Expand All @@ -21,8 +22,8 @@ class RegistrationVerificationComposeFragment : BaseFragment() {
savedInstanceState: Bundle?,
): View {
return mifosComposeView(requireContext()) {
RegistrationVerificationScreen(
navigateBack = { activity?.finish() } ,
org.mifos.mobile.feature.registration.screens.RegistrationVerificationScreen(
navigateBack = { activity?.finish() },
onVerified = {
startActivity(Intent(activity, LoginActivity::class.java))
activity?.finish()
Expand All @@ -36,3 +37,4 @@ class RegistrationVerificationComposeFragment : BaseFragment() {
}
}
}
*/
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import org.mifos.mobile.core.ui.component.MifosTopBar
import org.mifos.mobile.core.ui.theme.MifosMobileTheme
import org.mifos.mobile.ui.savings_account_withdraw.UiStatesParameterProvider
import org.mifos.mobile.core.common.Network
import org.mifos.mobile.utils.RegistrationUiState
import org.mifos.mobile.feature.registration.utils.RegistrationState


@Composable
Expand All @@ -49,7 +49,7 @@ fun UpdatePasswordScreen(

@Composable
fun UpdatePasswordScreen(
uiState: RegistrationUiState,
uiState: RegistrationState,
navigateBack: () -> Unit
) {
val context = LocalContext.current
Expand All @@ -76,15 +76,15 @@ fun UpdatePasswordScreen(
)

when (uiState) {
is RegistrationUiState.Loading -> {
is RegistrationState.Loading -> {
MifosProgressIndicator(
modifier = Modifier
.fillMaxSize()
.background(MaterialTheme.colorScheme.background.copy(0.8f))
)
}

is RegistrationUiState.Error -> {
is RegistrationState.Error -> {
if (updatePasswordButtonClicked) {
LaunchedEffect(snackbarHostState) {
snackbarHostState.showSnackbar(
Expand All @@ -96,9 +96,9 @@ fun UpdatePasswordScreen(
}
}

is RegistrationUiState.Initial -> Unit
is RegistrationState.Initial -> Unit

is RegistrationUiState.Success -> {
is RegistrationState.Success -> {
LaunchedEffect(snackbarHostState) {
snackbarHostState.showSnackbar(
context.getString(R.string.password_changed_successfully),
Expand All @@ -116,7 +116,7 @@ fun UpdatePasswordScreen(
@Composable
@Preview(showSystemUi = true, showBackground = true)
fun UpdatePasswordScreenPreview(
@PreviewParameter(UiStatesParameterProvider::class) registrationUiState: RegistrationUiState
@PreviewParameter(UiStatesParameterProvider::class) registrationUiState: RegistrationState
) {
MifosMobileTheme {
UpdatePasswordScreen(navigateBack = {})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
package org.mifos.mobile.ui.update_password

import android.content.Context
import androidx.compose.ui.res.stringResource
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import dagger.hilt.android.lifecycle.HiltViewModel
import dagger.hilt.android.qualifiers.ApplicationContext
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.catch
import kotlinx.coroutines.launch
import org.mifos.mobile.R
import org.mifos.mobile.core.data.repositories.ClientRepository
import org.mifos.mobile.core.data.repositories.UserAuthRepository
import org.mifos.mobile.utils.RegistrationUiState
import org.mifos.mobile.feature.registration.utils.RegistrationState
import javax.inject.Inject

@HiltViewModel
Expand All @@ -22,17 +19,17 @@ class UpdatePasswordViewModel @Inject constructor(
private val clientRepositoryImp: ClientRepository,
) : ViewModel() {

private val _updatePasswordUiState = MutableStateFlow<RegistrationUiState>(RegistrationUiState.Initial)
val updatePasswordUiState: StateFlow<RegistrationUiState> get() = _updatePasswordUiState
private val _updatePasswordUiState = MutableStateFlow<RegistrationState>(RegistrationState.Initial)
val updatePasswordUiState: StateFlow<RegistrationState> get() = _updatePasswordUiState

fun updateAccountPassword(newPassword: String, confirmPassword: String) {
viewModelScope.launch {
_updatePasswordUiState.value = RegistrationUiState.Loading
_updatePasswordUiState.value = RegistrationState.Loading
userAuthRepositoryImp.updateAccountPassword(newPassword, confirmPassword).catch {
_updatePasswordUiState.value =
RegistrationUiState.Error(R.string.could_not_update_password_error)
RegistrationState.Error(R.string.could_not_update_password_error)
}.collect {
_updatePasswordUiState.value = RegistrationUiState.Success
_updatePasswordUiState.value = RegistrationState.Success
clientRepositoryImp.updateAuthenticationToken(newPassword)
}
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package org.mifos.mobile.viewModels

import CoroutineTestRule
import androidx.arch.core.executor.testing.InstantTaskExecutorRule
import androidx.lifecycle.Observer
import app.cash.turbine.test
import junit.framework.TestCase.assertEquals
import kotlinx.coroutines.ExperimentalCoroutinesApi
Expand All @@ -11,15 +10,13 @@ import kotlinx.coroutines.test.runTest
import okhttp3.ResponseBody
import org.junit.*
import org.junit.runner.RunWith
import org.mifos.mobile.repositories.UserAuthRepository
import org.mifos.mobile.ui.registration.RegistrationViewModel
import org.mifos.mobile.core.data.repositories.UserAuthRepository
import org.mifos.mobile.util.RxSchedulersOverrideRule
import org.mifos.mobile.utils.RegistrationUiState
import org.mifos.mobile.feature.registration.utils.RegistrationState
import org.mockito.Mock
import org.mockito.Mockito
import org.mockito.MockitoAnnotations
import org.mockito.junit.MockitoJUnitRunner
import retrofit2.Response

@RunWith(MockitoJUnitRunner::class)
class RegistrationViewModelTest {
Expand All @@ -38,12 +35,15 @@ class RegistrationViewModelTest {
@Mock
lateinit var userAuthRepositoryImp: UserAuthRepository

private lateinit var registrationViewModel: RegistrationViewModel
private lateinit var registrationViewModel: org.mifos.mobile.feature.registration.viewmodel.RegistrationViewModel

@Before
fun setUp() {
MockitoAnnotations.openMocks(this)
registrationViewModel = RegistrationViewModel(userAuthRepositoryImp)
registrationViewModel =
org.mifos.mobile.feature.registration.viewmodel.RegistrationViewModel(
userAuthRepositoryImp
)

}

Expand Down Expand Up @@ -136,9 +136,9 @@ class RegistrationViewModelTest {
"password",
"username"
)
assertEquals(RegistrationUiState.Initial, awaitItem())
assertEquals(RegistrationUiState.Loading, awaitItem())
assertEquals(RegistrationUiState.Success, awaitItem())
assertEquals(RegistrationState.Initial, awaitItem())
assertEquals(RegistrationState.Loading, awaitItem())
assertEquals(RegistrationState.Success, awaitItem())
cancelAndIgnoreRemainingEvents()
}
}
Expand Down Expand Up @@ -169,9 +169,9 @@ class RegistrationViewModelTest {
"password",
"username"
)
assertEquals(RegistrationUiState.Initial, awaitItem())
assertEquals(RegistrationUiState.Loading, awaitItem())
assertEquals(RegistrationUiState.Error(0), awaitItem())
assertEquals(RegistrationState.Initial, awaitItem())
assertEquals(RegistrationState.Loading, awaitItem())
assertEquals(RegistrationState.Error(0), awaitItem())
cancelAndIgnoreRemainingEvents()
}
}
Expand All @@ -185,9 +185,9 @@ class RegistrationViewModelTest {

registrationViewModel.registrationVerificationUiState.test {
registrationViewModel.verifyUser("authenticationToken", "requestId")
assertEquals(RegistrationUiState.Initial,awaitItem())
assertEquals(RegistrationUiState.Loading,awaitItem())
assertEquals(RegistrationUiState.Success,awaitItem())
assertEquals(RegistrationState.Initial,awaitItem())
assertEquals(RegistrationState.Loading,awaitItem())
assertEquals(RegistrationState.Success,awaitItem())
cancelAndIgnoreRemainingEvents()
}
}
Expand All @@ -201,9 +201,9 @@ class RegistrationViewModelTest {
).thenThrow(errorResponse)
registrationViewModel.registrationVerificationUiState.test{
registrationViewModel.verifyUser("authenticationToken", "requestId")
assertEquals(RegistrationUiState.Initial,awaitItem())
assertEquals(RegistrationUiState.Loading,awaitItem())
assertEquals(RegistrationUiState.Error(0),awaitItem())
assertEquals(RegistrationState.Initial,awaitItem())
assertEquals(RegistrationState.Loading,awaitItem())
assertEquals(RegistrationState.Error(0),awaitItem())
cancelAndIgnoreRemainingEvents()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ import kotlinx.coroutines.runBlocking
import okhttp3.ResponseBody
import org.junit.*
import org.junit.runner.RunWith
import org.mifos.mobile.repositories.ClientRepository
import org.mifos.mobile.repositories.UserAuthRepository
import org.mifos.mobile.core.data.repositories.ClientRepository
import org.mifos.mobile.core.data.repositories.UserAuthRepository
import org.mifos.mobile.ui.update_password.UpdatePasswordViewModel
import org.mifos.mobile.util.RxSchedulersOverrideRule
import org.mifos.mobile.utils.RegistrationUiState
import org.mifos.mobile.feature.registration.utils.RegistrationState
import org.mockito.Mock
import org.mockito.Mockito
import org.mockito.MockitoAnnotations
Expand Down Expand Up @@ -93,9 +93,9 @@ class UpdatePasswordViewModelTest {
).thenReturn(flowOf(responseBody))
updatePasswordViewModel.updatePasswordUiState.test {
updatePasswordViewModel.updateAccountPassword("newPassword", "newPassword")
assertEquals(RegistrationUiState.Initial, awaitItem())
assertEquals(RegistrationUiState.Loading, awaitItem())
assertEquals(RegistrationUiState.Success, awaitItem())
assertEquals(RegistrationState.Initial, awaitItem())
assertEquals(RegistrationState.Loading, awaitItem())
assertEquals(RegistrationState.Success, awaitItem())
cancelAndIgnoreRemainingEvents()
}
}
Expand All @@ -108,9 +108,9 @@ class UpdatePasswordViewModelTest {

updatePasswordViewModel.updatePasswordUiState.test{
updatePasswordViewModel.updateAccountPassword("newPassword", "newPassword")
assertEquals(RegistrationUiState.Initial, awaitItem())
assertEquals(RegistrationUiState.Loading, awaitItem())
assertEquals(RegistrationUiState.Error(0), awaitItem())
assertEquals(RegistrationState.Initial, awaitItem())
assertEquals(RegistrationState.Loading, awaitItem())
assertEquals(RegistrationState.Error(0), awaitItem())
cancelAndIgnoreRemainingEvents()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,7 @@ object Constants {
const val GUARANTOR_LIST_SCREEN_ROUTE_BASE = "guarantor_list_screen"
const val GUARANTOR_DETAIL_SCREEN_ROUTE_BASE = "guarantor_detail_screen"
const val GUARANTOR_ADD_SCREEN_ROUTE_BASE = "guarantor_add_screen"

const val REGISTRATION_SCREEN_ROUTE_BASE = "registration_screen"
const val REGISTRATION_VERIFICATION_SCREEN_ROUTE_BASE = "registration_verification_screen"
}
Loading

0 comments on commit 887864e

Please sign in to comment.