Browse Source

Image uri test cases

Signed-off-by: sowjanyakch <sowjanya.kch@gmail.com>
sowjanyakch 1 year ago
parent
commit
a51e3b98ad

+ 20 - 2
app/src/test/java/com/nextcloud/talk/contacts/ContactsViewModelTest.kt

@@ -58,16 +58,18 @@ class ContactsViewModelTest {
         runTest {
             viewModel = ContactsViewModel(FakeRepositoryError())
             assert(viewModel.contactsViewState.value is ContactsUiState.Error)
+            val errorState = viewModel.contactsViewState.value as ContactsUiState.Error
+            assert(errorState.message == "unable to fetch contacts")
         }
 
     @Test
-    fun `update search query`()  {
+    fun `update search query`() {
         viewModel.updateSearchQuery("Ma")
         assert(viewModel.searchQuery.value == "Ma")
     }
 
     @Test
-    fun `initial search query is empty string`()  {
+    fun `initial search query is empty string`() {
         viewModel.updateSearchQuery("")
         assert(viewModel.searchQuery.value == "")
     }
@@ -104,5 +106,21 @@ class ContactsViewModelTest {
             viewModel = ContactsViewModel(FakeRepositoryError())
             viewModel.createRoom("1", "users", "s@gmail.com", null)
             assert(viewModel.roomViewState.value is RoomUiState.Error)
+            val errorState = viewModel.roomViewState.value as RoomUiState.Error
+            assert(errorState.message == "unable to create room")
         }
+
+    @Test
+    fun `test image uri`() {
+        val expectedImageUri = "https://mydomain.com/index.php/avatar/vidya/512"
+        val imageUri = viewModel.getImageUri("vidya", false)
+        assert(imageUri == expectedImageUri)
+    }
+
+    @Test
+    fun `test error image uri`() {
+        val expectedImageUri = "https://mydoman.com/index.php/avatar/vidya/512"
+        val imageUri = viewModel.getImageUri("vidya", false)
+        assert(imageUri != expectedImageUri)
+    }
 }

+ 3 - 3
app/src/test/java/com/nextcloud/talk/contacts/repository/FakeRepositoryError.kt

@@ -13,7 +13,7 @@ import com.nextcloud.talk.models.json.conversations.RoomOverall
 
 class FakeRepositoryError() : ContactsRepository {
     override suspend fun getContacts(searchQuery: String?, shareTypes: List<String>): AutocompleteOverall {
-        throw Exception("unknown error occurred")
+        throw Exception("unable to fetch contacts")
     }
 
     override suspend fun createRoom(
@@ -22,10 +22,10 @@ class FakeRepositoryError() : ContactsRepository {
         userId: String,
         conversationName: String?
     ): RoomOverall {
-        throw Exception("unknown error occurred")
+        throw Exception("unable to create room")
     }
 
     override fun getImageUri(avatarId: String, requestBigSize: Boolean): String {
-        throw Exception("unknown error occurred")
+        return "https://mydoman.com/index.php/avatar/$avatarId/512"
     }
 }