Skip to content

Commit 194a047

Browse files
TASK-1786159: adding tests for embedded data add/remove record
1 parent e1048b2 commit 194a047

File tree

2 files changed

+44
-8
lines changed
  • samples/android-cmp-app/src/androidInstrumentedTest/kotlin/com/pega/constellation/sdk/kmp/samples/androidcmpapp
  • ui-renderer-cmp/src/commonMain/kotlin/com/pega/constellation/sdk/kmp/ui/renderer/cmp/containers

2 files changed

+44
-8
lines changed

samples/android-cmp-app/src/androidInstrumentedTest/kotlin/com/pega/constellation/sdk/kmp/samples/androidcmpapp/CaseProcessingTest.kt

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,19 @@ package com.pega.constellation.sdk.kmp.samples.androidcmpapp
22

33
import androidx.compose.ui.test.ExperimentalTestApi
44
import androidx.compose.ui.test.assertTextContains
5+
import androidx.compose.ui.test.hasContentDescription
56
import androidx.compose.ui.test.hasSetTextAction
67
import androidx.compose.ui.test.hasText
78
import androidx.compose.ui.test.onFirst
9+
import androidx.compose.ui.test.onNodeWithContentDescription
810
import androidx.compose.ui.test.onNodeWithText
911
import androidx.compose.ui.test.onSiblings
1012
import androidx.compose.ui.test.performClick
1113
import androidx.compose.ui.test.performTextInput
1214
import androidx.compose.ui.test.performTextReplacement
1315
import androidx.compose.ui.test.runComposeUiTest
16+
import androidx.compose.ui.test.waitUntilDoesNotExist
17+
import androidx.compose.ui.test.waitUntilNodeCount
1418
import kotlin.test.Test
1519

1620
@OptIn(ExperimentalTestApi::class)
@@ -80,18 +84,27 @@ class CaseProcessingTest : ComposeTest() {
8084
// create case
8185
onNodeWithText(CREATE_CASE_TEXT).performClick()
8286

83-
// verify form components
87+
// verify form title and instruction
8488
waitForNode("Create EmbeddedData (E-")
8589
waitForNode("Embedded Data use-case")
8690
waitForNode("EmbeddedData cars editable")
8791
waitForNode("EmbeddedData cars readonly")
92+
93+
// remove and verify empty list
94+
onNodeWithContentDescription("Delete item 1").performClick()
95+
waitForNodes("No items", count = 2)
96+
waitUntilNodeCount(hasContentDescription("No items"), count = 2)
97+
98+
onNodeWithText("Add", substring = true).performClick()
99+
100+
// verify empty record
88101
waitForNodes("Row 1", 2)
89102
waitForNode("Details")
90103
waitForNodes("Brand", 2)
91104
waitForNodes("Model", 2)
92105
waitForNodes("---", 2)
93106

94-
// enter some data
107+
// enter data
95108
onNodeWithText("Client name").performTextInput("Lukasz")
96109
onNode(hasText("Brand") and hasSetTextAction()).performTextInput("Audi")
97110
onNode(hasText("Model") and hasSetTextAction()).performTextInput("A5")
@@ -102,6 +115,29 @@ class CaseProcessingTest : ComposeTest() {
102115
waitForNodes("Audi", 2)
103116
waitForNodes("A5", 2)
104117

118+
// adding 2nd record
119+
onNodeWithText("Add", substring = true).performClick()
120+
121+
// enter data in Row 2
122+
waitForNodes("Row 2", count = 2)
123+
onNode(hasText("Client name") and !hasText("Lukasz") and hasSetTextAction()).performTextInput("Marek")
124+
onNode(hasText("Brand") and !hasText("Audi") and hasSetTextAction()).performTextInput("Ford")
125+
onNode(hasText("Model") and !hasText("A5") and hasSetTextAction()).performTextInput("Focus")
126+
onNodeWithText("Row 2").performClick() // remove focus to propagate data
127+
128+
// verify data propagation for Row 2
129+
waitForNodes("Marek", 2)
130+
waitForNodes("Ford", 2)
131+
waitForNodes("Focus", 2)
132+
133+
// remove Row 1 and verify
134+
onNodeWithContentDescription("Delete item 1").performClick()
135+
136+
waitUntilDoesNotExist(hasText("Row 2"))
137+
waitUntilDoesNotExist(hasText("Lukasz"))
138+
waitUntilDoesNotExist(hasText("Audi"))
139+
waitUntilDoesNotExist(hasText("A5"))
140+
105141
// go to next step
106142
onNodeWithText("Next").performClick()
107143

ui-renderer-cmp/src/commonMain/kotlin/com/pega/constellation/sdk/kmp/ui/renderer/cmp/containers/FieldGroupTemplateRenderer.kt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,28 +32,28 @@ class FieldGroupTemplateRenderer : ComponentRenderer<FieldGroupTemplateComponent
3232
override fun FieldGroupTemplateComponent.Render() {
3333
val focusManager = LocalFocusManager.current
3434
Column(modifier = Modifier.fillMaxWidth()) {
35-
items.forEach {
35+
items.forEachIndexed { index, item ->
3636
Column {
3737
Row(
3838
verticalAlignment = Alignment.CenterVertically,
3939
horizontalArrangement = Arrangement.SpaceBetween,
4040
modifier = Modifier.fillMaxWidth()
4141
) {
42-
Text(it.heading, fontSize = 16.sp, fontWeight = FontWeight.Bold)
43-
if (it.allowDelete) {
42+
Text(item.heading, fontSize = 16.sp, fontWeight = FontWeight.Bold)
43+
if (item.allowDelete) {
4444
IconButton(onClick = {
4545
focusManager.clearFocus()
46-
deleteItem(it)
46+
deleteItem(item)
4747
}) {
4848
Icon(
4949
painterResource(Res.drawable.outline_delete_48),
50-
"Delete item",
50+
"Delete item ${index + 1}",
5151
Modifier.size(24.dp)
5252
)
5353
}
5454
}
5555
}
56-
it.component.Render()
56+
item.component.Render()
5757
}
5858
}
5959
if (items.isEmpty()) {

0 commit comments

Comments
 (0)