Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ jobs:
- name: Deploy
run: |
if [[ '${{ github.ref }}' =~ 'refs/tags' ]]; then
./gradlew jreleaserFullRelease
./gradlew common:jreleaserFullRelease
else
./gradlew common:jreleaserDeploy
fi
Expand Down
Original file line number Diff line number Diff line change
@@ -1,29 +1,55 @@
package com.progressive.kherkin.compose.steps.assertion

import androidx.compose.ui.semantics.SemanticsProperties
import androidx.compose.ui.test.SemanticsMatcher
import androidx.compose.ui.test.assert
import androidx.compose.ui.test.hasSetTextAction
import androidx.compose.ui.test.hasTestTag
import androidx.compose.ui.test.hasText
import androidx.compose.ui.test.isNotEnabled
import androidx.compose.ui.test.junit4.ComposeTestRule
import androidx.compose.ui.test.onNodeWithTag
import androidx.compose.ui.test.onNodeWithText
import com.progressive.kherkin.common.testcore.ComposeTestLogger
import com.progressive.kherkin.common.testcore.Gherkin

/** Finds a node [tag] and checks that it has text that is displayed. */
/** Finds a node [tag] and checks that it has EditableText. */
fun Gherkin.IShouldSeeTextField(tag: String, composeTestRule: ComposeTestRule) {
ComposeTestLogger().info("${::IShouldSeeTextField.name}: onNodeWithTag($tag).assert(hasSetTextAction())")
composeTestRule.onNodeWithTag(tag).assert(hasSetTextAction())
composeTestRule.onNodeWithTag(tag).assert(SemanticsMatcher.keyIsDefined(SemanticsProperties.EditableText))
}

/** Finds a node text field that contains [text] and checks that it is displayed. */
/** Finds a node that contains [text] and checks that it has EditableText. */
fun Gherkin.IShouldSeeTextFieldWithText(text: String, composeTestRule: ComposeTestRule) {
ComposeTestLogger().info("${::IShouldSeeTextFieldWithText.name}: onNodeWithText($text).assert(hasSetTextAction())")
composeTestRule.onNodeWithText(text).assert(hasSetTextAction())
composeTestRule.onNodeWithText(text).assert(SemanticsMatcher.keyIsDefined(SemanticsProperties.EditableText))
}

/** Finds a node [tag] that contains [text] and checks that it is displayed. */
/** Finds a node [tag] that contains [text] and checks that it has EditableText. */
fun Gherkin.IShouldSeeTextFieldWithTagAndText(tag: String, text: String, composeTestRule: ComposeTestRule) {
ComposeTestLogger().info("${::IShouldSeeTextFieldWithTagAndText.name}: onNode(hasTestTag($tag).and(hasText($text))).assert(hasSetTextAction())")
composeTestRule.onNode(hasTestTag(tag).and(hasText(text))).assert(hasSetTextAction())
composeTestRule.onNode(hasTestTag(tag).and(hasText(text))).assert(SemanticsMatcher.keyIsDefined(SemanticsProperties.EditableText))
}

/** Finds a node [tag] and checks that it has EditableText and is not enabled. */
fun Gherkin.IShouldSeeDisabledTextField(tag: String, composeTestRule: ComposeTestRule) {
ComposeTestLogger().info("${::IShouldSeeDisabledTextField.name}: onNodeWithTag($tag).assert(keyIsDefined(EditableText)).assert(isNotEnabled())")
composeTestRule.onNodeWithTag(tag)
.assert(SemanticsMatcher.keyIsDefined(SemanticsProperties.EditableText))
.assert(isNotEnabled())
}

/** Finds a node that contains [text] and checks that it has EditableText and is not enabled. */
fun Gherkin.IShouldSeeDisabledTextFieldWithText(text: String, composeTestRule: ComposeTestRule) {
ComposeTestLogger().info("${::IShouldSeeDisabledTextFieldWithText.name}: onNode(hasText($text)).assert(keyIsDefined(EditableText)).assert(isNotEnabled())")
composeTestRule.onNode(hasText(text))
.assert(SemanticsMatcher.keyIsDefined(SemanticsProperties.EditableText))
.assert(isNotEnabled())
}

/** Finds a node [tag] that contains [text] and checks that it has EditableText and is not enabled. */
fun Gherkin.IShouldSeeDisabledTextFieldWithTagAndText(tag: String, text: String, composeTestRule: ComposeTestRule) {
ComposeTestLogger().info("${::IShouldSeeDisabledTextFieldWithTagAndText.name}: onNode(hasTestTag($tag).and(hasText($text))).assert(keyIsDefined(EditableText)).assert(isNotEnabled())")
composeTestRule.onNode(hasTestTag(tag).and(hasText(text)))
.assert(SemanticsMatcher.keyIsDefined(SemanticsProperties.EditableText))
.assert(isNotEnabled())
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ import com.progressive.kherkin.common.testcore.When
import com.progressive.kherkin.compose.steps.actions.IClearField
import com.progressive.kherkin.compose.steps.actions.IEnterTextIntoField
import com.progressive.kherkin.compose.steps.actions.ILeaveFieldEmpty
import com.progressive.kherkin.compose.steps.actions.IWaitToSeeScreen
import com.progressive.kherkin.compose.steps.assertion.IShouldSeeDisabledTextField
import com.progressive.kherkin.compose.steps.assertion.IShouldSeeDisabledTextFieldWithTagAndText
import com.progressive.kherkin.compose.steps.assertion.IShouldSeeDisabledTextFieldWithText
import com.progressive.kherkin.compose.steps.assertion.IShouldSeeTextField
import com.progressive.kherkin.compose.steps.assertion.IShouldSeeTextFieldWithTagAndText
import com.progressive.kherkin.compose.steps.assertion.IShouldSeeTextFieldWithText
Expand Down Expand Up @@ -41,4 +45,13 @@ class TestTextFieldSteps : SampleBaseIntegrationTestCase() {
When.IClearField("Prefilled Field", composeTestRule)
Then.IShouldSeeTextFieldWithTagAndText("Prefilled Field", "", composeTestRule)
}

@Test
fun testDisabledTextField() {
Given.IRenderScreen(BasicComposeScreen(), composeTestRule)
When.IWaitToSeeScreen(BasicComposeScreen(), composeTestRule)
Then.IShouldSeeDisabledTextField("Disabled Field", composeTestRule)
And.IShouldSeeDisabledTextFieldWithText("Disabled text field", composeTestRule)
And.IShouldSeeDisabledTextFieldWithTagAndText("Disabled Field", "Disabled text field", composeTestRule)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ fun SmallTopAppBar() {
HidingButton(buttonIsVisible = buttonVisibility, changeValue = { buttonVisibility = it } )
TextField()
TextFieldPrefilled()
TextFieldPrefilledDisabled()
ScrollBoxes()
NavigateButton()
Link()
Expand Down Expand Up @@ -193,6 +194,33 @@ private fun TextFieldPrefilled() {
)
}

@Composable
private fun TextFieldPrefilledDisabled() {
val focusManager = LocalFocusManager.current
val textFieldText = stringResource(id = R.string.disabled_text_field)
var text by remember { mutableStateOf(textFieldText) }
val keyboardController = LocalSoftwareKeyboardController.current

TextField(
value = text,
onValueChange = { text = it },
label = { Text(stringResource(id = R.string.label)) },
placeholder = { Text(stringResource(id = R.string.placeholder)) },
singleLine = true,
keyboardOptions = KeyboardOptions(imeAction = ImeAction.Done),
keyboardActions = KeyboardActions(
onDone = {
keyboardController?.hide()
focusManager.clearFocus()
}
),
enabled = false,
modifier = Modifier
.padding(10.dp)
.testTag("Disabled Field")
)
}

@Composable
private fun ScrollBoxes() {
Column(
Expand Down
1 change: 1 addition & 0 deletions sampleapp/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@
<string name="label">Label</string>
<string name="placeholder">Placeholder</string>
<string name="prefilled_text_field">Default text</string>
<string name="disabled_text_field">Disabled text field</string>

<!-- SecondComposeActivity -->
<string name="second_title">Second Compose Activity</string>
Expand Down
Loading