-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
62a9ff6
commit 9c3280f
Showing
2 changed files
with
198 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
193 changes: 193 additions & 0 deletions
193
...topTest/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputPositiveIntegerTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,193 @@ | ||
package org.hisp.dhis.mobile.ui.designsystem.component | ||
|
||
import androidx.compose.runtime.getValue | ||
import androidx.compose.runtime.mutableStateOf | ||
import androidx.compose.runtime.saveable.rememberSaveable | ||
import androidx.compose.runtime.setValue | ||
import androidx.compose.ui.test.assert | ||
import androidx.compose.ui.test.assertHasClickAction | ||
import androidx.compose.ui.test.assertIsNotEnabled | ||
import androidx.compose.ui.test.assertTextEquals | ||
import androidx.compose.ui.test.hasText | ||
import androidx.compose.ui.test.junit4.createComposeRule | ||
import androidx.compose.ui.test.onNodeWithTag | ||
import androidx.compose.ui.test.performClick | ||
import androidx.compose.ui.test.performTextInput | ||
import org.hisp.dhis.mobile.ui.designsystem.theme.SurfaceColor | ||
import org.junit.Rule | ||
import org.junit.Test | ||
|
||
class InputPositiveIntegerTest { | ||
|
||
@get:Rule | ||
val rule = createComposeRule() | ||
|
||
@Test | ||
fun shouldDisplayInputPositiveIntegerCorrectly() { | ||
rule.setContent { | ||
InputPositiveInteger( | ||
title = "Label", | ||
) | ||
} | ||
rule.onNodeWithTag("INPUT_POSITIVE_INTEGER").assertExists() | ||
rule.onNodeWithTag("INPUT_POSITIVE_INTEGER_LEGEND").assertDoesNotExist() | ||
rule.onNodeWithTag("INPUT_POSITIVE_INTEGER_SUPPORTING_TEXT").assertDoesNotExist() | ||
} | ||
|
||
@Test | ||
fun shouldAllowUserInputWhenEnabled() { | ||
rule.setContent { | ||
var inputValue by rememberSaveable { mutableStateOf("") } | ||
InputPositiveInteger( | ||
title = "Label", | ||
inputText = inputValue, | ||
onValueChanged = { | ||
if (it != null) { | ||
inputValue = it | ||
} | ||
}, | ||
) | ||
} | ||
rule.onNodeWithTag("INPUT_POSITIVE_INTEGER").assertExists() | ||
rule.onNodeWithTag("INPUT_POSITIVE_INTEGER_FIELD").performTextInput("1234") | ||
rule.onNodeWithTag("INPUT_POSITIVE_INTEGER_FIELD").assert(hasText("1234")) | ||
} | ||
|
||
@Test | ||
fun shouldNotAllowUserInputWhenDisabled() { | ||
rule.setContent { | ||
InputPositiveInteger( | ||
title = "Label", | ||
state = InputShellState.DISABLED, | ||
) | ||
} | ||
rule.onNodeWithTag("INPUT_POSITIVE_INTEGER").assertExists() | ||
rule.onNodeWithTag("INPUT_POSITIVE_INTEGER_FIELD").assertIsNotEnabled() | ||
} | ||
|
||
@Test | ||
fun shouldShowResetButtonWhenTextFieldHasContent() { | ||
rule.setContent { | ||
var inputValue by rememberSaveable { mutableStateOf("") } | ||
InputPositiveInteger( | ||
title = "Label", | ||
inputText = inputValue, | ||
onValueChanged = { | ||
if (it != null) { | ||
inputValue = it | ||
} | ||
}, | ||
) | ||
} | ||
rule.onNodeWithTag("INPUT_POSITIVE_INTEGER").assertExists() | ||
rule.onNodeWithTag("INPUT_POSITIVE_INTEGER_FIELD").assertExists() | ||
rule.onNodeWithTag("INPUT_POSITIVE_INTEGER_FIELD").performTextInput("1234") | ||
rule.onNodeWithTag("INPUT_POSITIVE_INTEGER_RESET_BUTTON").assertExists() | ||
} | ||
|
||
@Test | ||
fun shouldDeleteContentWhenResetButtonIsClickedAndHideResetButton() { | ||
rule.setContent { | ||
var inputValue by rememberSaveable { mutableStateOf("1234") } | ||
|
||
InputPositiveInteger( | ||
title = "Label", | ||
inputText = inputValue, | ||
onValueChanged = { | ||
if (it != null) { | ||
inputValue = it | ||
} | ||
}, | ||
) | ||
} | ||
rule.onNodeWithTag("INPUT_POSITIVE_INTEGER").assertExists() | ||
rule.onNodeWithTag("INPUT_POSITIVE_INTEGER_RESET_BUTTON").assertExists() | ||
rule.onNodeWithTag("INPUT_POSITIVE_INTEGER_RESET_BUTTON").performClick() | ||
rule.onNodeWithTag("INPUT_POSITIVE_INTEGER_FIELD").assertTextEquals("") | ||
rule.onNodeWithTag("INPUT_POSITIVE_INTEGER_RESET_BUTTON").assertDoesNotExist() | ||
} | ||
|
||
@Test | ||
fun shouldShowLegendCorrectly() { | ||
rule.setContent { | ||
InputPositiveInteger( | ||
title = "Label", | ||
inputText = "", | ||
legendData = LegendData(SurfaceColor.CustomGreen, "Legend"), | ||
) | ||
} | ||
rule.onNodeWithTag("INPUT_POSITIVE_INTEGER").assertExists() | ||
rule.onNodeWithTag("INPUT_POSITIVE_INTEGER_LEGEND").assertExists() | ||
rule.onNodeWithTag("INPUT_POSITIVE_INTEGER_LEGEND").assertHasClickAction() | ||
} | ||
|
||
@Test | ||
fun shouldShowSupportingTextCorrectly() { | ||
rule.setContent { | ||
InputPositiveInteger( | ||
title = "Label", | ||
inputText = "", | ||
supportingText = listOf(SupportingTextData("Supporting text", SupportingTextState.DEFAULT)), | ||
) | ||
} | ||
rule.onNodeWithTag("INPUT_POSITIVE_INTEGER").assertExists() | ||
rule.onNodeWithTag("INPUT_POSITIVE_INTEGER_SUPPORTING_TEXT").assertExists() | ||
} | ||
|
||
@Test | ||
fun shouldNotAllowDecimalValues() { | ||
rule.setContent { | ||
var inputValue by rememberSaveable { mutableStateOf("") } | ||
InputPositiveInteger( | ||
title = "Label", | ||
inputText = inputValue, | ||
onValueChanged = { | ||
if (it != null) { | ||
inputValue = it | ||
} | ||
}, | ||
) | ||
} | ||
rule.onNodeWithTag("INPUT_POSITIVE_INTEGER").assertExists() | ||
rule.onNodeWithTag("INPUT_POSITIVE_INTEGER_FIELD").performTextInput("12.12") | ||
rule.onNodeWithTag("INPUT_POSITIVE_INTEGER_FIELD").assert(hasText("")) | ||
} | ||
|
||
@Test | ||
fun shouldNotAllowNegativeValues() { | ||
rule.setContent { | ||
var inputValue by rememberSaveable { mutableStateOf("") } | ||
InputPositiveInteger( | ||
title = "Label", | ||
inputText = inputValue, | ||
onValueChanged = { | ||
if (it != null) { | ||
inputValue = it | ||
} | ||
}, | ||
) | ||
} | ||
rule.onNodeWithTag("INPUT_POSITIVE_INTEGER").assertExists() | ||
rule.onNodeWithTag("INPUT_POSITIVE_INTEGER_FIELD").performTextInput("-1212") | ||
rule.onNodeWithTag("INPUT_POSITIVE_INTEGER_FIELD").assert(hasText("")) | ||
} | ||
|
||
@Test | ||
fun shouldNotAllowValuesWithALeadingZero() { | ||
rule.setContent { | ||
var inputValue by rememberSaveable { mutableStateOf("") } | ||
InputPositiveInteger( | ||
title = "Label", | ||
inputText = inputValue, | ||
onValueChanged = { | ||
if (it != null) { | ||
inputValue = it | ||
} | ||
}, | ||
) | ||
} | ||
rule.onNodeWithTag("INPUT_POSITIVE_INTEGER").assertExists() | ||
rule.onNodeWithTag("INPUT_POSITIVE_INTEGER_FIELD").performTextInput("01212") | ||
rule.onNodeWithTag("INPUT_POSITIVE_INTEGER_FIELD").assert(hasText("")) | ||
} | ||
} |