Localize Troubleshoot notification feature.
This commit is contained in:
parent
33526db485
commit
09b2cbaaf5
26 changed files with 221 additions and 64 deletions
|
|
@ -22,6 +22,8 @@ import io.element.android.libraries.core.notifications.NotificationTroubleshootT
|
|||
import io.element.android.libraries.core.notifications.NotificationTroubleshootTestState
|
||||
import io.element.android.libraries.di.AppScope
|
||||
import io.element.android.libraries.push.api.GetCurrentPushProvider
|
||||
import io.element.android.libraries.push.impl.R
|
||||
import io.element.android.services.toolbox.api.strings.StringProvider
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
import javax.inject.Inject
|
||||
|
|
@ -29,11 +31,12 @@ import javax.inject.Inject
|
|||
@ContributesMultibinding(AppScope::class)
|
||||
class CurrentPushProviderTest @Inject constructor(
|
||||
private val getCurrentPushProvider: GetCurrentPushProvider,
|
||||
private val stringProvider: StringProvider,
|
||||
) : NotificationTroubleshootTest {
|
||||
override val order = 110
|
||||
private val delegate = NotificationTroubleshootTestDelegate(
|
||||
defaultName = "Current push provider",
|
||||
defaultDescription = "Get the name of the current provider.",
|
||||
defaultName = stringProvider.getString(R.string.troubleshoot_notifications_test_current_push_provider_title),
|
||||
defaultDescription = stringProvider.getString(R.string.troubleshoot_notifications_test_current_push_provider_description),
|
||||
fakeDelay = NotificationTroubleshootTestDelegate.SHORT_DELAY,
|
||||
)
|
||||
override val state: StateFlow<NotificationTroubleshootTestState> = delegate.state
|
||||
|
|
@ -43,12 +46,12 @@ class CurrentPushProviderTest @Inject constructor(
|
|||
val provider = getCurrentPushProvider.getCurrentPushProvider()
|
||||
if (provider != null) {
|
||||
delegate.updateState(
|
||||
description = "Current push provider: $provider",
|
||||
description = stringProvider.getString(R.string.troubleshoot_notifications_test_current_push_provider_success, provider),
|
||||
status = NotificationTroubleshootTestState.Status.Success
|
||||
)
|
||||
} else {
|
||||
delegate.updateState(
|
||||
description = "No push providers selected",
|
||||
description = stringProvider.getString(R.string.troubleshoot_notifications_test_current_push_provider_failure),
|
||||
status = NotificationTroubleshootTestState.Status.Failure(false)
|
||||
)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,8 +21,10 @@ import io.element.android.libraries.core.notifications.NotificationTroubleshootT
|
|||
import io.element.android.libraries.core.notifications.NotificationTroubleshootTestDelegate
|
||||
import io.element.android.libraries.core.notifications.NotificationTroubleshootTestState
|
||||
import io.element.android.libraries.di.AppScope
|
||||
import io.element.android.libraries.push.impl.R
|
||||
import io.element.android.libraries.push.impl.notifications.NotificationDisplayer
|
||||
import io.element.android.libraries.push.impl.notifications.factories.NotificationCreator
|
||||
import io.element.android.services.toolbox.api.strings.StringProvider
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
import kotlinx.coroutines.flow.first
|
||||
|
|
@ -36,12 +38,13 @@ import kotlin.time.Duration.Companion.seconds
|
|||
class NotificationTest @Inject constructor(
|
||||
private val notificationCreator: NotificationCreator,
|
||||
private val notificationDisplayer: NotificationDisplayer,
|
||||
private val notificationClickHandler: NotificationClickHandler
|
||||
private val notificationClickHandler: NotificationClickHandler,
|
||||
private val stringProvider: StringProvider,
|
||||
) : NotificationTroubleshootTest {
|
||||
override val order = 50
|
||||
private val delegate = NotificationTroubleshootTestDelegate(
|
||||
defaultName = "Display notification",
|
||||
defaultDescription = "Check that the application can display notification",
|
||||
defaultName = stringProvider.getString(R.string.troubleshoot_notifications_test_display_notification_title),
|
||||
defaultDescription = stringProvider.getString(R.string.troubleshoot_notifications_test_display_notification_description),
|
||||
fakeDelay = NotificationTroubleshootTestDelegate.SHORT_DELAY,
|
||||
)
|
||||
override val state: StateFlow<NotificationTroubleshootTestState> = delegate.state
|
||||
|
|
@ -53,12 +56,12 @@ class NotificationTest @Inject constructor(
|
|||
if (result) {
|
||||
coroutineScope.listenToNotificationClick()
|
||||
delegate.updateState(
|
||||
description = "Please click on the notification to continue the test.",
|
||||
description = stringProvider.getString(R.string.troubleshoot_notifications_test_display_notification_waiting),
|
||||
status = NotificationTroubleshootTestState.Status.WaitingForUser
|
||||
)
|
||||
} else {
|
||||
delegate.updateState(
|
||||
description = "Cannot display the notification.",
|
||||
description = stringProvider.getString(R.string.troubleshoot_notifications_test_display_notification_permission_failure),
|
||||
status = NotificationTroubleshootTestState.Status.Failure(false)
|
||||
)
|
||||
}
|
||||
|
|
@ -76,12 +79,12 @@ class NotificationTest @Inject constructor(
|
|||
if (s == null) {
|
||||
notificationDisplayer.dismissDiagnosticNotification()
|
||||
delegate.updateState(
|
||||
description = "The notification has not been clicked.",
|
||||
description = stringProvider.getString(R.string.troubleshoot_notifications_test_display_notification_failure),
|
||||
status = NotificationTroubleshootTestState.Status.Failure(false)
|
||||
)
|
||||
} else {
|
||||
delegate.updateState(
|
||||
description = "The notification has been clicked!",
|
||||
description = stringProvider.getString(R.string.troubleshoot_notifications_test_display_notification_success),
|
||||
status = NotificationTroubleshootTestState.Status.Success
|
||||
)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,6 +23,8 @@ import io.element.android.libraries.core.notifications.NotificationTroubleshootT
|
|||
import io.element.android.libraries.di.AppScope
|
||||
import io.element.android.libraries.push.api.PushService
|
||||
import io.element.android.libraries.push.api.gateway.PushGatewayFailure
|
||||
import io.element.android.libraries.push.impl.R
|
||||
import io.element.android.services.toolbox.api.strings.StringProvider
|
||||
import io.element.android.services.toolbox.api.systemclock.SystemClock
|
||||
import kotlinx.coroutines.CompletableDeferred
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
|
|
@ -39,11 +41,12 @@ class PushLoopbackTest @Inject constructor(
|
|||
private val pushService: PushService,
|
||||
private val diagnosticPushHandler: DiagnosticPushHandler,
|
||||
private val clock: SystemClock,
|
||||
private val stringProvider: StringProvider,
|
||||
) : NotificationTroubleshootTest {
|
||||
override val order = 500
|
||||
private val delegate = NotificationTroubleshootTestDelegate(
|
||||
defaultName = "Test Push loopback",
|
||||
defaultDescription = "Ensure that the application is receiving push.",
|
||||
defaultName = stringProvider.getString(R.string.troubleshoot_notifications_test_push_loop_back_title),
|
||||
defaultDescription = stringProvider.getString(R.string.troubleshoot_notifications_test_push_loop_back_description),
|
||||
)
|
||||
override val state: StateFlow<NotificationTroubleshootTestState> = delegate.state
|
||||
|
||||
|
|
@ -59,7 +62,7 @@ class PushLoopbackTest @Inject constructor(
|
|||
pushService.testPush()
|
||||
} catch (pusherRejected: PushGatewayFailure.PusherRejected) {
|
||||
delegate.updateState(
|
||||
description = "Error: pusher has rejected the request.",
|
||||
description = stringProvider.getString(R.string.troubleshoot_notifications_test_push_loop_back_failure_1),
|
||||
status = NotificationTroubleshootTestState.Status.Failure(false)
|
||||
)
|
||||
job.cancel()
|
||||
|
|
@ -67,7 +70,7 @@ class PushLoopbackTest @Inject constructor(
|
|||
} catch (e: Exception) {
|
||||
Timber.e(e, "Failed to test push")
|
||||
delegate.updateState(
|
||||
description = "Error: ${e.message}.",
|
||||
description = stringProvider.getString(R.string.troubleshoot_notifications_test_push_loop_back_failure_2, e.message),
|
||||
status = NotificationTroubleshootTestState.Status.Failure(false)
|
||||
)
|
||||
job.cancel()
|
||||
|
|
@ -75,7 +78,7 @@ class PushLoopbackTest @Inject constructor(
|
|||
}
|
||||
if (!testPushResult) {
|
||||
delegate.updateState(
|
||||
description = "Error, cannot test push.",
|
||||
description = stringProvider.getString(R.string.troubleshoot_notifications_test_push_loop_back_failure_3),
|
||||
status = NotificationTroubleshootTestState.Status.Failure(false)
|
||||
)
|
||||
job.cancel()
|
||||
|
|
@ -87,12 +90,12 @@ class PushLoopbackTest @Inject constructor(
|
|||
job.cancel()
|
||||
if (result == null) {
|
||||
delegate.updateState(
|
||||
description = "Error, timeout waiting for push.",
|
||||
description = stringProvider.getString(R.string.troubleshoot_notifications_test_push_loop_back_failure_4),
|
||||
status = NotificationTroubleshootTestState.Status.Failure(false)
|
||||
)
|
||||
} else {
|
||||
delegate.updateState(
|
||||
description = "Push loopback took $result ms",
|
||||
description = stringProvider.getString(R.string.troubleshoot_notifications_test_push_loop_back_success, result),
|
||||
status = NotificationTroubleshootTestState.Status.Success
|
||||
)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,7 +21,9 @@ import io.element.android.libraries.core.notifications.NotificationTroubleshootT
|
|||
import io.element.android.libraries.core.notifications.NotificationTroubleshootTestDelegate
|
||||
import io.element.android.libraries.core.notifications.NotificationTroubleshootTestState
|
||||
import io.element.android.libraries.di.AppScope
|
||||
import io.element.android.libraries.push.impl.R
|
||||
import io.element.android.libraries.pushproviders.api.PushProvider
|
||||
import io.element.android.services.toolbox.api.strings.StringProvider
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
import javax.inject.Inject
|
||||
|
|
@ -29,12 +31,13 @@ import javax.inject.Inject
|
|||
@ContributesMultibinding(AppScope::class)
|
||||
class PushProvidersTest @Inject constructor(
|
||||
pushProviders: Set<@JvmSuppressWildcards PushProvider>,
|
||||
private val stringProvider: StringProvider,
|
||||
) : NotificationTroubleshootTest {
|
||||
private val sortedPushProvider = pushProviders.sortedBy { it.index }
|
||||
override val order = 100
|
||||
private val delegate = NotificationTroubleshootTestDelegate(
|
||||
defaultName = "Detect push providers",
|
||||
defaultDescription = "Ensure that the application has at least one push provider.",
|
||||
defaultName = stringProvider.getString(R.string.troubleshoot_notifications_test_detect_push_provider_title),
|
||||
defaultDescription = stringProvider.getString(R.string.troubleshoot_notifications_test_detect_push_provider_description),
|
||||
fakeDelay = NotificationTroubleshootTestDelegate.SHORT_DELAY,
|
||||
)
|
||||
override val state: StateFlow<NotificationTroubleshootTestState> = delegate.state
|
||||
|
|
@ -44,12 +47,17 @@ class PushProvidersTest @Inject constructor(
|
|||
val result = sortedPushProvider.isNotEmpty()
|
||||
if (result) {
|
||||
delegate.updateState(
|
||||
description = "Found ${sortedPushProvider.size} push providers: ${sortedPushProvider.joinToString { it.name }}",
|
||||
description = stringProvider.getQuantityString(
|
||||
resId = R.plurals.troubleshoot_notifications_test_detect_push_provider_success,
|
||||
quantity = sortedPushProvider.size,
|
||||
sortedPushProvider.size,
|
||||
sortedPushProvider.joinToString { it.name }
|
||||
),
|
||||
status = NotificationTroubleshootTestState.Status.Success
|
||||
)
|
||||
} else {
|
||||
delegate.updateState(
|
||||
description = "No push providers found",
|
||||
description = stringProvider.getString(R.string.troubleshoot_notifications_test_detect_push_provider_failure),
|
||||
status = NotificationTroubleshootTestState.Status.Failure(false)
|
||||
)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -50,4 +50,28 @@
|
|||
<string name="push_distributor_background_sync_android">"Background synchronization"</string>
|
||||
<string name="push_distributor_firebase_android">"Google Services"</string>
|
||||
<string name="push_no_valid_google_play_services_apk_android">"No valid Google Play Services found. Notifications may not work properly."</string>
|
||||
<string name="troubleshoot_notifications_test_current_push_provider_description">"Get the name of the current provider."</string>
|
||||
<string name="troubleshoot_notifications_test_current_push_provider_failure">"No push providers selected."</string>
|
||||
<string name="troubleshoot_notifications_test_current_push_provider_success">"Current push provider: %1$s."</string>
|
||||
<string name="troubleshoot_notifications_test_current_push_provider_title">"Current push provider"</string>
|
||||
<string name="troubleshoot_notifications_test_detect_push_provider_description">"Ensure that the application has at least one push provider."</string>
|
||||
<string name="troubleshoot_notifications_test_detect_push_provider_failure">"No push providers found."</string>
|
||||
<plurals name="troubleshoot_notifications_test_detect_push_provider_success">
|
||||
<item quantity="one">"Found %1$d push provider: %2$s"</item>
|
||||
<item quantity="other">"Found %1$d push providers: %2$s"</item>
|
||||
</plurals>
|
||||
<string name="troubleshoot_notifications_test_detect_push_provider_title">"Detect push providers"</string>
|
||||
<string name="troubleshoot_notifications_test_display_notification_description">"Check that the application can display notification."</string>
|
||||
<string name="troubleshoot_notifications_test_display_notification_failure">"The notification has not been clicked."</string>
|
||||
<string name="troubleshoot_notifications_test_display_notification_permission_failure">"Cannot display the notification."</string>
|
||||
<string name="troubleshoot_notifications_test_display_notification_success">"The notification has been clicked!"</string>
|
||||
<string name="troubleshoot_notifications_test_display_notification_title">"Display notification"</string>
|
||||
<string name="troubleshoot_notifications_test_display_notification_waiting">"Please click on the notification to continue the test."</string>
|
||||
<string name="troubleshoot_notifications_test_push_loop_back_description">"Ensure that the application is receiving push."</string>
|
||||
<string name="troubleshoot_notifications_test_push_loop_back_failure_1">"Error: pusher has rejected the request."</string>
|
||||
<string name="troubleshoot_notifications_test_push_loop_back_failure_2">"Error: %1$s."</string>
|
||||
<string name="troubleshoot_notifications_test_push_loop_back_failure_3">"Error, cannot test push."</string>
|
||||
<string name="troubleshoot_notifications_test_push_loop_back_failure_4">"Error, timeout waiting for push."</string>
|
||||
<string name="troubleshoot_notifications_test_push_loop_back_success">"Push loop back took %1$d ms."</string>
|
||||
<string name="troubleshoot_notifications_test_push_loop_back_title">"Test Push loop back"</string>
|
||||
</resources>
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ import app.cash.turbine.test
|
|||
import com.google.common.truth.Truth.assertThat
|
||||
import io.element.android.libraries.core.notifications.NotificationTroubleshootTestState
|
||||
import io.element.android.libraries.push.test.FakeGetCurrentPushProvider
|
||||
import io.element.android.services.toolbox.test.strings.FakeStringProvider
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.test.runTest
|
||||
import org.junit.Test
|
||||
|
|
@ -28,7 +29,8 @@ class CurrentPushProviderTestTest {
|
|||
@Test
|
||||
fun `test CurrentPushProviderTest with a push provider`() = runTest {
|
||||
val sut = CurrentPushProviderTest(
|
||||
getCurrentPushProvider = FakeGetCurrentPushProvider("foo")
|
||||
getCurrentPushProvider = FakeGetCurrentPushProvider("foo"),
|
||||
stringProvider = FakeStringProvider(),
|
||||
)
|
||||
launch {
|
||||
sut.run(this)
|
||||
|
|
@ -45,7 +47,8 @@ class CurrentPushProviderTestTest {
|
|||
@Test
|
||||
fun `test CurrentPushProviderTest without push provider`() = runTest {
|
||||
val sut = CurrentPushProviderTest(
|
||||
getCurrentPushProvider = FakeGetCurrentPushProvider(null)
|
||||
getCurrentPushProvider = FakeGetCurrentPushProvider(null),
|
||||
stringProvider = FakeStringProvider(),
|
||||
)
|
||||
launch {
|
||||
sut.run(this)
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ import com.google.common.truth.Truth.assertThat
|
|||
import io.element.android.libraries.core.notifications.NotificationTroubleshootTestState
|
||||
import io.element.android.libraries.push.impl.notifications.fake.MockkNotificationCreator
|
||||
import io.element.android.libraries.push.impl.notifications.fake.MockkNotificationDisplayer
|
||||
import io.element.android.services.toolbox.test.strings.FakeStringProvider
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.test.runTest
|
||||
import org.junit.Test
|
||||
|
|
@ -82,7 +83,8 @@ class NotificationTestTest {
|
|||
return NotificationTest(
|
||||
notificationCreator = mockkNotificationCreator.instance,
|
||||
notificationDisplayer = mockkNotificationDisplayer.instance,
|
||||
notificationClickHandler = notificationClickHandler
|
||||
notificationClickHandler = notificationClickHandler,
|
||||
stringProvider = FakeStringProvider(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ import io.element.android.libraries.matrix.test.AN_EXCEPTION
|
|||
import io.element.android.libraries.matrix.test.A_FAILURE_REASON
|
||||
import io.element.android.libraries.push.api.gateway.PushGatewayFailure
|
||||
import io.element.android.libraries.push.test.FakePushService
|
||||
import io.element.android.services.toolbox.test.strings.FakeStringProvider
|
||||
import io.element.android.services.toolbox.test.systemclock.FakeSystemClock
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.test.runTest
|
||||
|
|
@ -35,7 +36,8 @@ class PushLoopbackTestTest {
|
|||
val sut = PushLoopbackTest(
|
||||
pushService = FakePushService(),
|
||||
diagnosticPushHandler = diagnosticPushHandler,
|
||||
clock = FakeSystemClock()
|
||||
clock = FakeSystemClock(),
|
||||
stringProvider = FakeStringProvider(),
|
||||
)
|
||||
launch {
|
||||
sut.run(this)
|
||||
|
|
@ -45,7 +47,6 @@ class PushLoopbackTestTest {
|
|||
assertThat(awaitItem().status).isEqualTo(NotificationTroubleshootTestState.Status.InProgress)
|
||||
val lastItem = awaitItem()
|
||||
assertThat(lastItem.status).isEqualTo(NotificationTroubleshootTestState.Status.Failure(false))
|
||||
assertThat(lastItem.description).contains("timeout")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -59,7 +60,8 @@ class PushLoopbackTestTest {
|
|||
}
|
||||
),
|
||||
diagnosticPushHandler = diagnosticPushHandler,
|
||||
clock = FakeSystemClock()
|
||||
clock = FakeSystemClock(),
|
||||
stringProvider = FakeStringProvider(),
|
||||
)
|
||||
launch {
|
||||
sut.run(this)
|
||||
|
|
@ -69,7 +71,6 @@ class PushLoopbackTestTest {
|
|||
assertThat(awaitItem().status).isEqualTo(NotificationTroubleshootTestState.Status.InProgress)
|
||||
val lastItem = awaitItem()
|
||||
assertThat(lastItem.status).isEqualTo(NotificationTroubleshootTestState.Status.Failure(false))
|
||||
assertThat(lastItem.description).contains("rejected")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -81,7 +82,8 @@ class PushLoopbackTestTest {
|
|||
testPushBlock = { false }
|
||||
),
|
||||
diagnosticPushHandler = diagnosticPushHandler,
|
||||
clock = FakeSystemClock()
|
||||
clock = FakeSystemClock(),
|
||||
stringProvider = FakeStringProvider(),
|
||||
)
|
||||
launch {
|
||||
sut.run(this)
|
||||
|
|
@ -91,7 +93,6 @@ class PushLoopbackTestTest {
|
|||
assertThat(awaitItem().status).isEqualTo(NotificationTroubleshootTestState.Status.InProgress)
|
||||
val lastItem = awaitItem()
|
||||
assertThat(lastItem.status).isEqualTo(NotificationTroubleshootTestState.Status.Failure(false))
|
||||
assertThat(lastItem.description).contains("cannot test push")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -105,7 +106,8 @@ class PushLoopbackTestTest {
|
|||
}
|
||||
),
|
||||
diagnosticPushHandler = diagnosticPushHandler,
|
||||
clock = FakeSystemClock()
|
||||
clock = FakeSystemClock(),
|
||||
stringProvider = FakeStringProvider(),
|
||||
)
|
||||
launch {
|
||||
sut.run(this)
|
||||
|
|
@ -128,7 +130,8 @@ class PushLoopbackTestTest {
|
|||
true
|
||||
}),
|
||||
diagnosticPushHandler = diagnosticPushHandler,
|
||||
clock = FakeSystemClock()
|
||||
clock = FakeSystemClock(),
|
||||
stringProvider = FakeStringProvider(),
|
||||
)
|
||||
launch {
|
||||
sut.run(this)
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ import app.cash.turbine.test
|
|||
import com.google.common.truth.Truth.assertThat
|
||||
import io.element.android.libraries.core.notifications.NotificationTroubleshootTestState
|
||||
import io.element.android.libraries.pushproviders.test.FakePushProvider
|
||||
import io.element.android.services.toolbox.test.strings.FakeStringProvider
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.test.runTest
|
||||
import org.junit.Test
|
||||
|
|
@ -29,6 +30,7 @@ class PushProvidersTestTest {
|
|||
fun `test PushProvidersTest with empty list`() = runTest {
|
||||
val sut = PushProvidersTest(
|
||||
pushProviders = emptySet(),
|
||||
stringProvider = FakeStringProvider(),
|
||||
)
|
||||
launch {
|
||||
sut.run(this)
|
||||
|
|
@ -48,6 +50,7 @@ class PushProvidersTestTest {
|
|||
FakePushProvider(name = "foo"),
|
||||
FakePushProvider(name = "bar"),
|
||||
),
|
||||
stringProvider = FakeStringProvider(),
|
||||
)
|
||||
launch {
|
||||
sut.run(this)
|
||||
|
|
@ -57,6 +60,7 @@ class PushProvidersTestTest {
|
|||
assertThat(awaitItem().status).isEqualTo(NotificationTroubleshootTestState.Status.InProgress)
|
||||
val lastItem = awaitItem()
|
||||
assertThat(lastItem.status).isEqualTo(NotificationTroubleshootTestState.Status.Success)
|
||||
assertThat(lastItem.description).contains("2")
|
||||
assertThat(lastItem.description).contains("foo")
|
||||
assertThat(lastItem.description).contains("bar")
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue