Skip to content

Commit

Permalink
Adds test
Browse files Browse the repository at this point in the history
  • Loading branch information
ferdyrod authored and xavimolloy committed Jun 27, 2024
1 parent 0a4a795 commit cf0aa61
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -176,6 +178,33 @@ class TableRobot(
return fakeModel
}

fun initEmptyTableAppScreen(
emptyTablesText: String,
): List<TableModel> {
val fakeModel: List<TableModel> = 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<TableModel>, tableCell: TableCell): List<TableModel> {
return fakeModel.map { tableModel ->
val hasRowWithDataElement = tableModel.tableRows.find {
Expand Down Expand Up @@ -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()
}
}
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -20,4 +25,15 @@ class DataSetTableUiTest {
)
}
}
}

@Test
fun shouldRenderInfoBarIfTableListIsEmpty() {
tableRobot(composeTestRule) {
initEmptyTableAppScreen(
emptyTablesText = "Section is misconfigured"
)

assertInfoBarIsVisible("Section is misconfigured")
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -308,6 +309,7 @@ fun DataSetTableScreen(
actionText = null,
onClick = {},
),
Modifier.testTag(EMPTY_TABLE_TEXT_TAG),
)
}
} else {
Expand All @@ -330,3 +332,5 @@ fun DataSetTableScreen(
}
}
}

const val EMPTY_TABLE_TEXT_TAG = "EMPTY_TABLE_TEXT_TAG"

0 comments on commit cf0aa61

Please sign in to comment.