|
7 | 7 |
|
8 | 8 | package io.element.android.libraries.matrix.ui.model
|
9 | 9 |
|
| 10 | +import androidx.test.ext.junit.runners.AndroidJUnit4 |
| 11 | +import app.cash.molecule.RecompositionMode |
| 12 | +import app.cash.molecule.moleculeFlow |
| 13 | +import app.cash.turbine.test |
10 | 14 | import com.google.common.truth.Truth.assertThat
|
11 | 15 | import io.element.android.libraries.designsystem.components.avatar.AvatarData
|
12 | 16 | import io.element.android.libraries.designsystem.components.avatar.AvatarSize
|
13 | 17 | import io.element.android.libraries.matrix.api.user.MatrixUser
|
14 | 18 | import io.element.android.libraries.matrix.test.A_USER_ID
|
| 19 | +import io.element.android.tests.testutils.WarmUpRule |
| 20 | +import io.element.android.tests.testutils.withConfigurationAndContext |
| 21 | +import kotlinx.coroutines.test.runTest |
| 22 | +import org.junit.Rule |
15 | 23 | import org.junit.Test
|
| 24 | +import org.junit.runner.RunWith |
16 | 25 |
|
| 26 | +@RunWith(AndroidJUnit4::class) |
17 | 27 | class MatrixUserExtensionsTest {
|
| 28 | + @get:Rule |
| 29 | + val warmUpRule = WarmUpRule() |
| 30 | + |
18 | 31 | @Test
|
19 | 32 | fun `getAvatarData should return the expected value`() {
|
20 | 33 | val matrixUser = MatrixUser(
|
@@ -59,20 +72,30 @@ class MatrixUserExtensionsTest {
|
59 | 72 | }
|
60 | 73 |
|
61 | 74 | @Test
|
62 |
| - fun `getFullName should return the display name is available and the userId`() { |
| 75 | + fun `getFullName should return the display name is available and the userId`() = runTest { |
63 | 76 | val matrixUser = MatrixUser(
|
64 | 77 | userId = A_USER_ID,
|
65 | 78 | displayName = "displayName",
|
66 | 79 | )
|
67 |
| - assertThat(matrixUser.getFullName()).isEqualTo("displayName (@alice:server.org)") |
| 80 | + moleculeFlow(RecompositionMode.Immediate) { |
| 81 | + withConfigurationAndContext { |
| 82 | + matrixUser.getFullName() |
| 83 | + } |
| 84 | + }.test { |
| 85 | + assertThat(awaitItem()).isEqualTo("displayName (@alice:server.org)") |
| 86 | + } |
68 | 87 | }
|
69 | 88 |
|
70 | 89 | @Test
|
71 |
| - fun `getBestName should return only the id when name is not available`() { |
| 90 | + fun `getBestName should return only the id when name is not available`() = runTest { |
72 | 91 | val matrixUser = MatrixUser(
|
73 | 92 | userId = A_USER_ID,
|
74 | 93 | displayName = null,
|
75 | 94 | )
|
76 |
| - assertThat(matrixUser.getFullName()).isEqualTo(A_USER_ID.value) |
| 95 | + moleculeFlow(RecompositionMode.Immediate) { |
| 96 | + matrixUser.getFullName() |
| 97 | + }.test { |
| 98 | + assertThat(awaitItem()).isEqualTo(A_USER_ID.value) |
| 99 | + } |
77 | 100 | }
|
78 | 101 | }
|
0 commit comments