diff --git a/app/src/androidTest/java/org/dhis2/usescases/flow/syncFlow/robot/SyncFlowRobot.kt b/app/src/androidTest/java/org/dhis2/usescases/flow/syncFlow/robot/SyncFlowRobot.kt index 47febdf6ea..44dbf0d4fb 100644 --- a/app/src/androidTest/java/org/dhis2/usescases/flow/syncFlow/robot/SyncFlowRobot.kt +++ b/app/src/androidTest/java/org/dhis2/usescases/flow/syncFlow/robot/SyncFlowRobot.kt @@ -34,7 +34,7 @@ class SyncFlowRobot(val composeTestRule: ComposeTestRule) : BaseRobot() { fun checkSyncWasSuccessfully() { val expectedTitle = InstrumentationRegistry.getInstrumentation() .targetContext.getString(R.string.sync_dialog_title_synced) - composeTestRule.waitUntilAtLeastOneExists(hasText(expectedTitle)) + composeTestRule.waitUntilAtLeastOneExists(hasText(expectedTitle), 2_000L) composeTestRule.onNodeWithTag(TITLE, useUnmergedTree = true).assert(hasText(expectedTitle, true)) } diff --git a/compose-table/src/main/java/org/dhis2/composetable/ui/TableCell.kt b/compose-table/src/main/java/org/dhis2/composetable/ui/TableCell.kt index 7df1f905d0..c2748435b9 100644 --- a/compose-table/src/main/java/org/dhis2/composetable/ui/TableCell.kt +++ b/compose-table/src/main/java/org/dhis2/composetable/ui/TableCell.kt @@ -40,6 +40,7 @@ import org.dhis2.composetable.model.TableCell import org.dhis2.composetable.ui.compositions.LocalCurrentCellValue import org.dhis2.composetable.ui.compositions.LocalInteraction import org.dhis2.composetable.ui.compositions.LocalUpdatingCell +import org.dhis2.composetable.ui.extensions.isNumeric import org.dhis2.composetable.ui.modifiers.cellBorder import org.dhis2.composetable.ui.semantics.CELL_ERROR_UNDERLINE_TEST_TAG import org.dhis2.composetable.ui.semantics.CELL_TEST_TAG @@ -173,7 +174,7 @@ fun TableCell( overflow = TextOverflow.Ellipsis, style = TextStyle.Default.copy( fontSize = TableTheme.dimensions.defaultCellTextSize, - textAlign = TextAlign.End, + textAlign = if (cellValue.isNumeric()) TextAlign.End else TextAlign.Start, color = LocalTableColors.current.cellTextColor( hasError = cell.error != null, hasWarning = cell.warning != null, diff --git a/compose-table/src/main/java/org/dhis2/composetable/ui/extensions/StringExtensions.kt b/compose-table/src/main/java/org/dhis2/composetable/ui/extensions/StringExtensions.kt new file mode 100644 index 0000000000..cfa069cd8d --- /dev/null +++ b/compose-table/src/main/java/org/dhis2/composetable/ui/extensions/StringExtensions.kt @@ -0,0 +1,3 @@ +package org.dhis2.composetable.ui.extensions + +fun String?.isNumeric() = this?.toDoubleOrNull() != null diff --git a/compose-table/src/test/java/org/dhis2/extensions/StringExtensionsTest.kt b/compose-table/src/test/java/org/dhis2/extensions/StringExtensionsTest.kt new file mode 100644 index 0000000000..782cfc31b5 --- /dev/null +++ b/compose-table/src/test/java/org/dhis2/extensions/StringExtensionsTest.kt @@ -0,0 +1,23 @@ +package org.dhis2.extensions + +import org.dhis2.composetable.ui.extensions.isNumeric +import org.junit.Assert.assertFalse +import org.junit.Assert.assertTrue +import org.junit.Test + +class StringExtensionsTest { + + @Test + fun shouldReturnTrueIfTextIsNumericFalseOtherwise() { + assertTrue("0".isNumeric()) + assertTrue("231".isNumeric()) + assertTrue("11.33".isNumeric()) + assertTrue("-123.3".isNumeric()) + assertTrue("11232.54".isNumeric()) + assertFalse("1,1232.54".isNumeric()) + assertFalse("One".isNumeric()) + assertFalse("[89.23, -14.20]".isNumeric()) + assertFalse("12/01/2020".isNumeric()) + assertFalse("has 1.2".isNumeric()) + } +}