mirror of
https://github.com/msfjarvis/compose-lobsters
synced 2025-08-18 03:17:03 +05:30
Add test to ensure new item is added correctly
Signed-off-by: Harsh Shandilya <me@msfjarvis.dev>
This commit is contained in:
parent
e0e28b5e35
commit
0ccd3b353d
2 changed files with 26 additions and 1 deletions
|
@ -1,9 +1,13 @@
|
|||
package dev.msfjarvis.todo
|
||||
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.ui.test.assertIsDisplayed
|
||||
import androidx.ui.test.createComposeRule
|
||||
import androidx.ui.test.onNodeWithTag
|
||||
import androidx.ui.test.onNodeWithText
|
||||
import androidx.ui.test.performClick
|
||||
import androidx.ui.test.performTextInput
|
||||
import dev.msfjarvis.todo.data.model.TodoItem
|
||||
import dev.msfjarvis.todo.ui.TodoTheme
|
||||
import org.junit.Rule
|
||||
|
@ -29,4 +33,23 @@ class MainActivityTest {
|
|||
onNodeWithTag("fab").performClick()
|
||||
onNodeWithTag("item_dialog").assertIsDisplayed()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun item_addition_adds_new_entry() {
|
||||
composeTestRule.setContent {
|
||||
val items by mutableStateOf(arrayListOf<TodoItem>())
|
||||
TodoTheme {
|
||||
TodoApp(
|
||||
items,
|
||||
items::add,
|
||||
items::remove,
|
||||
)
|
||||
}
|
||||
}
|
||||
onNodeWithText("Item 1").assertDoesNotExist()
|
||||
onNodeWithTag("fab").performClick()
|
||||
onNodeWithTag("item_name").performTextInput("Item 1")
|
||||
onNodeWithTag("add_button").performClick()
|
||||
onNodeWithText("Item 1").assertIsDisplayed()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -108,6 +108,7 @@ fun ItemAddDialog(
|
|||
value = newItemName,
|
||||
onValueChange = { newItemName = it },
|
||||
label = { Text(text = "Name") },
|
||||
modifier = Modifier.testTag("item_name")
|
||||
)
|
||||
},
|
||||
confirmButton = {
|
||||
|
@ -118,7 +119,8 @@ fun ItemAddDialog(
|
|||
newItemName = TextFieldValue("")
|
||||
hideDialog.invoke()
|
||||
}
|
||||
}
|
||||
},
|
||||
modifier = Modifier.testTag("add_button")
|
||||
) {
|
||||
Text(text = "Add")
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue