Skip to content

Commit

Permalink
fix: [ANDROAPP-6121] Align numeric values to the left in all tables (#…
Browse files Browse the repository at this point in the history
…3711)

* Align numeric values to the right in tables

* test: fix shouldCheckDisplayInList

Signed-off-by: andresmr <[email protected]>

---------

Signed-off-by: andresmr <[email protected]>
Co-authored-by: andresmr <[email protected]>
  • Loading branch information
ferdyrod and andresmr authored Jul 22, 2024
1 parent 01f3122 commit 00c9143
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package org.dhis2.composetable.ui.extensions

fun String?.isNumeric() = this?.toDoubleOrNull() != null
Original file line number Diff line number Diff line change
@@ -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())
}
}

0 comments on commit 00c9143

Please sign in to comment.