Add unit test on DefaultRageshakeFeatureAvailability

This commit is contained in:
Benoit Marty
2025-08-11 11:18:29 +02:00
parent 50809d2adb
commit e566bb37ed

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.features.rageshake.impl
import app.cash.turbine.test
import com.google.common.truth.Truth.assertThat
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.test.runTest
import okhttp3.HttpUrl
import okhttp3.HttpUrl.Companion.toHttpUrl
import org.junit.Test
class DefaultRageshakeFeatureAvailabilityTest {
@Test
fun `test isAvailable returns true when bug reporter URL is provided`() = runTest {
val flow = MutableStateFlow<HttpUrl?>(null)
val sut = DefaultRageshakeFeatureAvailability(
bugReporterUrlProvider = { flow },
)
sut.isAvailable().test {
assertThat(awaitItem()).isFalse()
flow.value = "https://example.com/bugreport".toHttpUrl()
assertThat(awaitItem()).isTrue()
flow.value = null
assertThat(awaitItem()).isFalse()
}
}
}