Cleanup testImplementation dependencies (#4790)

This commit is contained in:
Benoit Marty 2025-06-02 10:51:02 +02:00 committed by GitHub
parent 6b82e62e7a
commit 2c96fb8871
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
25 changed files with 409 additions and 93 deletions

View file

@ -31,6 +31,7 @@ dependencies {
testImplementation(projects.libraries.matrix.test)
testImplementation(libs.test.junit)
testImplementation(libs.coroutines.test)
testImplementation(libs.molecule.runtime)
testImplementation(libs.test.turbine)
testImplementation(libs.test.truth)
}

View file

@ -0,0 +1,102 @@
/*
* Copyright 2025 New Vector Ltd.
*
* SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
* Please see LICENSE files in the repository root for full details.
*/
package io.element.android.libraries.indicator.impl
import app.cash.molecule.RecompositionMode
import app.cash.molecule.moleculeFlow
import app.cash.turbine.test
import com.google.common.truth.Truth.assertThat
import io.element.android.libraries.matrix.api.encryption.BackupState
import io.element.android.libraries.matrix.api.encryption.RecoveryState
import io.element.android.libraries.matrix.test.encryption.FakeEncryptionService
import io.element.android.libraries.matrix.test.verification.FakeSessionVerificationService
import kotlinx.coroutines.test.runTest
import org.junit.Test
class DefaultIndicatorServiceTest {
@Test
fun `test - showRoomListTopBarIndicator`() = runTest {
val encryptionService = FakeEncryptionService()
val sessionVerificationService = FakeSessionVerificationService()
val sut = DefaultIndicatorService(
sessionVerificationService = sessionVerificationService,
encryptionService = encryptionService,
)
moleculeFlow(RecompositionMode.Immediate) {
sut.showRoomListTopBarIndicator().value
}.test {
assertThat(awaitItem()).isTrue()
sessionVerificationService.emitNeedsSessionVerification(false)
encryptionService.emitBackupState(BackupState.ENABLED)
encryptionService.emitRecoveryState(RecoveryState.ENABLED)
assertThat(awaitItem()).isFalse()
sessionVerificationService.emitNeedsSessionVerification(true)
assertThat(awaitItem()).isTrue()
}
}
@Test
fun `test - showSettingChatBackupIndicator is true when BackupState is UNKNOWN`() = runTest {
val encryptionService = FakeEncryptionService()
val sessionVerificationService = FakeSessionVerificationService()
val sut = DefaultIndicatorService(
sessionVerificationService = sessionVerificationService,
encryptionService = encryptionService,
)
moleculeFlow(RecompositionMode.Immediate) {
sut.showSettingChatBackupIndicator().value
}.test {
assertThat(awaitItem()).isTrue()
encryptionService.emitBackupState(BackupState.ENABLED)
encryptionService.emitRecoveryState(RecoveryState.ENABLED)
assertThat(awaitItem()).isFalse()
encryptionService.emitBackupState(BackupState.UNKNOWN)
assertThat(awaitItem()).isTrue()
}
}
@Test
fun `test - showSettingChatBackupIndicator is true when recoveryState is DISABLED`() = runTest {
val encryptionService = FakeEncryptionService()
val sessionVerificationService = FakeSessionVerificationService()
val sut = DefaultIndicatorService(
sessionVerificationService = sessionVerificationService,
encryptionService = encryptionService,
)
moleculeFlow(RecompositionMode.Immediate) {
sut.showSettingChatBackupIndicator().value
}.test {
assertThat(awaitItem()).isTrue()
encryptionService.emitBackupState(BackupState.ENABLED)
encryptionService.emitRecoveryState(RecoveryState.ENABLED)
assertThat(awaitItem()).isFalse()
encryptionService.emitRecoveryState(RecoveryState.DISABLED)
assertThat(awaitItem()).isTrue()
}
}
@Test
fun `test - showSettingChatBackupIndicator is true when recoveryState is INCOMPLETE`() = runTest {
val encryptionService = FakeEncryptionService()
val sessionVerificationService = FakeSessionVerificationService()
val sut = DefaultIndicatorService(
sessionVerificationService = sessionVerificationService,
encryptionService = encryptionService,
)
moleculeFlow(RecompositionMode.Immediate) {
sut.showSettingChatBackupIndicator().value
}.test {
assertThat(awaitItem()).isTrue()
encryptionService.emitBackupState(BackupState.ENABLED)
encryptionService.emitRecoveryState(RecoveryState.ENABLED)
assertThat(awaitItem()).isFalse()
encryptionService.emitRecoveryState(RecoveryState.INCOMPLETE)
assertThat(awaitItem()).isTrue()
}
}
}

View file

@ -0,0 +1,19 @@
/*
* Copyright 2025 New Vector Ltd.
*
* SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
* Please see LICENSE files in the repository root for full details.
*/
plugins {
id("io.element.android-compose-library")
}
android {
namespace = "io.element.android.libraries.indicator.test"
}
dependencies {
implementation(projects.libraries.matrix.api)
api(projects.libraries.indicator.api)
}

View file

@ -0,0 +1,37 @@
/*
* Copyright 2025 New Vector Ltd.
*
* SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
* Please see LICENSE files in the repository root for full details.
*/
package io.element.android.libraries.indicator.test
import androidx.compose.runtime.Composable
import androidx.compose.runtime.MutableState
import androidx.compose.runtime.State
import androidx.compose.runtime.mutableStateOf
import io.element.android.libraries.indicator.api.IndicatorService
class FakeIndicatorService : IndicatorService {
private val showRoomListTopBarIndicatorResult: MutableState<Boolean> = mutableStateOf(false)
private val showSettingChatBackupIndicatorResult: MutableState<Boolean> = mutableStateOf(false)
fun setShowRoomListTopBarIndicator(value: Boolean) {
showRoomListTopBarIndicatorResult.value = value
}
fun setShowSettingChatBackupIndicator(value: Boolean) {
showSettingChatBackupIndicatorResult.value = value
}
@Composable
override fun showRoomListTopBarIndicator(): State<Boolean> {
return showRoomListTopBarIndicatorResult
}
@Composable
override fun showSettingChatBackupIndicator(): State<Boolean> {
return showSettingChatBackupIndicatorResult
}
}

View file

@ -40,6 +40,7 @@ dependencies {
api(projects.libraries.oidc.api)
testImplementation(libs.test.junit)
testImplementation(libs.test.robolectric)
testImplementation(libs.androidx.test.ext.junit)
testImplementation(libs.coroutines.test)
testImplementation(libs.molecule.runtime)

View file

@ -0,0 +1,69 @@
/*
* Copyright 2025 New Vector Ltd.
*
* SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
* Please see LICENSE files in the repository root for full details.
*/
package io.element.android.libraries.oidc.impl
import android.app.Activity
import android.content.Intent
import androidx.core.net.toUri
import com.google.common.truth.Truth.assertThat
import io.element.android.libraries.matrix.test.auth.FakeOidcRedirectUrlProvider
import io.element.android.libraries.oidc.api.OidcAction
import org.junit.Assert.assertThrows
import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner
import org.robolectric.RuntimeEnvironment
@RunWith(RobolectricTestRunner::class)
class DefaultOidcIntentResolverTest {
@Test
fun `test resolve oidc go back`() {
val sut = createDefaultOidcIntentResolver()
val intent = Intent(RuntimeEnvironment.getApplication(), Activity::class.java).apply {
action = Intent.ACTION_VIEW
data = "io.element.android:/?error=access_denied&state=IFF1UETGye2ZA8pO".toUri()
}
val result = sut.resolve(intent)
assertThat(result).isEqualTo(OidcAction.GoBack)
}
@Test
fun `test resolve oidc success`() {
val sut = createDefaultOidcIntentResolver()
val intent = Intent(RuntimeEnvironment.getApplication(), Activity::class.java).apply {
action = Intent.ACTION_VIEW
data = "io.element.android:/?state=IFF1UETGye2ZA8pO&code=y6X1GZeqA3xxOWcTeShgv8nkgFJXyzWB".toUri()
}
val result = sut.resolve(intent)
assertThat(result).isEqualTo(
OidcAction.Success(
url = "io.element.android:/?state=IFF1UETGye2ZA8pO&code=y6X1GZeqA3xxOWcTeShgv8nkgFJXyzWB"
)
)
}
@Test
fun `test resolve oidc invalid`() {
val sut = createDefaultOidcIntentResolver()
val intent = Intent(RuntimeEnvironment.getApplication(), Activity::class.java).apply {
action = Intent.ACTION_VIEW
data = "io.element.android:/invalid".toUri()
}
assertThrows(IllegalStateException::class.java) {
sut.resolve(intent)
}
}
private fun createDefaultOidcIntentResolver(): DefaultOidcIntentResolver {
return DefaultOidcIntentResolver(
oidcUrlParser = DefaultOidcUrlParser(
oidcRedirectUrlProvider = FakeOidcRedirectUrlProvider(),
),
)
}
}

View file

@ -0,0 +1,33 @@
/*
* Copyright 2025 New Vector Ltd.
*
* SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
* Please see LICENSE files in the repository root for full details.
*/
package io.element.android.libraries.oidc.impl.customtab
import com.google.common.truth.Truth.assertThat
import io.element.android.libraries.oidc.api.OidcAction
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import kotlinx.coroutines.test.runTest
import org.junit.Test
class DefaultOidcActionFlowTest {
@Test
fun `collect gets all the posted events`() = runTest {
val data = mutableListOf<OidcAction?>()
val sut = DefaultOidcActionFlow()
backgroundScope.launch {
sut.collect { action ->
data.add(action)
}
}
sut.post(OidcAction.GoBack)
delay(1)
sut.reset()
delay(1)
assertThat(data).containsExactly(OidcAction.GoBack, null)
}
}

View file

@ -0,0 +1,20 @@
/*
* Copyright 2025 New Vector Ltd.
*
* SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
* Please see LICENSE files in the repository root for full details.
*/
plugins {
id("io.element.android-library")
}
android {
namespace = "io.element.android.libraries.oidc.test"
}
dependencies {
implementation(libs.coroutines.core)
api(projects.libraries.oidc.api)
implementation(projects.tests.testutils)
}

View file

@ -0,0 +1,21 @@
/*
* Copyright 2025 New Vector Ltd.
*
* SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
* Please see LICENSE files in the repository root for full details.
*/
package io.element.android.libraries.oidc.test
import android.content.Intent
import io.element.android.libraries.oidc.api.OidcAction
import io.element.android.libraries.oidc.api.OidcIntentResolver
import io.element.android.tests.testutils.lambda.lambdaError
class FakeOidcIntentResolver(
private val resolveResult: (Intent) -> OidcAction? = { lambdaError() }
) : OidcIntentResolver {
override fun resolve(intent: Intent): OidcAction? {
return resolveResult(intent)
}
}

View file

@ -0,0 +1,32 @@
/*
* Copyright 2025 New Vector Ltd.
*
* SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
* Please see LICENSE files in the repository root for full details.
*/
package io.element.android.libraries.oidc.test.customtab
import io.element.android.libraries.oidc.api.OidcAction
import io.element.android.libraries.oidc.api.OidcActionFlow
import kotlinx.coroutines.flow.FlowCollector
import kotlinx.coroutines.flow.MutableStateFlow
/**
* This is actually a copy of DefaultOidcActionFlow.
*/
class FakeOidcActionFlow : OidcActionFlow {
private val mutableStateFlow = MutableStateFlow<OidcAction?>(null)
override fun post(oidcAction: OidcAction) {
mutableStateFlow.value = oidcAction
}
override suspend fun collect(collector: FlowCollector<OidcAction?>) {
mutableStateFlow.collect(collector)
}
override fun reset() {
mutableStateFlow.value = null
}
}

View file

@ -10,8 +10,8 @@ package io.element.android.libraries.permissions.impl.troubleshoot
import android.os.Build
import app.cash.turbine.test
import com.google.common.truth.Truth.assertThat
import io.element.android.libraries.permissions.impl.FakePermissionStateProvider
import io.element.android.libraries.permissions.impl.action.FakePermissionActions
import io.element.android.libraries.permissions.test.FakePermissionStateProvider
import io.element.android.libraries.troubleshoot.api.test.NotificationTroubleshootTestState
import io.element.android.services.toolbox.test.sdk.FakeBuildVersionSdkIntProvider
import io.element.android.services.toolbox.test.strings.FakeStringProvider

View file

@ -5,7 +5,7 @@
* Please see LICENSE files in the repository root for full details.
*/
package io.element.android.libraries.permissions.impl
package io.element.android.libraries.permissions.test
import io.element.android.libraries.permissions.api.PermissionStateProvider
import kotlinx.coroutines.flow.Flow