1818package com.wire.android.navigation
1919
2020import com.wire.android.config.DefaultServerConfig
21- import com.wire.android.config.TestDispatcherProvider
2221import com.wire.android.util.newServerConfig
2322import com.wire.kalium.logic.CoreLogic
2423import com.wire.kalium.logic.configuration.server.ServerConfig
@@ -34,75 +33,60 @@ import org.amshove.kluent.internal.assertEquals
3433import org.junit.jupiter.api.Test
3534
3635class LoginTypeSelectorTest {
37- private val dispatcherProvider = TestDispatcherProvider ()
3836
3937 @Test
4038 fun `given default config with enterprise context, then can use new login` () =
41- runTest(dispatcherProvider.main()) {
39+ runTest {
4240 val (_, loginTypeSelector) = Arrangement ()
4341 .withContextFlowForConfig(DefaultServerConfig , flowOf(LoginContext .EnterpriseLogin ))
44- .arrange()
42+ .arrange(true )
4543 val result = loginTypeSelector.canUseNewLogin()
4644 assertEquals(true , result)
4745 }
4846
4947 @Test
5048 fun `given custom config with enterprise context, then can use new login` () =
51- runTest(dispatcherProvider.main()) {
49+ runTest {
5250 val config = newServerConfig(1 )
5351 val (_, loginTypeSelector) = Arrangement ()
5452 .withContextFlowForConfig(DefaultServerConfig , flowOf(LoginContext .FallbackLogin ))
5553 .withContextFlowForConfig(config.links, flowOf(LoginContext .EnterpriseLogin ))
56- .arrange()
54+ .arrange(true )
5755 val result = loginTypeSelector.canUseNewLogin(config.links)
5856 assertEquals(true , result)
5957 }
6058
6159 @Test
6260 fun `given default config with fallback context, then cannot use new login` () =
63- runTest(dispatcherProvider.main()) {
61+ runTest {
6462 val (_, loginTypeSelector) = Arrangement ()
6563 .withContextFlowForConfig(DefaultServerConfig , flowOf(LoginContext .FallbackLogin ))
66- .arrange()
64+ .arrange(false )
6765 val result = loginTypeSelector.canUseNewLogin()
6866 assertEquals(false , result)
6967 }
7068
7169 @Test
7270 fun `given custom config with fallback context, then cannot use new login` () =
73- runTest(dispatcherProvider.main()) {
71+ runTest {
7472 val config = newServerConfig(1 )
7573 val (_, loginTypeSelector) = Arrangement ()
7674 .withContextFlowForConfig(DefaultServerConfig , flowOf(LoginContext .EnterpriseLogin ))
7775 .withContextFlowForConfig(config.links, flowOf(LoginContext .FallbackLogin ))
78- .arrange()
76+ .arrange(true )
7977 val result = loginTypeSelector.canUseNewLogin(config.links)
8078 assertEquals(false , result)
8179 }
8280
83- @Test
84- fun `given default config with fallback context, when context changes to enterprise, then can use new login after it changes` () =
85- runTest(dispatcherProvider.main()) {
86- val contextFlow = MutableStateFlow <LoginContext >(LoginContext .FallbackLogin )
87- val (_, loginTypeSelector) = Arrangement ()
88- .withContextFlowForConfig(DefaultServerConfig , contextFlow)
89- .arrange()
90- val resultBeforeChange = loginTypeSelector.canUseNewLogin()
91- assertEquals(false , resultBeforeChange)
92- contextFlow.value = LoginContext .EnterpriseLogin
93- val resultAfterChange = loginTypeSelector.canUseNewLogin()
94- assertEquals(true , resultAfterChange)
95- }
96-
9781 @Test
9882 fun `given custom config with fallback context, when context changes to enterprise, then can use new login after it changes` () =
99- runTest(dispatcherProvider.main()) {
83+ runTest {
10084 val config = newServerConfig(1 )
10185 val contextFlow = MutableStateFlow <LoginContext >(LoginContext .FallbackLogin )
10286 val (_, loginTypeSelector) = Arrangement ()
10387 .withContextFlowForConfig(DefaultServerConfig , flowOf(LoginContext .FallbackLogin ))
10488 .withContextFlowForConfig(config.links, contextFlow)
105- .arrange()
89+ .arrange(true )
10690 val resultBeforeChange = loginTypeSelector.canUseNewLogin(config.links)
10791 assertEquals(false , resultBeforeChange)
10892 contextFlow.value = LoginContext .EnterpriseLogin
@@ -118,7 +102,7 @@ class LoginTypeSelectorTest {
118102 MockKAnnotations .init (this , relaxUnitFun = true )
119103 }
120104
121- suspend fun arrange () = this to LoginTypeSelector (dispatcherProvider, coreLogic). also { it. init () }
105+ fun arrange (useNewLoginForDefaultBackend : Boolean ) = this to LoginTypeSelector (coreLogic, useNewLoginForDefaultBackend)
122106
123107 fun withContextFlowForConfig (config : ServerConfig .Links , contextFlow : Flow <LoginContext >) = apply {
124108 coEvery { coreLogic.getGlobalScope().observeLoginContext(config) } returns contextFlow
0 commit comments