From 415d680b89d649e3648ef5e4c0a10248ba6c9528 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Miguel=20Rubio?= Date: Wed, 30 Nov 2022 22:26:59 +0100 Subject: [PATCH] Androapp5035 edit stock (#27) * ANDROAPP-4900 Integrate RTSM module into capture app * Fixing exported in debug manifests Fixing exported in debug manifests * update dependencies and check styles * kotlin check style * Androapp 4915 Link RSTM module with current test program * Removing RecentActivity section xml code from HomeActivity * Removing RecentActivity Code code from HomeActivity * Removing RecentActivity Code from HomeViewModel.kt * Removing data persistent package and it's files * Removed this package files * Removing imports * Removinf imports from HomeViewModel * Removed imports * Removing un necessary usages. * Delete RecentActivityAdapter * Removing all code inside dtabaseModule * Deliting no used functions * Remove un necessary code * Delete DatabaseModule.kt * Update paperwork.json * Removing room libraries * Removing TypeConverter Annotation * Update paperwork.json * Removing room compile Options annotation * Update paperwork.json * Update paperwork.json * kotlin check style * Update dhis2-android-sdk * Adding variables inside homeActivity xml file * Adding new topbar to all activity_home.xml files * Update strings.xml * Adding variables * Impoting variables * Update HomeActivity.java * Update paperwork.json * Create ic_filter.xml * Call Settings Activity * Update paperwork.json * Setting title and subtitle * Set title on select DestributionType * Update paperwork.json * Adding from and to Strings. I have added this only in the main strings.xm file. So you i did't dothe transactions. * Adding Topbar logic usecase according to selected TransactionType * Update paperwork.json * Update HomeActivity.java * Update paperwork.json * Changing subtitle font size * change status bar color dynamically * Update paperwork.json * Update dhis2-android-sdk * Update paperwork.json * Adding title and subTitle Variables. * Adding title and subtile variables and removing commented code. * Removing theme variable * Removing theme variable * Removing theme variable * Removing setTitle and Subtitle Method * Create method to set title on Toolbar * Binding data from HomeViewmodel to activity_home.xml file * inding data from HomeViewModel to activity_home.xml files * Update paperwork.json * Add data dynamically to android studio * Adding method to set subtitle * Removing methods from HomeActivity * Update paperwork.json * Removing not used variables * Update HomeViewModel.kt * Update paperwork.json * Update HomeViewModel.kt * Implement back buttton. * Status bar color changing support from API 21+ * Update paperwork.json * Update dhis2-android-sdk * Correting title on toolbar click sequence * Update HomeViewModel.kt * Update paperwork.json * Test: Toolbar on title change * Update dhis2-android-sdk * Test: Toolbar on subtitle change * Androapp 4924 (#7) * update SDK * Create android.yml (#8) * setup ci (#9) * Fix item list layout * Fix imports on ProgramFragment.kt * Androapp 4930 (#12) ANDROAPP-4930 Replace Sync button behaviour * Androapp 4923 (#11) Settings section new layout * Sync develop (#15) * Androapp 4955 (#13) App bar design review * fix GranularSyncPresenterImpl.kt test * Androapp 4953 (#14) * Androapp 5000 (#16) Create DataentryFragment * Androapp 5025 (#17) Move Search box and scan code buttons to Dataentry section * Androapp 4925 (#18) * Implement table structure for data entry * Initialize ManageStockViewModel.kt to get data entry into table * stock table label * update * loading ManageStockViewModel.kt for data entry * building table for data entry * updade * Removing initialization by SavedStateHandle, removing init method to initialize data * Resolving merge * Resolving code style * update * update * adding test dependency * resolving tests * update * resolving code style * resolving manage stock view model unit test * initializing transaction * update * resolving code style * removing stock management * Insert table into main content * moving table, methods and removing unnecessary vars * fixing code style * removing form dependency * removing hardcoded appconfig * removing commend and make proceed button go to review * resolving code style * Changing text color * calling mdc theme as parent of the tree component * moving mapTableModel to ManageStockViewModel.kt * implementing mapTableModel to ManageStockViewModel.kt * Removing mdctheme * Resolving code style * Androapp 5036 (#19) Implement search * ANDROAPP-4900 Integrate RTSM module into capture app * Fixing exported in debug manifests Fixing exported in debug manifests * update dependencies and check styles * kotlin check style * Androapp 4915 Link RSTM module with current test program * Removing RecentActivity section xml code from HomeActivity * Removing RecentActivity Code code from HomeActivity * Removing RecentActivity Code from HomeViewModel.kt * Removing data persistent package and it's files * Removed this package files * Removing imports * Removinf imports from HomeViewModel * Removed imports * Removing un necessary usages. * Delete RecentActivityAdapter * Removing all code inside dtabaseModule * Deliting no used functions * Remove un necessary code * Delete DatabaseModule.kt * Update paperwork.json * Removing room libraries * Removing TypeConverter Annotation * Update paperwork.json * Removing room compile Options annotation * Update paperwork.json * Update paperwork.json * kotlin check style * Adding variables inside homeActivity xml file * Adding new topbar to all activity_home.xml files * Update strings.xml * Adding variables * Impoting variables * Update HomeActivity.java * Update paperwork.json * Create ic_filter.xml * Call Settings Activity * Update paperwork.json * Setting title and subtitle * Set title on select DestributionType * Update paperwork.json * Adding from and to Strings. I have added this only in the main strings.xm file. So you i did't dothe transactions. * Adding Topbar logic usecase according to selected TransactionType * Update paperwork.json * Update HomeActivity.java * Update paperwork.json * Changing subtitle font size * Update paperwork.json * change status bar color dynamically * Update paperwork.json * Adding title and subTitle Variables. * Adding title and subtile variables and removing commented code. * Removing theme variable * Removing theme variable * Removing theme variable * Removing setTitle and Subtitle Method * Create method to set title on Toolbar * Binding data from HomeViewmodel to activity_home.xml file * inding data from HomeViewModel to activity_home.xml files * Update paperwork.json * Add data dynamically to android studio * Adding method to set subtitle * Removing methods from HomeActivity * Update paperwork.json * Removing not used variables * Update HomeViewModel.kt * Update paperwork.json * Update HomeViewModel.kt * Implement back buttton. * Update paperwork.json * Status bar color changing support from API 21+ * Correting title on toolbar click sequence * Update HomeViewModel.kt * Update paperwork.json * Test: Toolbar on title change * Test: Toolbar on subtitle change * Androapp 4924 (#7) * Create android.yml (#8) * setup ci (#9) * Fix item list layout * Fix imports on ProgramFragment.kt * Androapp 4930 (#12) ANDROAPP-4930 Replace Sync button behaviour * Androapp 4923 (#11) Settings section new layout * Sync develop (#15) * Androapp 4955 (#13) App bar design review * fix GranularSyncPresenterImpl.kt test * Androapp 4953 (#14) * Androapp 5000 (#16) Create DataentryFragment * Androapp 5025 (#17) Move Search box and scan code buttons to Dataentry section * Androapp 4925 (#18) * Implement table structure for data entry * Initialize ManageStockViewModel.kt to get data entry into table * stock table label * update * loading ManageStockViewModel.kt for data entry * building table for data entry * updade * Removing initialization by SavedStateHandle, removing init method to initialize data * Resolving merge * Resolving code style * update * update * adding test dependency * resolving tests * update * resolving code style * resolving manage stock view model unit test * initializing transaction * update * resolving code style * removing stock management * Insert table into main content * moving table, methods and removing unnecessary vars * fixing code style * removing form dependency * removing hardcoded appconfig * removing commend and make proceed button go to review * resolving code style * Changing text color * calling mdc theme as parent of the tree component * moving mapTableModel to ManageStockViewModel.kt * implementing mapTableModel to ManageStockViewModel.kt * Removing mdctheme * Resolving code style * Androapp 5036 (#19) Implement search * update table usage * Androapp 5037 (#21) Implement scan button * adding testing credentials to lmis * fix code style * implementing data entry * Adding Verifications to solve table colors (#22) Correct table color * implementing data entry: test * creating state for table data entry * implementing screen state and stock item load * feat: [ANDROAPP-4919] Remove SDK submodule and use LMIS SNAPSHOT * Implementing data entry with item cache stored: blocked * fixing merge conflicts * stock items * when user finish edition apply program rules * Set title and subtitle on input field * Implementing conceal backdrop when cell is clicked and table error management * code style format * unused var * code style format (removing comma) * code style format * refactoring table error handler * refactoring table on edit cell * refactoring table on edit cell to conceal backdrop * code style check * [ANDROAPP-5035] avoid crash on backdrop Co-authored-by: Miguel Vasco Macamo Co-authored-by: Carlos Macaneta <56470814+CarlosMacaneta@users.noreply.github.com> Co-authored-by: Carlos Macaneta Co-authored-by: andresmr --- app/src/main/assets/paperwork.json | 2 +- stock-managment/src/main/AndroidManifest.xml | 9 +- .../android/rtsm/ui/home/HomeActivity.kt | 2 +- .../screens/components/BackdropComponent.kt | 1 - .../ui/home/screens/components/MainContent.kt | 14 +- .../ui/managestock/ManageStockViewModel.kt | 184 +++++++++++++++--- .../components/ManageStockTable.kt | 43 ++-- .../viewmodels/ManageStockViewModelTest.kt | 53 ++--- 8 files changed, 203 insertions(+), 105 deletions(-) diff --git a/app/src/main/assets/paperwork.json b/app/src/main/assets/paperwork.json index 490e54086d..4a76ad19ee 100644 --- a/app/src/main/assets/paperwork.json +++ b/app/src/main/assets/paperwork.json @@ -1 +1 @@ -{"buildTime":"2022-11-29 16:42","gitSha":"9b13dc04d"} \ No newline at end of file +{"buildTime":"2022-11-30 14:55","gitSha":"502a8af8a"} \ No newline at end of file diff --git a/stock-managment/src/main/AndroidManifest.xml b/stock-managment/src/main/AndroidManifest.xml index 1da4e52fbf..4aa1ac0c9b 100644 --- a/stock-managment/src/main/AndroidManifest.xml +++ b/stock-managment/src/main/AndroidManifest.xml @@ -29,16 +29,11 @@ - + android:configChanges="keyboardHidden|orientation|screenSize" + android:windowSoftInputMode="adjustResize" /> navigateToReviewStock(scope, scaffold) } + ::navigateToReviewStock ) { scope, scaffold -> synchronizeData( scope, diff --git a/stock-managment/src/main/java/org/dhis2/android/rtsm/ui/home/screens/components/BackdropComponent.kt b/stock-managment/src/main/java/org/dhis2/android/rtsm/ui/home/screens/components/BackdropComponent.kt index 56909bc007..b2b16235b0 100644 --- a/stock-managment/src/main/java/org/dhis2/android/rtsm/ui/home/screens/components/BackdropComponent.kt +++ b/stock-managment/src/main/java/org/dhis2/android/rtsm/ui/home/screens/components/BackdropComponent.kt @@ -96,7 +96,6 @@ fun Backdrop( manageStockViewModel, hasFacilitySelected, hasDestinationSelected, - homeContext, barcodeLauncher ) }, diff --git a/stock-managment/src/main/java/org/dhis2/android/rtsm/ui/home/screens/components/MainContent.kt b/stock-managment/src/main/java/org/dhis2/android/rtsm/ui/home/screens/components/MainContent.kt index b3ffa91bc6..f3dca15855 100644 --- a/stock-managment/src/main/java/org/dhis2/android/rtsm/ui/home/screens/components/MainContent.kt +++ b/stock-managment/src/main/java/org/dhis2/android/rtsm/ui/home/screens/components/MainContent.kt @@ -47,7 +47,6 @@ import com.journeyapps.barcodescanner.ScanOptions import kotlinx.coroutines.launch import org.dhis2.android.rtsm.R import org.dhis2.android.rtsm.data.TransactionType -import org.dhis2.android.rtsm.ui.home.HomeActivity import org.dhis2.android.rtsm.ui.home.HomeViewModel import org.dhis2.android.rtsm.ui.managestock.ManageStockViewModel import org.dhis2.android.rtsm.ui.managestock.components.ManageStockTable @@ -63,7 +62,6 @@ fun MainContent( manageStockViewModel: ManageStockViewModel, hasFacilitySelected: Boolean, hasDestinationSelected: Boolean?, - homeContext: HomeActivity, barcodeLauncher: ActivityResultLauncher ) { val scope = rememberCoroutineScope() @@ -206,21 +204,27 @@ fun MainContent( ) { if (hasFacilitySelected && hasDestinationSelected == true) { updateTableState(manageStockViewModel, viewModel) - ManageStockTable(manageStockViewModel) + ManageStockTable(manageStockViewModel) { + scope.launch { backdropState.conceal() } + } } } else if (viewModel.toolbarTitle.collectAsState().value.name == TransactionType.CORRECTION.name ) { if (hasFacilitySelected) { updateTableState(manageStockViewModel, viewModel) - ManageStockTable(manageStockViewModel) + ManageStockTable(manageStockViewModel) { + scope.launch { backdropState.conceal() } + } } } else if (viewModel.toolbarTitle.collectAsState().value.name == TransactionType.DISCARD.name ) { if (hasFacilitySelected) { updateTableState(manageStockViewModel, viewModel) - ManageStockTable(manageStockViewModel) + ManageStockTable(manageStockViewModel) { + scope.launch { backdropState.conceal() } + } } } } diff --git a/stock-managment/src/main/java/org/dhis2/android/rtsm/ui/managestock/ManageStockViewModel.kt b/stock-managment/src/main/java/org/dhis2/android/rtsm/ui/managestock/ManageStockViewModel.kt index ea7acddad6..cd52a5b9f2 100644 --- a/stock-managment/src/main/java/org/dhis2/android/rtsm/ui/managestock/ManageStockViewModel.kt +++ b/stock-managment/src/main/java/org/dhis2/android/rtsm/ui/managestock/ManageStockViewModel.kt @@ -2,7 +2,6 @@ package org.dhis2.android.rtsm.ui.managestock import androidx.lifecycle.LiveData import androidx.lifecycle.MutableLiveData -import androidx.lifecycle.SavedStateHandle import androidx.lifecycle.Transformations import androidx.lifecycle.asFlow import androidx.lifecycle.viewModelScope @@ -14,6 +13,8 @@ import java.util.Collections import java.util.Date import java.util.concurrent.TimeUnit import javax.inject.Inject +import kotlinx.coroutines.flow.MutableStateFlow +import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.launch import org.dhis2.android.rtsm.R import org.dhis2.android.rtsm.commons.Constants.QUANTITY_ENTRY_DEBOUNCE @@ -33,8 +34,10 @@ import org.dhis2.android.rtsm.services.rules.RuleValidationHelper import org.dhis2.android.rtsm.services.scheduler.BaseSchedulerProvider import org.dhis2.android.rtsm.ui.base.ItemWatcher import org.dhis2.android.rtsm.ui.base.SpeechRecognitionAwareViewModel +import org.dhis2.android.rtsm.utils.Utils.Companion.isValidStockOnHand import org.dhis2.commons.resources.ResourceManager import org.dhis2.composetable.TableScreenState +import org.dhis2.composetable.model.KeyboardInputType import org.dhis2.composetable.model.RowHeader import org.dhis2.composetable.model.TableCell import org.dhis2.composetable.model.TableHeader @@ -42,12 +45,13 @@ import org.dhis2.composetable.model.TableHeaderCell import org.dhis2.composetable.model.TableHeaderRow import org.dhis2.composetable.model.TableModel import org.dhis2.composetable.model.TableRowModel +import org.dhis2.composetable.model.TextInputModel +import org.hisp.dhis.rules.models.RuleActionAssign +import org.hisp.dhis.rules.models.RuleEffect import org.jetbrains.annotations.NotNull -import org.jetbrains.annotations.Nullable @HiltViewModel class ManageStockViewModel @Inject constructor( - savedState: SavedStateHandle, private val disposable: CompositeDisposable, private val schedulerProvider: BaseSchedulerProvider, preferenceProvider: PreferenceProvider, @@ -76,23 +80,29 @@ class ManageStockViewModel @Inject constructor( val operationState: LiveData>>> get() = _networkState + private val _allTableState = MutableStateFlow>(mutableListOf()) + private val allTableState: StateFlow> = _allTableState + private val _screenState: MutableLiveData = MutableLiveData( TableScreenState(emptyList(), false) ) val screenState: LiveData = _screenState + private val _stockItems: MutableLiveData> = + MutableLiveData>() + fun setup(transaction: Transaction) { _transaction.value = transaction configureRelays() loadStockItems() - refreshData() } fun refreshData() { viewModelScope.launch { getStockItems().asFlow().collect { + _stockItems.value = it tableRowData( it, resources.getString(R.string.stock), @@ -193,19 +203,25 @@ class ManageStockViewModel @Inject constructor( row = index ), values = mapOf( - 0 to TableCell( - id = item.id, - row = index, - column = 0, - editable = false, - value = item.stockOnHand + Pair( + 0, + TableCell( + id = item.id, + row = index, + column = 0, + editable = false, + value = item.stockOnHand + ) ), - 1 to TableCell( - id = item.id, - row = index, - column = 1, - value = null, - editable = true + Pair( + 1, + TableCell( + id = item.id, + row = index, + column = 1, + value = null, + editable = true + ) ) ), maxLines = 3 @@ -214,12 +230,14 @@ class ManageStockViewModel @Inject constructor( tableRowModels.add(tableRowModel) } + _allTableState.value = mapTableModel( + tableRowModels, + stockLabel, + qtdLabel + ) + _screenState.value = TableScreenState( - tables = mapTableModel( - tableRowModels, - stockLabel, - qtdLabel - ), + tables = allTableState.value, selectNext = false ) } @@ -245,6 +263,128 @@ class ManageStockViewModel @Inject constructor( ) ) + fun onCellValueChanged(tableCell: TableCell) { + val updatedData = screenState.value?.tables?.map { tableModel -> + if (tableModel.hasCellWithId(tableCell.id)) { + tableModel.copy( + overwrittenValues = mapOf( + Pair(tableCell.column!!, tableCell) + ) + ) + } else { + tableModel + } + } ?: emptyList() + + _screenState.postValue( + TableScreenState( + tables = updatedData, + selectNext = false + ) + ) + } + + fun onCellClick(cell: TableCell): TextInputModel { + val stockItem = _stockItems.value?.find { it.id == cell.id } + val itemName = stockItem?.name ?: "" + return TextInputModel( + id = cell.id ?: "", + mainLabel = itemName, + secondaryLabels = mutableListOf(resources.getString(R.string.quantity)), + currentValue = cell.value, + keyboardInputType = KeyboardInputType.NumericInput( + allowDecimal = false, + allowSigned = false + ) + ) + } + + fun onSaveValueChange( + cell: TableCell, + selectNext: Boolean + ) { + // When user taps on done or next. We should apply program rules here + val stockItem = _stockItems.value?.find { it.id == cell.id } + stockItem?.let { + cell.value?.let { value -> + setQuantity( + it, 0, value, + object : ItemWatcher.OnQuantityValidated { + override fun validationCompleted(ruleEffects: List) { + // Update fields + ruleEffects.forEach { ruleEffect -> + if (ruleEffect.ruleAction() is RuleActionAssign && + ( + (ruleEffect.ruleAction() as RuleActionAssign).field() + == config.value?.stockOnHand + ) + ) { + val data = ruleEffect.data() + val isValid: Boolean = isValidStockOnHand(data) + val stockOnHand = if (isValid) data else it.stockOnHand + addItem(it, cell.value, stockOnHand, !isValid) + + _allTableState.value = _allTableState.value.map { tableModel -> + tableModel.copy( + tableRows = updateTableRows(tableModel.tableRows, cell) + ) + } + } + } + + _screenState.postValue( + TableScreenState( + tables = allTableState.value, + selectNext = selectNext + ) + ) + } + } + ) + } + } + } + + private fun updateTableRows( + tableRowModels: List, + cell: TableCell + ): List { + return tableRowModels.map { tableRowModel -> + if (tableRowModel.values.values.find { tableCell -> + tableCell.id == cell.id + } != null + ) { + tableRowModel.copy( + values = updateTableCells(tableRowModel.values, cell) + ) + } else { + tableRowModel + } + } + } + + private fun updateTableCells( + tableCells: Map, + cell: TableCell + ): Map { + val stockEntry = getPopulatedEntries().find { it.item.id == cell.id } + return tableCells.mapValues { (index, tableCell) -> + when (index) { + 0 -> tableCell.copy( + value = stockEntry?.stockOnHand + ) + else -> tableCell.copy( + value = stockEntry?.qty, + error = if (stockEntry?.hasError == true) { + resources.getString(R.string.stock_on_hand_exceeded_message) + } else { + null + } + ) + } + } + } + fun onSearchQueryChanged(query: String) { searchRelay.accept(query) } @@ -257,7 +397,7 @@ class ManageStockViewModel @Inject constructor( item: @NotNull StockItem, position: @NotNull Int, qty: @NotNull String, - callback: @Nullable ItemWatcher.OnQuantityValidated? + callback: ItemWatcher.OnQuantityValidated? ) { entryRelay.accept(RowAction(StockEntry(item, qty), position, callback)) } diff --git a/stock-managment/src/main/java/org/dhis2/android/rtsm/ui/managestock/components/ManageStockTable.kt b/stock-managment/src/main/java/org/dhis2/android/rtsm/ui/managestock/components/ManageStockTable.kt index e00a595db8..c70e516307 100644 --- a/stock-managment/src/main/java/org/dhis2/android/rtsm/ui/managestock/components/ManageStockTable.kt +++ b/stock-managment/src/main/java/org/dhis2/android/rtsm/ui/managestock/components/ManageStockTable.kt @@ -1,55 +1,40 @@ package org.dhis2.android.rtsm.ui.managestock.components -import android.content.Context import androidx.compose.runtime.Composable import androidx.compose.runtime.getValue import androidx.compose.runtime.livedata.observeAsState -import androidx.compose.ui.platform.LocalContext import com.google.android.material.composethemeadapter.MdcTheme import org.dhis2.android.rtsm.ui.managestock.ManageStockViewModel -import org.dhis2.composetable.model.KeyboardInputType -import org.dhis2.composetable.model.TableCell -import org.dhis2.composetable.model.TextInputModel import org.dhis2.composetable.ui.DataSetTableScreen @Composable fun ManageStockTable( - viewModel: ManageStockViewModel + viewModel: ManageStockViewModel, + concealBackdropState: () -> Unit ) { - val context = LocalContext.current val screenState by viewModel.screenState.observeAsState() MdcTheme { DataSetTableScreen( tableScreenState = screenState!!, onCellClick = { _, cell -> - onCellClick(cell) + viewModel.onCellClick(cell) }, onEdition = { isEditing -> - editingCellValue(context, isEditing) + editingCellValue(isEditing, concealBackdropState) }, - onCellValueChange = { cell -> - onCellValueChanged(cell) - }, - onSaveValue = { cell, _ -> - onSaveValueChange(cell) - } + onCellValueChange = viewModel::onCellValueChanged, + onSaveValue = viewModel::onSaveValueChange ) } } -fun editingCellValue(context: Context, editing: Boolean) {} - -fun onCellClick(cell: TableCell): TextInputModel { - return TextInputModel( - id = cell.id!!, - mainLabel = "Quantity", - currentValue = cell.value, - keyboardInputType = KeyboardInputType.NumericInput( - allowDecimal = false, - allowSigned = false - ) - ) +fun editingCellValue( + editing: Boolean, + onEditionStart: () -> Unit +) { + // TODO Hide review button + if (editing) { + onEditionStart.invoke() + } } -fun onCellValueChanged(tableCell: TableCell) {} -fun onSaveValueChange(cell: TableCell) {} diff --git a/stock-managment/src/test/java/org/dhis2/android/rtsm/viewmodels/ManageStockViewModelTest.kt b/stock-managment/src/test/java/org/dhis2/android/rtsm/viewmodels/ManageStockViewModelTest.kt index 68f3c2a17b..799e31efa6 100644 --- a/stock-managment/src/test/java/org/dhis2/android/rtsm/viewmodels/ManageStockViewModelTest.kt +++ b/stock-managment/src/test/java/org/dhis2/android/rtsm/viewmodels/ManageStockViewModelTest.kt @@ -1,14 +1,11 @@ package org.dhis2.android.rtsm.viewmodels import androidx.arch.core.executor.testing.InstantTaskExecutorRule -import androidx.lifecycle.SavedStateHandle import com.github.javafaker.Faker import io.reactivex.disposables.CompositeDisposable import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.test.runTest import org.dhis2.android.rtsm.MainDispatcherRule -import org.dhis2.android.rtsm.commons.Constants.INTENT_EXTRA_APP_CONFIG -import org.dhis2.android.rtsm.commons.Constants.INTENT_EXTRA_TRANSACTION import org.dhis2.android.rtsm.data.AppConfig import org.dhis2.android.rtsm.data.DestinationFactory import org.dhis2.android.rtsm.data.FacilityFactory @@ -72,25 +69,15 @@ class ManageStockViewModelTest { private val resourceManager: ResourceManager = mock() - private fun getStateHandle(transaction: Transaction): SavedStateHandle { - val state = hashMapOf( - INTENT_EXTRA_TRANSACTION to transaction, - INTENT_EXTRA_APP_CONFIG to appConfig - ) - return SavedStateHandle(state) - } - - private fun getModel(transaction: Transaction) = - ManageStockViewModel( - getStateHandle(transaction), - disposable, - schedulerProvider, - preferenceProvider, - stockManager, - ruleValidationHelperImpl, - speechRecognitionManagerImpl, - resourceManager - ) + private fun getModel() = ManageStockViewModel( + disposable, + schedulerProvider, + preferenceProvider, + stockManager, + ruleValidationHelperImpl, + speechRecognitionManagerImpl, + resourceManager + ) private fun createStockEntry(uid: String) = StockItem( uid, faker.name().name(), faker.number().numberBetween(1, 800).toString() @@ -142,7 +129,7 @@ class ManageStockViewModelTest { transactionDate = transactionDate, distributedTo = distributedTo ) - val viewModel = getModel(transaction) + val viewModel = getModel() viewModel.setup(transaction) viewModel.transaction.let { @@ -161,7 +148,7 @@ class ManageStockViewModelTest { transactionDate = transactionDate, distributedTo = null ) - val viewModel = getModel(transaction) + val viewModel = getModel() viewModel.setup(transaction) viewModel.transaction.let { @@ -180,7 +167,7 @@ class ManageStockViewModelTest { transactionDate = transactionDate, distributedTo = null ) - val viewModel = getModel(transaction) + val viewModel = getModel() viewModel.setup(transaction) viewModel.transaction.let { @@ -193,13 +180,7 @@ class ManageStockViewModelTest { @Test fun canSetAndGetItemQuantityForSelectedItem() { - val transaction = Transaction( - transactionType = TransactionType.DISTRIBUTION, - facility = facility, - transactionDate = transactionDate, - distributedTo = distributedTo - ) - val viewModel = getModel(transaction) + val viewModel = getModel() val qty = 319L val item = createStockEntry("someUid", viewModel, qty.toString()) @@ -218,13 +199,7 @@ class ManageStockViewModelTest { @Test fun canUpdateExistingItemQuantityForSelectedItem() { - val transaction = Transaction( - transactionType = TransactionType.DISTRIBUTION, - facility = facility, - transactionDate = transactionDate, - distributedTo = distributedTo - ) - val viewModel = getModel(transaction) + val viewModel = getModel() val qty2 = 95L val item = createStockEntry("someUid", viewModel, qty2.toString())