diff --git a/compose-table/src/androidTest/java/org/dhis2/composetable/TableRobot.kt b/compose-table/src/androidTest/java/org/dhis2/composetable/TableRobot.kt index 43e8955d4c..06424d9d2e 100644 --- a/compose-table/src/androidTest/java/org/dhis2/composetable/TableRobot.kt +++ b/compose-table/src/androidTest/java/org/dhis2/composetable/TableRobot.kt @@ -17,6 +17,7 @@ import androidx.compose.ui.test.assertIsNotDisplayed import androidx.compose.ui.test.assertTextEquals import androidx.compose.ui.test.hasParent import androidx.compose.ui.test.hasTestTag +import androidx.compose.ui.test.hasText import androidx.compose.ui.test.junit4.ComposeContentTestRule import androidx.compose.ui.test.onNodeWithTag import androidx.compose.ui.test.performClick @@ -40,6 +41,7 @@ import org.dhis2.composetable.model.TextInputModel import org.dhis2.composetable.ui.DataSetTableScreen import org.dhis2.composetable.ui.DataTable import org.dhis2.composetable.ui.DrawableId +import org.dhis2.composetable.ui.EMPTY_TABLE_TEXT_TAG import org.dhis2.composetable.ui.INPUT_ERROR_MESSAGE_TEST_TAG import org.dhis2.composetable.ui.INPUT_HELPER_TEXT_TEST_TAG import org.dhis2.composetable.ui.INPUT_ICON_TEST_TAG @@ -176,6 +178,33 @@ class TableRobot( return fakeModel } + fun initEmptyTableAppScreen( + emptyTablesText: String, + ): List { + val fakeModel: List = emptyList() + composeTestRule.setContent { + val screenState = TableScreenState(fakeModel, state = TableState.SUCCESS) + + val model by remember { mutableStateOf(screenState) } + TableTheme( + tableColors = TableColors().copy(primary = MaterialTheme.colors.primary), + tableConfiguration = TableConfiguration(), + tableResizeActions = object : TableResizeActions {} + ) { + DataSetTableScreen( + tableScreenState = model, + onCellClick = { _, _, _ -> + null + }, + emptyTablesText = emptyTablesText, + onEdition = {}, + onSaveValue = {} + ) + } + } + return fakeModel + } + private fun updateValue(fakeModel: List, tableCell: TableCell): List { return fakeModel.map { tableModel -> val hasRowWithDataElement = tableModel.tableRows.find { @@ -456,4 +485,12 @@ class TableRobot( fun hideKeyboard() { keyboardHelper.hideKeyboard() } + + fun assertInfoBarIsVisible(emptyString: String) { + composeTestRule.onNode( + hasParent(hasTestTag(EMPTY_TABLE_TEXT_TAG)) + and + hasText(emptyString) + ).assertIsDisplayed() + } } \ No newline at end of file diff --git a/compose-table/src/androidTest/java/org/dhis2/composetable/ui/DataSetTableUiTest.kt b/compose-table/src/androidTest/java/org/dhis2/composetable/ui/DataSetTableUiTest.kt index 75b8fcd759..2685ac04bc 100644 --- a/compose-table/src/androidTest/java/org/dhis2/composetable/ui/DataSetTableUiTest.kt +++ b/compose-table/src/androidTest/java/org/dhis2/composetable/ui/DataSetTableUiTest.kt @@ -1,8 +1,13 @@ package org.dhis2.composetable.ui import androidx.compose.ui.platform.LocalContext +import androidx.compose.ui.test.assertIsDisplayed +import androidx.compose.ui.test.hasParent +import androidx.compose.ui.test.hasTestTag +import androidx.compose.ui.test.hasText import androidx.compose.ui.test.junit4.createComposeRule import org.dhis2.composetable.model.FakeTableModels +import org.dhis2.composetable.tableRobot import org.junit.Rule import org.junit.Test @@ -20,4 +25,15 @@ class DataSetTableUiTest { ) } } -} \ No newline at end of file + + @Test + fun shouldRenderInfoBarIfTableListIsEmpty() { + tableRobot(composeTestRule) { + initEmptyTableAppScreen( + emptyTablesText = "Section is misconfigured" + ) + + assertInfoBarIsVisible("Section is misconfigured") + } + } +} diff --git a/compose-table/src/main/java/org/dhis2/composetable/ui/DataSetTableScreen.kt b/compose-table/src/main/java/org/dhis2/composetable/ui/DataSetTableScreen.kt index e28c58aa78..315b7e7b50 100644 --- a/compose-table/src/main/java/org/dhis2/composetable/ui/DataSetTableScreen.kt +++ b/compose-table/src/main/java/org/dhis2/composetable/ui/DataSetTableScreen.kt @@ -34,6 +34,7 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.focus.FocusRequester import androidx.compose.ui.graphics.Color import androidx.compose.ui.platform.LocalFocusManager +import androidx.compose.ui.platform.testTag import androidx.compose.ui.unit.dp import kotlinx.coroutines.launch import org.dhis2.composetable.TableScreenState @@ -308,6 +309,7 @@ fun DataSetTableScreen( actionText = null, onClick = {}, ), + Modifier.testTag(EMPTY_TABLE_TEXT_TAG), ) } } else { @@ -330,3 +332,5 @@ fun DataSetTableScreen( } } } + +const val EMPTY_TABLE_TEXT_TAG = "EMPTY_TABLE_TEXT_TAG"