From c75955a4a396accd2a6f2938aa088e423df2f080 Mon Sep 17 00:00:00 2001 From: Harsh Shandilya Date: Thu, 17 Sep 2020 02:06:43 +0530 Subject: [PATCH] Update tests for Compose alpha03 Signed-off-by: Harsh Shandilya --- .../dev/msfjarvis/todo/MainActivityTest.kt | 76 ++++++++++--------- 1 file changed, 41 insertions(+), 35 deletions(-) diff --git a/app/src/androidTest/java/dev/msfjarvis/todo/MainActivityTest.kt b/app/src/androidTest/java/dev/msfjarvis/todo/MainActivityTest.kt index f181b26c..6966327d 100644 --- a/app/src/androidTest/java/dev/msfjarvis/todo/MainActivityTest.kt +++ b/app/src/androidTest/java/dev/msfjarvis/todo/MainActivityTest.kt @@ -22,54 +22,60 @@ class MainActivityTest { @Test fun item_add_dialog_shows_on_fab_click() { - composeTestRule.setContent { - TodoTheme { - val items = arrayListOf() - TodoApp( - items, - items::add, - items::remove, - ) + composeTestRule.apply { + setContent { + TodoTheme { + val items = arrayListOf() + TodoApp( + items, + items::add, + items::remove, + ) + } } + onNodeWithTag("fab").performClick() + onNodeWithTag("item_dialog").assertIsDisplayed() } - onNodeWithTag("fab").performClick() - onNodeWithTag("item_dialog").assertIsDisplayed() } @Test fun item_addition_adds_new_entry() { - composeTestRule.setContent { - val items by mutableStateOf(arrayListOf()) - TodoTheme { - TodoApp( - items, - items::add, - items::remove, - ) + composeTestRule.apply { + setContent { + val items by mutableStateOf(arrayListOf()) + 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() } - onNodeWithText("Item 1").assertDoesNotExist() - onNodeWithTag("fab").performClick() - onNodeWithTag("item_name").performTextInput("Item 1") - onNodeWithTag("add_button").performClick() - onNodeWithText("Item 1").assertIsDisplayed() } @Test fun item_addition_with_empty_name_does_not_add_new_entry() { - composeTestRule.setContent { - val items by mutableStateOf(arrayListOf()) - TodoTheme { - TodoApp( - items, - items::add, - items::remove, - ) + composeTestRule.apply { + setContent { + val items by mutableStateOf(arrayListOf()) + TodoTheme { + TodoApp( + items, + items::add, + items::remove, + ) + } } + onNodeWithText("Item 1").assertDoesNotExist() + onNodeWithTag("fab").performClick() + onNodeWithTag("add_button").performClick() + onNodeWithText("Item 1").assertDoesNotExist() } - onNodeWithText("Item 1").assertDoesNotExist() - onNodeWithTag("fab").performClick() - onNodeWithTag("add_button").performClick() - onNodeWithText("Item 1").assertDoesNotExist() } }