[Chat][TEST] Message view UI test (#653)
This commit is contained in:
Родитель
fe57bef519
Коммит
02e073d7cd
|
@ -0,0 +1,63 @@
|
|||
package com.azure.android.communication.ui.chat
|
||||
|
||||
import androidx.compose.ui.test.assert
|
||||
import androidx.compose.ui.test.assertAny
|
||||
import androidx.compose.ui.test.hasText
|
||||
import androidx.compose.ui.test.junit4.createComposeRule
|
||||
import androidx.compose.ui.test.onAllNodesWithTag
|
||||
import androidx.compose.ui.test.onNodeWithTag
|
||||
import androidx.compose.ui.test.performClick
|
||||
import androidx.compose.ui.test.performTextInput
|
||||
import com.azure.android.communication.ui.chat.presentation.ui.chat.UITestTags
|
||||
import com.azure.android.communication.ui.chat.redux.state.ChatStatus
|
||||
import kotlinx.coroutines.test.runTest
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import java.time.LocalDateTime
|
||||
import java.time.format.DateTimeFormatter
|
||||
|
||||
internal class MessageViewTest : BaseUiTest() {
|
||||
@get:Rule
|
||||
val composeTestRule = createComposeRule()
|
||||
|
||||
@Test
|
||||
fun testOnMessageContentWithCurrentTime() = runTest {
|
||||
injectDependencies(testScheduler)
|
||||
|
||||
// launch composite
|
||||
chatSDK.setChatStatus(ChatStatus.INITIALIZED)
|
||||
launchChatComposite()
|
||||
|
||||
// send message
|
||||
val message = "hello"
|
||||
composeTestRule.onNodeWithTag(UITestTags.MESSAGE_INPUT_BOX).performTextInput(message)
|
||||
composeTestRule.onNodeWithTag(UITestTags.MESSAGE_SEND_BUTTON).performClick()
|
||||
|
||||
// current system time
|
||||
val formattedDate = LocalDateTime.now().format(DateTimeFormatter.ofPattern("h:mm a"))
|
||||
|
||||
// assert message is cleared after send
|
||||
composeTestRule.onNodeWithTag(UITestTags.MESSAGE_TIME_CONTENT).assert(hasText(formattedDate))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testOnMessageContentWithNoCurrentTime() = runTest {
|
||||
injectDependencies(testScheduler)
|
||||
|
||||
// launch composite
|
||||
chatSDK.setChatStatus(ChatStatus.INITIALIZED)
|
||||
launchChatComposite()
|
||||
|
||||
// send message
|
||||
val message = "hello"
|
||||
composeTestRule.onNodeWithTag(UITestTags.MESSAGE_INPUT_BOX).performTextInput(message)
|
||||
composeTestRule.onNodeWithTag(UITestTags.MESSAGE_SEND_BUTTON).performClick()
|
||||
|
||||
val secondMessage = "HELLO"
|
||||
composeTestRule.onNodeWithTag(UITestTags.MESSAGE_INPUT_BOX).performTextInput(secondMessage)
|
||||
composeTestRule.onNodeWithTag(UITestTags.MESSAGE_SEND_BUTTON).performClick()
|
||||
|
||||
// assert message is cleared after send
|
||||
composeTestRule.onAllNodesWithTag(UITestTags.MESSAGE_BASIC_CONTENT).assertAny(hasText(secondMessage))
|
||||
}
|
||||
}
|
|
@ -7,5 +7,7 @@ internal class UITestTags {
|
|||
companion object {
|
||||
const val MESSAGE_INPUT_BOX = "MESSAGE_INPUT_BOX"
|
||||
const val MESSAGE_SEND_BUTTON = "MESSAGE_SEND_BUTTON"
|
||||
const val MESSAGE_BASIC_CONTENT = "MESSAGE_BASIC_CONTENT"
|
||||
const val MESSAGE_TIME_CONTENT = "MESSAGE_TIME_CONTENT"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,6 +20,7 @@ import androidx.compose.runtime.Composable
|
|||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.platform.testTag
|
||||
import androidx.compose.ui.res.painterResource
|
||||
import androidx.compose.ui.tooling.preview.Preview
|
||||
import androidx.compose.ui.unit.dp
|
||||
|
@ -27,6 +28,7 @@ import androidx.compose.ui.viewinterop.AndroidView
|
|||
import androidx.core.text.HtmlCompat
|
||||
import com.azure.android.communication.ui.chat.R
|
||||
import com.azure.android.communication.ui.chat.presentation.style.ChatCompositeTheme
|
||||
import com.azure.android.communication.ui.chat.presentation.ui.chat.UITestTags
|
||||
import com.azure.android.communication.ui.chat.presentation.ui.viewmodel.MessageViewModel
|
||||
import com.azure.android.communication.ui.chat.presentation.ui.viewmodel.toViewModelList
|
||||
import com.azure.android.communication.ui.chat.preview.MOCK_LOCAL_USER_ID
|
||||
|
@ -202,6 +204,7 @@ private fun messageContent(viewModel: MessageViewModel) {
|
|||
?.format(timeFormat)
|
||||
?: "Unknown Time",
|
||||
style = ChatCompositeTheme.typography.messageHeaderDate,
|
||||
modifier = Modifier.testTag(UITestTags.MESSAGE_TIME_CONTENT)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -210,7 +213,8 @@ private fun messageContent(viewModel: MessageViewModel) {
|
|||
HtmlText(html = viewModel.message.content ?: "Empty")
|
||||
} else {
|
||||
BasicText(
|
||||
text = viewModel.message.content ?: "Empty"
|
||||
text = viewModel.message.content ?: "Empty",
|
||||
modifier = Modifier.testTag(UITestTags.MESSAGE_BASIC_CONTENT)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче