7
7
8
8
package io.element.android.libraries.accountselect.impl
9
9
10
- import app.cash.molecule.RecompositionMode
11
- import app.cash.molecule.moleculeFlow
12
- import app.cash.turbine.test
13
10
import com.google.common.truth.Truth.assertThat
11
+ import io.element.android.libraries.matrix.api.user.MatrixUser
12
+ import io.element.android.libraries.matrix.test.A_SESSION_ID
13
+ import io.element.android.libraries.matrix.test.A_SESSION_ID_2
14
14
import io.element.android.libraries.sessionstorage.api.SessionStore
15
+ import io.element.android.libraries.sessionstorage.impl.memory.InMemoryMultiSessionsStore
15
16
import io.element.android.libraries.sessionstorage.impl.memory.InMemorySessionStore
17
+ import io.element.android.libraries.sessionstorage.test.aSessionData
16
18
import io.element.android.tests.testutils.WarmUpRule
17
- import kotlinx.coroutines.test.TestScope
19
+ import io.element.android.tests.testutils.test
18
20
import kotlinx.coroutines.test.runTest
19
21
import org.junit.Rule
20
22
import org.junit.Test
@@ -26,15 +28,50 @@ class AccountSelectPresenterTest {
26
28
@Test
27
29
fun `present - initial state` () = runTest {
28
30
val presenter = createAccountSelectPresenter()
29
- moleculeFlow(RecompositionMode .Immediate ) {
30
- presenter.present()
31
- }.test {
31
+ presenter.test {
32
32
val initialState = awaitItem()
33
33
assertThat(initialState.accounts).isEmpty()
34
34
}
35
35
}
36
36
37
- private fun TestScope.createAccountSelectPresenter (
37
+ @Test
38
+ fun `present - multiple accounts case` () = runTest {
39
+ val presenter = createAccountSelectPresenter(
40
+ sessionStore = InMemoryMultiSessionsStore ().apply {
41
+ addSession(aSessionData(sessionId = A_SESSION_ID .value))
42
+ addSession(
43
+ aSessionData(
44
+ sessionId = A_SESSION_ID_2 .value,
45
+ userDisplayName = " Bob" ,
46
+ userAvatarUrl = " avatarUrl" ,
47
+ )
48
+ )
49
+ }
50
+ )
51
+ presenter.test {
52
+ skipItems(1 )
53
+ val initialState = awaitItem()
54
+ assertThat(initialState.accounts).hasSize(2 )
55
+ val firstAccount = initialState.accounts[0 ]
56
+ assertThat(firstAccount).isEqualTo(
57
+ MatrixUser (
58
+ userId = A_SESSION_ID ,
59
+ displayName = null ,
60
+ avatarUrl = null ,
61
+ )
62
+ )
63
+ val secondAccount = initialState.accounts[1 ]
64
+ assertThat(secondAccount).isEqualTo(
65
+ MatrixUser (
66
+ userId = A_SESSION_ID_2 ,
67
+ displayName = " Bob" ,
68
+ avatarUrl = " avatarUrl" ,
69
+ )
70
+ )
71
+ }
72
+ }
73
+
74
+ private fun createAccountSelectPresenter (
38
75
sessionStore : SessionStore = InMemorySessionStore (),
39
76
) = AccountSelectPresenter (
40
77
sessionStore = sessionStore,
0 commit comments