fix(test): add Compose waitUntil synchronization in ChatViewModelScopeTest

This commit is contained in:
Ochenstarik 2026-08-25 10:05:45 +07:00
parent c691d558f2
commit 97f2f929c3

View file

@ -1,11 +1,11 @@
package app.hermes.mobile.feature.chat package app.hermes.mobile.feature.chat
import androidx.compose.ui.test.assertExists
import androidx.compose.ui.test.junit4.createAndroidComposeRule import androidx.compose.ui.test.junit4.createAndroidComposeRule
import androidx.compose.ui.test.onAllNodesWithText
import androidx.compose.ui.test.onNodeWithText import androidx.compose.ui.test.onNodeWithText
import androidx.compose.ui.test.performClick import androidx.compose.ui.test.performClick
import androidx.compose.ui.test.performTextInput import androidx.compose.ui.test.performTextInput
import androidx.compose.ui.test.assertIsDisplayed
import androidx.compose.ui.test.hasText
import androidx.test.ext.junit.runners.AndroidJUnit4 import androidx.test.ext.junit.runners.AndroidJUnit4
import app.hermes.mobile.MainActivity import app.hermes.mobile.MainActivity
import org.junit.Rule import org.junit.Rule
@ -20,11 +20,25 @@ class ChatViewModelScopeTest {
@Test @Test
fun testChatStateSurvivesRecreation() { fun testChatStateSurvivesRecreation() {
// Create session // Wait for New Session button and click
composeTestRule.waitUntil(5000) {
composeTestRule.onAllNodesWithText("New Session", substring = true, ignoreCase = true)
.fetchSemanticsNodes().isNotEmpty()
}
composeTestRule.onNodeWithText("New Session", ignoreCase = true).performClick() composeTestRule.onNodeWithText("New Session", ignoreCase = true).performClick()
// Wait for Create dialog button and click
composeTestRule.waitUntil(5000) {
composeTestRule.onAllNodesWithText("Create", substring = true, ignoreCase = true)
.fetchSemanticsNodes().isNotEmpty()
}
composeTestRule.onNodeWithText("Create", ignoreCase = true).performClick() composeTestRule.onNodeWithText("Create", ignoreCase = true).performClick()
composeTestRule.onNodeWithText("Message Hermes…", ignoreCase = true).assertIsDisplayed() // Wait for ChatScreen input placeholder
composeTestRule.waitUntil(5000) {
composeTestRule.onAllNodesWithText("Message Hermes…", substring = true, ignoreCase = true)
.fetchSemanticsNodes().isNotEmpty()
}
composeTestRule.onNodeWithText("Message Hermes…", ignoreCase = true) composeTestRule.onNodeWithText("Message Hermes…", ignoreCase = true)
.performTextInput("Draft prompt before rotation") .performTextInput("Draft prompt before rotation")
@ -33,6 +47,11 @@ class ChatViewModelScopeTest {
composeTestRule.activityRule.scenario.recreate() composeTestRule.activityRule.scenario.recreate()
composeTestRule.waitForIdle() composeTestRule.waitForIdle()
// Verify text state persisted across recreation
composeTestRule.waitUntil(5000) {
composeTestRule.onAllNodesWithText("Draft prompt before rotation", substring = true)
.fetchSemanticsNodes().isNotEmpty()
}
composeTestRule.onNodeWithText("Draft prompt before rotation", substring = true).assertExists() composeTestRule.onNodeWithText("Draft prompt before rotation", substring = true).assertExists()
} }
} }