From b5cd371f8b8c9e35627a664b429a9e44608d0b2a Mon Sep 17 00:00:00 2001 From: Codex Date: Mon, 9 Mar 2026 15:37:10 +0300 Subject: [PATCH] android: add compose ui tests for auth and chat list states --- android/CHANGELOG.md | 5 ++ android/app/build.gradle.kts | 3 ++ .../messenger/ui/auth/LoginScreenTest.kt | 35 +++++++++++++ .../messenger/ui/chats/ChatListScreenTest.kt | 51 +++++++++++++++++++ docs/android-checklist.md | 2 +- 5 files changed, 95 insertions(+), 1 deletion(-) create mode 100644 android/app/src/androidTest/java/ru/daemonlord/messenger/ui/auth/LoginScreenTest.kt create mode 100644 android/app/src/androidTest/java/ru/daemonlord/messenger/ui/chats/ChatListScreenTest.kt diff --git a/android/CHANGELOG.md b/android/CHANGELOG.md index 12ff6e4..fbe3ef1 100644 --- a/android/CHANGELOG.md +++ b/android/CHANGELOG.md @@ -358,3 +358,8 @@ - Added global Coil image loader cache policy in `MessengerApplication` (memory + disk cache). - Added Media3 `SimpleCache` singleton module for media stream/file caching foundation. - Added Media3/Coil core dependencies and configured cache sizes for mobile usage. + +### Step 61 - Compose UI tests baseline +- Added instrumented Compose UI tests for login and chat list states. +- Added Android test dependencies for Compose test runner (`ui-test-junit4`) and test infra. +- Covered key visual states: auth error rendering, chat list loading state, and empty state. diff --git a/android/app/build.gradle.kts b/android/app/build.gradle.kts index 1261926..fb60773 100644 --- a/android/app/build.gradle.kts +++ b/android/app/build.gradle.kts @@ -106,6 +106,9 @@ dependencies { testImplementation("androidx.test:core:1.6.1") testImplementation("org.robolectric:robolectric:4.13") testImplementation("com.squareup.okhttp3:mockwebserver:4.12.0") + androidTestImplementation("androidx.compose.ui:ui-test-junit4:1.7.6") + androidTestImplementation("androidx.test.ext:junit:1.2.1") + androidTestImplementation("androidx.test.espresso:espresso-core:3.6.1") debugImplementation("androidx.compose.ui:ui-tooling:1.7.6") debugImplementation("androidx.compose.ui:ui-test-manifest:1.7.6") diff --git a/android/app/src/androidTest/java/ru/daemonlord/messenger/ui/auth/LoginScreenTest.kt b/android/app/src/androidTest/java/ru/daemonlord/messenger/ui/auth/LoginScreenTest.kt new file mode 100644 index 0000000..5adc044 --- /dev/null +++ b/android/app/src/androidTest/java/ru/daemonlord/messenger/ui/auth/LoginScreenTest.kt @@ -0,0 +1,35 @@ +package ru.daemonlord.messenger.ui.auth + +import androidx.activity.ComponentActivity +import androidx.compose.ui.test.assertIsDisplayed +import androidx.compose.ui.test.junit4.createAndroidComposeRule +import androidx.compose.ui.test.onNodeWithText +import org.junit.Rule +import org.junit.Test + +class LoginScreenTest { + + @get:Rule + val composeRule = createAndroidComposeRule() + + @Test + fun loginScreen_showsErrorMessage() { + composeRule.setContent { + LoginScreen( + state = AuthUiState( + email = "demo@daemonlord.ru", + password = "123456", + errorMessage = "Invalid email or password.", + ), + onEmailChanged = {}, + onPasswordChanged = {}, + onLoginClick = {}, + ) + } + + composeRule.onNodeWithText("Messenger Login").assertIsDisplayed() + composeRule.onNodeWithText("Invalid email or password.").assertIsDisplayed() + composeRule.onNodeWithText("Login").assertIsDisplayed() + } +} + diff --git a/android/app/src/androidTest/java/ru/daemonlord/messenger/ui/chats/ChatListScreenTest.kt b/android/app/src/androidTest/java/ru/daemonlord/messenger/ui/chats/ChatListScreenTest.kt new file mode 100644 index 0000000..8afb4f2 --- /dev/null +++ b/android/app/src/androidTest/java/ru/daemonlord/messenger/ui/chats/ChatListScreenTest.kt @@ -0,0 +1,51 @@ +package ru.daemonlord.messenger.ui.chats + +import androidx.activity.ComponentActivity +import androidx.compose.ui.test.assertIsDisplayed +import androidx.compose.ui.test.junit4.createAndroidComposeRule +import androidx.compose.ui.test.onNodeWithText +import org.junit.Rule +import org.junit.Test + +class ChatListScreenTest { + + @get:Rule + val composeRule = createAndroidComposeRule() + + @Test + fun chatListScreen_loadingState_showsLoadingText() { + composeRule.setContent { + ChatListScreen( + state = ChatListUiState(isLoading = true), + onTabSelected = {}, + onFilterSelected = {}, + onSearchChanged = {}, + onRefresh = {}, + onOpenSettings = {}, + onOpenProfile = {}, + onOpenChat = {}, + ) + } + + composeRule.onNodeWithText("Loading chats...").assertIsDisplayed() + } + + @Test + fun chatListScreen_emptyState_showsPlaceholder() { + composeRule.setContent { + ChatListScreen( + state = ChatListUiState(isLoading = false, chats = emptyList()), + onTabSelected = {}, + onFilterSelected = {}, + onSearchChanged = {}, + onRefresh = {}, + onOpenSettings = {}, + onOpenProfile = {}, + onOpenChat = {}, + ) + } + + composeRule.onNodeWithText("No chats found").assertIsDisplayed() + } +} + diff --git a/docs/android-checklist.md b/docs/android-checklist.md index 2971504..7b1b8fa 100644 --- a/docs/android-checklist.md +++ b/docs/android-checklist.md @@ -110,7 +110,7 @@ ## 15. Качество - [x] Unit tests (domain/data) -- [ ] UI tests (Compose test) +- [x] UI tests (Compose test) - [ ] Integration tests для auth/chat/realtime - [x] Performance baseline (startup, scroll, media) - [ ] ANR/crash budget + monitoring