Skip to content

Commit e99d166

Browse files
committed
Add unit test on AccountProviderDataSource
1 parent 0a57849 commit e99d166

File tree

1 file changed

+84
-0
lines changed

1 file changed

+84
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
/*
2+
* Copyright 2025 New Vector Ltd.
3+
*
4+
* SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
5+
* Please see LICENSE files in the repository root for full details.
6+
*/
7+
8+
package io.element.android.features.login.impl.accountprovider
9+
10+
import app.cash.turbine.test
11+
import com.google.common.truth.Truth.assertThat
12+
import io.element.android.appconfig.AuthenticationConfig
13+
import io.element.android.features.enterprise.test.FakeEnterpriseService
14+
import io.element.android.tests.testutils.WarmUpRule
15+
import kotlinx.coroutines.test.runTest
16+
import org.junit.Rule
17+
import org.junit.Test
18+
19+
class AccountProviderDataSourceTest {
20+
@get:Rule
21+
val warmUpRule = WarmUpRule()
22+
23+
@Test
24+
fun `present - initial state`() = runTest {
25+
val sut = AccountProviderDataSource(FakeEnterpriseService())
26+
sut.flow().test {
27+
val initialState = awaitItem()
28+
assertThat(initialState).isEqualTo(
29+
AccountProvider(
30+
url = FakeEnterpriseService.A_FAKE_HOMESERVER,
31+
title = FakeEnterpriseService.A_FAKE_HOMESERVER,
32+
subtitle = null,
33+
isPublic = false,
34+
isMatrixOrg = false,
35+
isValid = false,
36+
)
37+
)
38+
}
39+
}
40+
41+
@Test
42+
fun `present - initial state - matrix org`() = runTest {
43+
val sut = AccountProviderDataSource(FakeEnterpriseService(
44+
defaultHomeserverResult = { AuthenticationConfig.MATRIX_ORG_URL }
45+
))
46+
sut.flow().test {
47+
val initialState = awaitItem()
48+
assertThat(initialState).isEqualTo(
49+
AccountProvider(
50+
url = AuthenticationConfig.MATRIX_ORG_URL,
51+
title = "matrix.org",
52+
subtitle = null,
53+
isPublic = true,
54+
isMatrixOrg = true,
55+
isValid = false,
56+
)
57+
)
58+
}
59+
}
60+
61+
@Test
62+
fun `present - user change and reset`() = runTest {
63+
val sut = AccountProviderDataSource(FakeEnterpriseService())
64+
sut.flow().test {
65+
val initialState = awaitItem()
66+
assertThat(initialState.url).isEqualTo(FakeEnterpriseService.A_FAKE_HOMESERVER)
67+
sut.userSelection(AccountProvider(url = "https://example.com"))
68+
val changedState = awaitItem()
69+
assertThat(changedState).isEqualTo(
70+
AccountProvider(
71+
url = "https://example.com",
72+
title = "example.com",
73+
subtitle = null,
74+
isPublic = false,
75+
isMatrixOrg = false,
76+
isValid = false,
77+
)
78+
)
79+
sut.reset()
80+
val resetState = awaitItem()
81+
assertThat(resetState.url).isEqualTo(FakeEnterpriseService.A_FAKE_HOMESERVER)
82+
}
83+
}
84+
}

0 commit comments

Comments
 (0)