Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: [ANDROAPP-5869] duplicated indicators table #3713

Merged
merged 1 commit into from
Jul 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import org.dhis2.data.forms.dataentry.tablefields.spinner.SpinnerViewModel
import org.dhis2.form.model.ValueStoreResult.ERROR_UPDATING_VALUE
import org.dhis2.form.model.ValueStoreResult.VALUE_CHANGED
import org.dhis2.form.model.ValueStoreResult.VALUE_HAS_NOT_CHANGED
import org.dhis2.usescases.datasets.dataSetTable.dataSetSection.TableDataToTableModelMapper.Companion.INDICATORS_TABLE_ID
import org.hisp.dhis.android.core.arch.helpers.Result
import org.hisp.dhis.android.core.common.ValueType
import org.hisp.dhis.android.core.dataelement.DataElement
Expand Down Expand Up @@ -109,10 +110,12 @@ class DataValuePresenter(
val updatedTableModel = mapper(tableData)

val updatedTables = screenState.value.tables.map { tableModel ->
if (tableModel.id == catComboUid) {
updatedTableModel.copy(overwrittenValues = tableModel.overwrittenValues)
} else {
indicatorTables() ?: tableModel
when (tableModel.id) {
catComboUid -> updatedTableModel.copy(
overwrittenValues = tableModel.overwrittenValues,
)
INDICATORS_TABLE_ID -> indicatorTables() ?: tableModel
else -> tableModel
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,14 @@ class TableDataToTableModelMapper(val mapFieldValueToUser: MapFieldValueToUser)
}

return TableModel(
id = "indicators",
id = INDICATORS_TABLE_ID,
title = mapFieldValueToUser.resources.getString(R.string.dashboard_indicators),
tableHeaderModel = tableHeader,
tableRows = tableRows,
)
}

companion object {
const val INDICATORS_TABLE_ID = "indicators"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import org.dhis2.data.forms.dataentry.tablefields.spinner.SpinnerViewModel
import org.dhis2.data.schedulers.TrampolineSchedulerProvider
import org.dhis2.form.model.StoreResult
import org.dhis2.form.model.ValueStoreResult
import org.dhis2.usescases.datasets.dataSetTable.dataSetSection.TableDataToTableModelMapper.Companion.INDICATORS_TABLE_ID
import org.hisp.dhis.android.core.category.CategoryCombo
import org.hisp.dhis.android.core.common.ValueType
import org.hisp.dhis.android.core.dataelement.DataElement
Expand Down Expand Up @@ -381,7 +382,7 @@ class DataValuePresenterTest {
}

val mockedIndicatorTableModel = mock<TableModel> {
on { id } doReturn null
on { id } doReturn INDICATORS_TABLE_ID
}

val mockedUpdatedTableModel = mock<TableModel> {
Expand Down Expand Up @@ -426,6 +427,72 @@ class DataValuePresenterTest {
verify(view).onValueProcessed()
}

@Test
fun shouldUpdateValueWhenSavedForTwoTablesAndIndicators() {
val mockedTableCell = mock<TableCell> {
on { id } doReturn "mocked_id"
on { column } doReturn 1
on { row } doReturn 0
on { value } doReturn "valueToSave"
}

val mockedTableModelA = mock<TableModel> {
on { id } doReturn "tableIdA"
on { hasCellWithId(any()) } doReturn true
}

val mockedTableModelB = mock<TableModel> {
on { id } doReturn "tableIdB"
on { hasCellWithId(any()) } doReturn true
}

val mockedIndicatorTableModel = mock<TableModel> {
on { id } doReturn INDICATORS_TABLE_ID
}

val mockedUpdatedTableModel = mock<TableModel> {
on { id } doReturn "tableIdA_updated"
on { hasCellWithId(any()) } doReturn true
}

val mockedUpdatedIndicatorTableModel = mock<TableModel> {
on { id } doReturn "updated_indicator"
}

val tableStateValue = presenter.mutableTableData()
tableStateValue.value = TableScreenState(
listOf(mockedTableModelA, mockedTableModelB, mockedIndicatorTableModel),
)

whenever(valueStore.save(any(), any(), any(), any(), any(), any())) doReturn Flowable.just(
StoreResult(
uid = "id",
valueStoreResult = ValueStoreResult.VALUE_CHANGED,
valueStoreResultMessage = null,
),
)

whenever(dataValueRepository.getDataTableModel(any<String>())) doReturn Observable.just(
mockedDataTableModel,
)
whenever(dataValueRepository.setTableData(any(), any())) doReturn mockedTableData
whenever(mapper.invoke(any())) doReturn mockedUpdatedTableModel
whenever(
mockedUpdatedTableModel.copy(overwrittenValues = mockedTableModel.overwrittenValues),
) doReturn mockedUpdatedTableModel

whenever(dataValueRepository.getDataSetIndicators()) doReturn Single.just(mockedIndicators)
whenever(mapper.map(any())) doReturn mockedUpdatedIndicatorTableModel

presenter.onSaveValueChange(mockedTableCell)

assertTrue(presenter.currentState().value.tables.size == 3)
assertTrue(presenter.currentState().value.tables[0].id == "tableIdA_updated")
assertTrue(presenter.currentState().value.tables[1].id == "tableIdB")
assertTrue(presenter.currentState().value.tables.last().id == "updated_indicator")
verify(view).onValueProcessed()
}

@Test
fun shouldSetErrorValue() {
val mockedTableCell = mock<TableCell> {
Expand Down
Loading