Skip to content

Commit

Permalink
Add tests for clicking on the avatar
Browse files Browse the repository at this point in the history
  • Loading branch information
jmartinesp committed May 8, 2024
1 parent bebc855 commit 19aba86
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@
package io.element.android.features.userprofile

import androidx.activity.ComponentActivity
import androidx.compose.ui.test.hasTestTag
import androidx.compose.ui.test.junit4.AndroidComposeTestRule
import androidx.compose.ui.test.junit4.createAndroidComposeRule
import androidx.compose.ui.test.performClick
import androidx.test.ext.junit.runners.AndroidJUnit4
import io.element.android.features.userprofile.shared.R
import io.element.android.features.userprofile.shared.UserProfileEvents
Expand All @@ -27,7 +29,10 @@ import io.element.android.features.userprofile.shared.UserProfileView
import io.element.android.features.userprofile.shared.aUserProfileState
import io.element.android.libraries.architecture.AsyncData
import io.element.android.libraries.matrix.api.core.RoomId
import io.element.android.libraries.matrix.test.AN_AVATAR_URL
import io.element.android.libraries.matrix.test.A_ROOM_ID
import io.element.android.libraries.matrix.test.A_USER_NAME
import io.element.android.libraries.testtags.TestTags
import io.element.android.libraries.ui.strings.CommonStrings
import io.element.android.tests.testutils.EnsureNeverCalled
import io.element.android.tests.testutils.EnsureNeverCalledWithParam
Expand All @@ -36,6 +41,7 @@ import io.element.android.tests.testutils.EventsRecorder
import io.element.android.tests.testutils.clickOn
import io.element.android.tests.testutils.ensureCalledOnce
import io.element.android.tests.testutils.ensureCalledOnceWithParam
import io.element.android.tests.testutils.ensureCalledOnceWithTwoParams
import io.element.android.tests.testutils.pressBack
import io.element.android.tests.testutils.pressBackKey
import kotlinx.coroutines.test.runTest
Expand Down Expand Up @@ -68,6 +74,27 @@ class UserProfileViewTest {
}
}

@Test
fun `on avatar clicked - the expected callback is called`() = runTest {
ensureCalledOnceWithTwoParams(A_USER_NAME, AN_AVATAR_URL) { callback ->
rule.setUserProfileView(
state = aUserProfileState(userName = A_USER_NAME, avatarUrl = AN_AVATAR_URL),
openAvatarPreview = callback,
)
rule.onNode(hasTestTag(TestTags.memberDetailAvatar.value)).performClick()
}
}

@Test
fun `on avatar clicked with no avatar - nothing happens`() = runTest {
val callback = EnsureNeverCalledWithTwoParams<String, String>()
rule.setUserProfileView(
state = aUserProfileState(userName = A_USER_NAME, avatarUrl = null),
openAvatarPreview = callback,
)
rule.onNode(hasTestTag(TestTags.memberDetailAvatar.value)).performClick()
}

@Test
fun `on Share clicked - the expected callback is called`() = runTest {
ensureCalledOnce { callback ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,9 @@ fun <T, R> ensureCalledOnceWithParam(param: T, block: (callback: EnsureCalledOnc
block(callback)
callback.assertSuccess()
}

fun <P1, P2> ensureCalledOnceWithTwoParams(param1: P1, param2: P2, block: (callback: EnsureCalledOnceWithTwoParams<P1, P2>) -> Unit) {
val callback = EnsureCalledOnceWithTwoParams(param1, param2)
block(callback)
callback.assertSuccess()
}

0 comments on commit 19aba86

Please sign in to comment.