Create dedicated module for notification troubleshoot.

This commit is contained in:
Benoit Marty 2024-04-02 18:03:39 +02:00 committed by Benoit Marty
parent 4f320fd4f8
commit cb435c523b
60 changed files with 355 additions and 141 deletions

View file

@ -24,6 +24,7 @@ import com.bumble.appyx.core.node.Node
import com.bumble.appyx.core.plugin.Plugin
import com.bumble.appyx.core.plugin.plugins
import com.bumble.appyx.navmodel.backstack.BackStack
import com.bumble.appyx.navmodel.backstack.operation.pop
import com.bumble.appyx.navmodel.backstack.operation.push
import dagger.assisted.Assisted
import dagger.assisted.AssistedInject
@ -39,7 +40,6 @@ import io.element.android.features.preferences.impl.developer.DeveloperSettingsN
import io.element.android.features.preferences.impl.developer.tracing.ConfigureTracingNode
import io.element.android.features.preferences.impl.notifications.NotificationSettingsNode
import io.element.android.features.preferences.impl.notifications.edit.EditDefaultNotificationSettingNode
import io.element.android.features.preferences.impl.notifications.troubleshoot.TroubleshootNotificationsNode
import io.element.android.features.preferences.impl.root.PreferencesRootNode
import io.element.android.features.preferences.impl.user.editprofile.EditUserProfileNode
import io.element.android.libraries.architecture.BackstackView
@ -48,6 +48,7 @@ import io.element.android.libraries.architecture.createNode
import io.element.android.libraries.di.SessionScope
import io.element.android.libraries.matrix.api.core.RoomId
import io.element.android.libraries.matrix.api.user.MatrixUser
import io.element.android.libraries.troubleshoot.api.NotificationTroubleShootEntryPoint
import kotlinx.parcelize.Parcelize
@ContributesNode(SessionScope::class)
@ -55,6 +56,7 @@ class PreferencesFlowNode @AssistedInject constructor(
@Assisted buildContext: BuildContext,
@Assisted plugins: List<Plugin>,
private val lockScreenEntryPoint: LockScreenEntryPoint,
private val notificationTroubleShootEntryPoint: NotificationTroubleShootEntryPoint,
private val logoutEntryPoint: LogoutEntryPoint,
) : BaseFlowNode<PreferencesFlowNode.NavTarget>(
backstack = BackStack(
@ -189,7 +191,13 @@ class PreferencesFlowNode @AssistedInject constructor(
createNode<NotificationSettingsNode>(buildContext, listOf(notificationSettingsCallback))
}
NavTarget.TroubleshootNotifications -> {
createNode<TroubleshootNotificationsNode>(buildContext)
notificationTroubleShootEntryPoint.nodeBuilder(this, buildContext)
.callback(object : NotificationTroubleShootEntryPoint.Callback {
override fun onDone() {
backstack.pop()
}
})
.build()
}
is NavTarget.EditDefaultNotificationSetting -> {
val callback = object : EditDefaultNotificationSettingNode.Callback {

View file

@ -1,23 +0,0 @@
/*
* Copyright (c) 2024 New Vector Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.element.android.features.preferences.impl.notifications.troubleshoot
sealed interface TroubleshootNotificationsEvents {
data object StartTests : TroubleshootNotificationsEvents
data object RetryFailedTests : TroubleshootNotificationsEvents
data class QuickFix(val testIndex: Int) : TroubleshootNotificationsEvents
}

View file

@ -1,48 +0,0 @@
/*
* Copyright (c) 2024 New Vector Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.element.android.features.preferences.impl.notifications.troubleshoot
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import com.bumble.appyx.core.modality.BuildContext
import com.bumble.appyx.core.node.Node
import com.bumble.appyx.core.plugin.Plugin
import dagger.assisted.Assisted
import dagger.assisted.AssistedInject
import im.vector.app.features.analytics.plan.MobileScreen
import io.element.android.anvilannotations.ContributesNode
import io.element.android.libraries.di.SessionScope
import io.element.android.services.analytics.api.ScreenTracker
@ContributesNode(SessionScope::class)
class TroubleshootNotificationsNode @AssistedInject constructor(
@Assisted buildContext: BuildContext,
@Assisted plugins: List<Plugin>,
private val presenter: TroubleshootNotificationsPresenter,
private val screenTracker: ScreenTracker,
) : Node(buildContext, plugins = plugins) {
@Composable
override fun View(modifier: Modifier) {
screenTracker.TrackScreen(MobileScreen.ScreenName.NotificationTroubleshoot)
val state = presenter.present()
TroubleshootNotificationsView(
state = state,
onBackPressed = ::navigateUp,
modifier = modifier,
)
}
}

View file

@ -1,58 +0,0 @@
/*
* Copyright (c) 2024 New Vector Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.element.android.features.preferences.impl.notifications.troubleshoot
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.rememberCoroutineScope
import io.element.android.libraries.architecture.Presenter
import kotlinx.coroutines.launch
import javax.inject.Inject
class TroubleshootNotificationsPresenter @Inject constructor(
private val troubleshootTestSuite: TroubleshootTestSuite,
) : Presenter<TroubleshootNotificationsState> {
@Composable
override fun present(): TroubleshootNotificationsState {
val coroutineScope = rememberCoroutineScope()
LaunchedEffect(Unit) {
troubleshootTestSuite.start(this)
}
val testSuiteState by troubleshootTestSuite.state.collectAsState()
fun handleEvents(event: TroubleshootNotificationsEvents) {
when (event) {
TroubleshootNotificationsEvents.StartTests -> coroutineScope.launch {
troubleshootTestSuite.runTestSuite(this)
}
is TroubleshootNotificationsEvents.QuickFix -> coroutineScope.launch {
troubleshootTestSuite.quickFix(event.testIndex, this)
}
TroubleshootNotificationsEvents.RetryFailedTests -> coroutineScope.launch {
troubleshootTestSuite.retryFailedTest(this)
}
}
}
return TroubleshootNotificationsState(
testSuiteState = testSuiteState,
eventSink = ::handleEvents
)
}
}

View file

@ -1,24 +0,0 @@
/*
* Copyright (c) 2024 New Vector Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.element.android.features.preferences.impl.notifications.troubleshoot
data class TroubleshootNotificationsState(
val testSuiteState: TroubleshootTestSuiteState,
val eventSink: (TroubleshootNotificationsEvents) -> Unit,
) {
val hasFailedTests: Boolean = testSuiteState.mainState.isFailure()
}

View file

@ -1,119 +0,0 @@
/*
* Copyright (c) 2024 New Vector Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.element.android.features.preferences.impl.notifications.troubleshoot
import androidx.compose.ui.tooling.preview.PreviewParameterProvider
import io.element.android.libraries.core.notifications.NotificationTroubleshootTestState
import kotlinx.collections.immutable.toImmutableList
open class TroubleshootNotificationsStateProvider : PreviewParameterProvider<TroubleshootNotificationsState> {
override val values: Sequence<TroubleshootNotificationsState>
get() = sequenceOf(
aTroubleshootNotificationsState(
listOf(
aTroubleshootTestStateIdle(),
aTroubleshootTestStateIdle(),
aTroubleshootTestStateIdle(visible = false),
)
),
aTroubleshootNotificationsState(
listOf(
aTroubleshootTestStateInProgress(),
aTroubleshootTestStateIdle(),
aTroubleshootTestStateIdle(),
)
),
aTroubleshootNotificationsState(
listOf(
aTroubleshootTestStateSuccess(),
aTroubleshootTestStateInProgress(),
aTroubleshootTestStateIdle(),
)
),
aTroubleshootNotificationsState(
listOf(
aTroubleshootTestStateSuccess(),
aTroubleshootTestStateWaitingForUser(),
aTroubleshootTestStateIdle(),
)
),
aTroubleshootNotificationsState(
listOf(
aTroubleshootTestStateSuccess(),
aTroubleshootTestStateFailure(hasQuickFix = true),
aTroubleshootTestStateInProgress(),
)
),
aTroubleshootNotificationsState(
listOf(
aTroubleshootTestStateSuccess(),
aTroubleshootTestStateFailure(hasQuickFix = true),
aTroubleshootTestStateFailure(hasQuickFix = false),
)
),
aTroubleshootNotificationsState(
listOf(
aTroubleshootTestStateSuccess(),
aTroubleshootTestStateSuccess(),
aTroubleshootTestStateSuccess(),
)
),
aTroubleshootNotificationsState(
listOf(
aTroubleshootTestStateWaitingForUser(),
)
),
)
}
fun aTroubleshootNotificationsState(
tests: List<NotificationTroubleshootTestState> = emptyList(),
eventSink: (TroubleshootNotificationsEvents) -> Unit = {},
) = TroubleshootNotificationsState(
eventSink = eventSink,
testSuiteState = TroubleshootTestSuiteState(
mainState = tests.computeMainState(),
tests = tests.toImmutableList(),
),
)
fun aTroubleshootTestState(
status: NotificationTroubleshootTestState.Status,
name: String = "Test",
description: String = "Description",
): NotificationTroubleshootTestState {
return NotificationTroubleshootTestState(
name = name,
description = description,
status = status,
)
}
fun aTroubleshootTestStateIdle(visible: Boolean = true) =
aTroubleshootTestState(status = NotificationTroubleshootTestState.Status.Idle(visible = visible))
fun aTroubleshootTestStateInProgress() =
aTroubleshootTestState(status = NotificationTroubleshootTestState.Status.InProgress)
fun aTroubleshootTestStateWaitingForUser() =
aTroubleshootTestState(status = NotificationTroubleshootTestState.Status.WaitingForUser)
fun aTroubleshootTestStateSuccess() =
aTroubleshootTestState(status = NotificationTroubleshootTestState.Status.Success)
fun aTroubleshootTestStateFailure(hasQuickFix: Boolean) =
aTroubleshootTestState(status = NotificationTroubleshootTestState.Status.Failure(hasQuickFix = hasQuickFix))

View file

@ -1,224 +0,0 @@
/*
* Copyright (c) 2024 New Vector Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.element.android.features.preferences.impl.notifications.troubleshoot
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.progressSemantics
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.PreviewParameter
import androidx.compose.ui.unit.dp
import androidx.lifecycle.Lifecycle
import io.element.android.compound.theme.ElementTheme
import io.element.android.compound.tokens.generated.CompoundIcons
import io.element.android.features.preferences.impl.R
import io.element.android.libraries.architecture.AsyncAction
import io.element.android.libraries.core.notifications.NotificationTroubleshootTestState
import io.element.android.libraries.core.notifications.NotificationTroubleshootTestState.Status
import io.element.android.libraries.designsystem.components.list.ListItemContent
import io.element.android.libraries.designsystem.components.preferences.PreferencePage
import io.element.android.libraries.designsystem.preview.ElementPreview
import io.element.android.libraries.designsystem.preview.PreviewsDayNight
import io.element.android.libraries.designsystem.theme.components.Button
import io.element.android.libraries.designsystem.theme.components.CircularProgressIndicator
import io.element.android.libraries.designsystem.theme.components.Icon
import io.element.android.libraries.designsystem.theme.components.ListItem
import io.element.android.libraries.designsystem.theme.components.Text
import io.element.android.libraries.designsystem.utils.OnLifecycleEvent
@Composable
fun TroubleshootNotificationsView(
state: TroubleshootNotificationsState,
onBackPressed: () -> Unit,
modifier: Modifier = Modifier,
) {
OnLifecycleEvent { _, event ->
when (event) {
Lifecycle.Event.ON_RESUME -> {
if (state.hasFailedTests) {
state.eventSink(TroubleshootNotificationsEvents.RetryFailedTests)
}
}
else -> Unit
}
}
PreferencePage(
modifier = modifier,
onBackPressed = onBackPressed,
title = stringResource(id = R.string.troubleshoot_notifications_screen_title),
) {
TroubleshootNotificationsContent(state)
}
}
@Composable
private fun TroubleshootTestView(
testState: NotificationTroubleshootTestState,
onQuickFixClicked: () -> Unit,
) {
if ((testState.status as? Status.Idle)?.visible == false) return
ListItem(
headlineContent = { Text(text = testState.name) },
supportingContent = { Text(text = testState.description) },
trailingContent = when (testState.status) {
is Status.Idle -> null
Status.InProgress -> ListItemContent.Custom {
CircularProgressIndicator(
modifier = Modifier
.progressSemantics()
.size(20.dp),
strokeWidth = 2.dp
)
}
Status.WaitingForUser -> ListItemContent.Custom {
Icon(
contentDescription = null,
modifier = Modifier.size(24.dp),
imageVector = CompoundIcons.Info(),
tint = ElementTheme.colors.iconAccentTertiary
)
}
Status.Success -> ListItemContent.Custom {
Icon(
contentDescription = null,
modifier = Modifier.size(24.dp),
imageVector = CompoundIcons.Check(),
tint = ElementTheme.colors.iconAccentTertiary
)
}
is Status.Failure -> ListItemContent.Custom {
Icon(
contentDescription = null,
modifier = Modifier.size(24.dp),
imageVector = CompoundIcons.Error(),
tint = ElementTheme.colors.textCriticalPrimary
)
}
}
)
if ((testState.status as? Status.Failure)?.hasQuickFix == true) {
ListItem(
headlineContent = {
},
trailingContent = ListItemContent.Custom {
Button(
text = stringResource(id = R.string.troubleshoot_notifications_screen_quick_fix_action),
onClick = onQuickFixClicked
)
}
)
}
}
@Composable
private fun TroubleshootNotificationsContent(state: TroubleshootNotificationsState) {
when (state.testSuiteState.mainState) {
AsyncAction.Loading,
AsyncAction.Confirming,
is AsyncAction.Success,
is AsyncAction.Failure -> {
TestSuiteView(
testSuiteState = state.testSuiteState,
onQuickFixClicked = {
state.eventSink(TroubleshootNotificationsEvents.QuickFix(it))
}
)
}
AsyncAction.Uninitialized -> Unit
}
when (state.testSuiteState.mainState) {
AsyncAction.Uninitialized -> {
ListItem(headlineContent = {
Text(
text = stringResource(id = R.string.troubleshoot_notifications_screen_notice)
)
})
RunTestButton(state = state)
}
AsyncAction.Loading -> Unit
is AsyncAction.Failure -> {
ListItem(headlineContent = {
Text(text = stringResource(id = R.string.troubleshoot_notifications_screen_failure))
})
RunTestButton(state = state)
}
AsyncAction.Confirming -> {
ListItem(headlineContent = {
Text(
text = stringResource(id = R.string.troubleshoot_notifications_screen_waiting)
)
})
}
is AsyncAction.Success -> {
ListItem(headlineContent = {
Text(
text = stringResource(id = R.string.troubleshoot_notifications_screen_success)
)
})
}
}
}
@Composable
private fun RunTestButton(state: TroubleshootNotificationsState) {
ListItem(
headlineContent = {
Button(
text = stringResource(
id = if (state.testSuiteState.mainState is AsyncAction.Failure) {
R.string.troubleshoot_notifications_screen_action_again
} else {
R.string.troubleshoot_notifications_screen_action
}
),
onClick = {
state.eventSink(TroubleshootNotificationsEvents.StartTests)
},
modifier = Modifier.fillMaxWidth(),
)
}
)
}
@Composable
private fun TestSuiteView(
testSuiteState: TroubleshootTestSuiteState,
onQuickFixClicked: (Int) -> Unit,
) {
testSuiteState.tests.forEachIndexed { index, testState ->
TroubleshootTestView(
testState = testState,
onQuickFixClicked = {
onQuickFixClicked(index)
},
)
}
}
@PreviewsDayNight
@Composable
internal fun TroubleshootNotificationsViewPreview(
@PreviewParameter(TroubleshootNotificationsStateProvider::class) state: TroubleshootNotificationsState,
) = ElementPreview {
TroubleshootNotificationsView(
state = state,
onBackPressed = {},
)
}

View file

@ -1,122 +0,0 @@
/*
* Copyright (c) 2024 New Vector Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.element.android.features.preferences.impl.notifications.troubleshoot
import im.vector.app.features.analytics.plan.NotificationTroubleshoot
import io.element.android.libraries.architecture.AsyncAction
import io.element.android.libraries.core.notifications.NotificationTroubleshootTest
import io.element.android.libraries.core.notifications.NotificationTroubleshootTestState
import io.element.android.libraries.core.notifications.TestFilterData
import io.element.android.libraries.push.api.GetCurrentPushProvider
import io.element.android.services.analytics.api.AnalyticsService
import kotlinx.collections.immutable.toImmutableList
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach
import javax.inject.Inject
class TroubleshootTestSuite @Inject constructor(
private val notificationTroubleshootTests: Set<@JvmSuppressWildcards NotificationTroubleshootTest>,
private val getCurrentPushProvider: GetCurrentPushProvider,
private val analyticsService: AnalyticsService,
) {
lateinit var tests: List<NotificationTroubleshootTest>
private val _state: MutableStateFlow<TroubleshootTestSuiteState> = MutableStateFlow(
TroubleshootTestSuiteState(
mainState = AsyncAction.Uninitialized,
tests = emptyList<NotificationTroubleshootTestState>().toImmutableList()
)
)
val state: StateFlow<TroubleshootTestSuiteState> = _state
suspend fun start(coroutineScope: CoroutineScope) {
val testFilterData = TestFilterData(
currentPushProviderName = getCurrentPushProvider.getCurrentPushProvider()
)
tests = notificationTroubleshootTests
.filter { it.isRelevant(testFilterData) }
.sortedBy { it.order }
tests.forEach {
// Observe the state of the tests
it.state.onEach {
emitState()
}.launchIn(coroutineScope)
}
}
suspend fun runTestSuite(coroutineScope: CoroutineScope) {
tests.forEach {
it.reset()
}
tests.forEach {
it.run(coroutineScope)
}
}
suspend fun retryFailedTest(coroutineScope: CoroutineScope) {
tests
.filter { it.state.value.status is NotificationTroubleshootTestState.Status.Failure }
.forEach {
it.run(coroutineScope)
}
}
private suspend fun emitState() {
val states = tests.map { it.state.value }
val mainState = states.computeMainState()
when (mainState) {
is AsyncAction.Success -> {
analyticsService.capture(NotificationTroubleshoot(hasError = false))
}
is AsyncAction.Failure -> {
analyticsService.capture(NotificationTroubleshoot(hasError = true))
}
else -> Unit
}
_state.emit(
TroubleshootTestSuiteState(
mainState = states.computeMainState(),
tests = states.toImmutableList()
)
)
}
suspend fun quickFix(testIndex: Int, coroutineScope: CoroutineScope) {
tests[testIndex].quickFix(coroutineScope)
}
}
fun List<NotificationTroubleshootTestState>.computeMainState(): AsyncAction<Unit> {
val isIdle = all { it.status is NotificationTroubleshootTestState.Status.Idle }
val isRunning = any { it.status is NotificationTroubleshootTestState.Status.InProgress }
return when {
isIdle -> AsyncAction.Uninitialized
isRunning -> AsyncAction.Loading
else -> {
if (any { it.status is NotificationTroubleshootTestState.Status.WaitingForUser }) {
AsyncAction.Confirming
} else if (any { it.status is NotificationTroubleshootTestState.Status.Failure }) {
AsyncAction.Failure(Exception("Some tests failed"))
} else {
AsyncAction.Success(Unit)
}
}
}
}

View file

@ -1,26 +0,0 @@
/*
* Copyright (c) 2024 New Vector Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.element.android.features.preferences.impl.notifications.troubleshoot
import io.element.android.libraries.architecture.AsyncAction
import io.element.android.libraries.core.notifications.NotificationTroubleshootTestState
import kotlinx.collections.immutable.ImmutableList
data class TroubleshootTestSuiteState(
val mainState: AsyncAction<Unit>,
val tests: ImmutableList<NotificationTroubleshootTestState>,
)

View file

@ -51,12 +51,4 @@
<string name="screen_notification_settings_title">"Апавяшчэнні"</string>
<string name="troubleshoot_notifications_entry_point_section">"Выпраўленне непаладак"</string>
<string name="troubleshoot_notifications_entry_point_title">"Выпраўленне непаладак з апавяшчэннямі"</string>
<string name="troubleshoot_notifications_screen_action">"Запусціць тэсты"</string>
<string name="troubleshoot_notifications_screen_action_again">"Запусціце тэсты яшчэ раз"</string>
<string name="troubleshoot_notifications_screen_failure">"Некаторыя тэсты не ўдаліся. Калі ласка, праглядзіце дэталі."</string>
<string name="troubleshoot_notifications_screen_notice">"Запусціце тэсты, каб выявіць праблемы ў вашай канфігурацыі, з-за якіх апавяшчэння могуць паводзіць сябе не так, як чакалася."</string>
<string name="troubleshoot_notifications_screen_quick_fix_action">"Спроба выпраўлення"</string>
<string name="troubleshoot_notifications_screen_success">"Усе тэсты паспяхова пройдзены."</string>
<string name="troubleshoot_notifications_screen_title">"Выпраўленне непаладак з апавяшчэннямі"</string>
<string name="troubleshoot_notifications_screen_waiting">"Некаторыя тэсты патрабуюць вашай увагі. Калі ласка, праглядзіце дэталі."</string>
</resources>

View file

@ -53,12 +53,4 @@ Pokud budete pokračovat, některá nastavení se mohou změnit."</string>
<string name="screen_notification_settings_title">"Oznámení"</string>
<string name="troubleshoot_notifications_entry_point_section">"Odstraňování problémů"</string>
<string name="troubleshoot_notifications_entry_point_title">"Odstraňování problémů s upozorněními"</string>
<string name="troubleshoot_notifications_screen_action">"Spustit testy"</string>
<string name="troubleshoot_notifications_screen_action_again">"Spustit testy znovu"</string>
<string name="troubleshoot_notifications_screen_failure">"Některé testy selhaly. Zkontrolujte prosím podrobnosti."</string>
<string name="troubleshoot_notifications_screen_notice">"Spusťte testy, abyste zjistili jakýkoli problém ve vaší konfiguraci, který může způsobit, že se oznámení nebudou chovat podle očekávání."</string>
<string name="troubleshoot_notifications_screen_quick_fix_action">"Pokus o opravu"</string>
<string name="troubleshoot_notifications_screen_success">"Všechny testy proběhly úspěšně."</string>
<string name="troubleshoot_notifications_screen_title">"Odstraňování problémů s upozorněními"</string>
<string name="troubleshoot_notifications_screen_waiting">"Některé testy vyžadují vaši pozornost. Zkontrolujte prosím podrobnosti."</string>
</resources>

View file

@ -51,12 +51,4 @@ Wenn du fortfährst, können sich einige deiner Einstellungen ändern."</string>
<string name="screen_notification_settings_title">"Benachrichtigungen"</string>
<string name="troubleshoot_notifications_entry_point_section">"Fehlerbehebung"</string>
<string name="troubleshoot_notifications_entry_point_title">"Fehlerbehebung für Benachrichtigungen"</string>
<string name="troubleshoot_notifications_screen_action">"Tests durchführen"</string>
<string name="troubleshoot_notifications_screen_action_again">"Tests erneut durchführen"</string>
<string name="troubleshoot_notifications_screen_failure">"Einige Tests sind fehlgeschlagen. Bitte überprüfe die Details."</string>
<string name="troubleshoot_notifications_screen_notice">"Führe die Tests durch, um Probleme zu erkennen, die dazu führen können, dass sich die Benachrichtigungen nicht wie erwartet verhalten."</string>
<string name="troubleshoot_notifications_screen_quick_fix_action">"Versuche das Problem zu beheben"</string>
<string name="troubleshoot_notifications_screen_success">"Alle Tests wurden erfolgreich bestanden."</string>
<string name="troubleshoot_notifications_screen_title">"Fehlerbehebung für Benachrichtigungen"</string>
<string name="troubleshoot_notifications_screen_waiting">"Einige Tests erfordern deine Aufmerksamkeit. Bitte überprüfe die Details."</string>
</resources>

View file

@ -51,12 +51,4 @@ Si vous continuez, il est possible que certains de vos paramètres soient modifi
<string name="screen_notification_settings_title">"Notifications"</string>
<string name="troubleshoot_notifications_entry_point_section">"Dépannage"</string>
<string name="troubleshoot_notifications_entry_point_title">"Résoudre les problèmes liés aux notifications"</string>
<string name="troubleshoot_notifications_screen_action">"Exécuter les tests"</string>
<string name="troubleshoot_notifications_screen_action_again">"Relancer les tests"</string>
<string name="troubleshoot_notifications_screen_failure">"Certains tests ont échoué. Veuillez vérifier les détails."</string>
<string name="troubleshoot_notifications_screen_notice">"Exécuter les tests pour détecter tout problème dans votre configuration susceptible de provoquer un dysfonctionnement des notifications."</string>
<string name="troubleshoot_notifications_screen_quick_fix_action">"Tenter de corriger"</string>
<string name="troubleshoot_notifications_screen_success">"Tous les tests ont réussi."</string>
<string name="troubleshoot_notifications_screen_title">"Dépanner les notifications"</string>
<string name="troubleshoot_notifications_screen_waiting">"Certains tests nécessitent votre attention. Veuillez vérifier les détails."</string>
</resources>

View file

@ -51,12 +51,4 @@ Ha folytatja, egyes beállítások megváltozhatnak."</string>
<string name="screen_notification_settings_title">"Értesítések"</string>
<string name="troubleshoot_notifications_entry_point_section">"Hibaelhárítás"</string>
<string name="troubleshoot_notifications_entry_point_title">"Értesítések hibaelhárítása"</string>
<string name="troubleshoot_notifications_screen_action">"Tesztek futtatása"</string>
<string name="troubleshoot_notifications_screen_action_again">"Tesztek újbóli futtatása"</string>
<string name="troubleshoot_notifications_screen_failure">"Egyes tesztek sikertelenek voltak. Ellenőrizze a részleteket."</string>
<string name="troubleshoot_notifications_screen_notice">"A tesztek futtatása, hogy észlelje a konfigurációban felmerülő olyan problémákat, amelyek miatt az értesítések nem az elvárt módon viselkednek."</string>
<string name="troubleshoot_notifications_screen_quick_fix_action">"Kísérlet a javításra"</string>
<string name="troubleshoot_notifications_screen_success">"Minden teszt sikeresen lezajlott."</string>
<string name="troubleshoot_notifications_screen_title">"Értesítések hibaelhárítása"</string>
<string name="troubleshoot_notifications_screen_waiting">"Egyes tesztek a figyelmét igénylik. Ellenőrizze a részleteket."</string>
</resources>

View file

@ -53,12 +53,4 @@ Jika Anda melanjutkan, beberapa pengaturan Anda dapat berubah."</string>
<string name="screen_notification_settings_title">"Notifikasi"</string>
<string name="troubleshoot_notifications_entry_point_section">"Pemecahan masalah"</string>
<string name="troubleshoot_notifications_entry_point_title">"Pecahkan masalah notifikasi"</string>
<string name="troubleshoot_notifications_screen_action">"Jalankan tes"</string>
<string name="troubleshoot_notifications_screen_action_again">"Jalankan tes lagi"</string>
<string name="troubleshoot_notifications_screen_failure">"Beberapa tes gagal. Silakan periksa detailnya."</string>
<string name="troubleshoot_notifications_screen_notice">"Jalankan pengujian untuk mendeteksi masalah apa pun dalam konfigurasi Anda yang mungkin membuat notifikasi tidak berperilaku seperti yang diharapkan."</string>
<string name="troubleshoot_notifications_screen_quick_fix_action">"Mencoba untuk memperbaiki"</string>
<string name="troubleshoot_notifications_screen_success">"Semua tes berhasil dilalui."</string>
<string name="troubleshoot_notifications_screen_title">"Pecahkan masalah notifikasi"</string>
<string name="troubleshoot_notifications_screen_waiting">"Beberapa tes membutuhkan perhatian Anda. Silakan periksa detailnya."</string>
</resources>

View file

@ -51,12 +51,4 @@
<string name="screen_notification_settings_title">"Уведомления"</string>
<string name="troubleshoot_notifications_entry_point_section">"Устранение неполадок"</string>
<string name="troubleshoot_notifications_entry_point_title">"Уведомления об устранении неполадок"</string>
<string name="troubleshoot_notifications_screen_action">"Выполнение тестов"</string>
<string name="troubleshoot_notifications_screen_action_again">"Повторное выполнение тестов"</string>
<string name="troubleshoot_notifications_screen_failure">"Некоторые тесты провалились. Пожалуйста, проверьте детали."</string>
<string name="troubleshoot_notifications_screen_notice">"Выполните тесты, чтобы обнаружить любую проблему в конфигурации, из-за которой уведомления могут работать не так, как ожидалось."</string>
<string name="troubleshoot_notifications_screen_quick_fix_action">"Попытка исправить"</string>
<string name="troubleshoot_notifications_screen_success">"Все тесты прошли успешно."</string>
<string name="troubleshoot_notifications_screen_title">"Уведомления об устранении неполадок"</string>
<string name="troubleshoot_notifications_screen_waiting">"Некоторые тесты требуют вашего внимания. Пожалуйста, проверьте детали."</string>
</resources>

View file

@ -53,12 +53,4 @@ Ak budete pokračovať, niektoré z vašich nastavení sa môžu zmeniť."</stri
<string name="screen_notification_settings_title">"Oznámenia"</string>
<string name="troubleshoot_notifications_entry_point_section">"Riešenie problémov"</string>
<string name="troubleshoot_notifications_entry_point_title">"Oznámenia riešení problémov"</string>
<string name="troubleshoot_notifications_screen_action">"Spustiť testy"</string>
<string name="troubleshoot_notifications_screen_action_again">"Spustiť testy znova"</string>
<string name="troubleshoot_notifications_screen_failure">"Niektoré testy zlyhali. Skontrolujte prosím podrobnosti."</string>
<string name="troubleshoot_notifications_screen_notice">"Spustite testy, aby ste zistili akýkoľvek problém vo vašej konfigurácii, ktorý môže spôsobiť, že sa upozornenia nebudú správať podľa očakávania."</string>
<string name="troubleshoot_notifications_screen_quick_fix_action">"Pokus o opravu"</string>
<string name="troubleshoot_notifications_screen_success">"Všetky testy prebehli úspešne."</string>
<string name="troubleshoot_notifications_screen_title">"Oznámenia riešení problémov"</string>
<string name="troubleshoot_notifications_screen_waiting">"Niektoré testy si vyžadujú vašu pozornosť. Prosím skontrolujte podrobnosti."</string>
</resources>

View file

@ -51,12 +51,4 @@ If you proceed, some of your settings may change."</string>
<string name="screen_notification_settings_title">"Notifications"</string>
<string name="troubleshoot_notifications_entry_point_section">"Troubleshoot"</string>
<string name="troubleshoot_notifications_entry_point_title">"Troubleshoot notifications"</string>
<string name="troubleshoot_notifications_screen_action">"Run tests"</string>
<string name="troubleshoot_notifications_screen_action_again">"Run tests again"</string>
<string name="troubleshoot_notifications_screen_failure">"Some tests failed. Please check the details."</string>
<string name="troubleshoot_notifications_screen_notice">"Run the tests to detect any issue in your configuration that may make notifications not behave as expected."</string>
<string name="troubleshoot_notifications_screen_quick_fix_action">"Attempt to fix"</string>
<string name="troubleshoot_notifications_screen_success">"All tests passed successfully."</string>
<string name="troubleshoot_notifications_screen_title">"Troubleshoot notifications"</string>
<string name="troubleshoot_notifications_screen_waiting">"Some tests require your attention. Please check the details."</string>
</resources>

View file

@ -1,82 +0,0 @@
/*
* Copyright (c) 2024 New Vector Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.element.android.features.preferences.impl.notifications.troubleshoot
import io.element.android.libraries.core.notifications.NotificationTroubleshootTest
import io.element.android.libraries.core.notifications.NotificationTroubleshootTestState
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.asStateFlow
class FakeNotificationTroubleshootTest(
override val order: Int = 0,
private val defaultName: String = "test name",
private val defaultDescription: String = "test description",
private val firstStatus: NotificationTroubleshootTestState.Status = NotificationTroubleshootTestState.Status.Idle(visible = true),
private val runAction: () -> NotificationTroubleshootTestState? = { null },
private val resetAction: () -> NotificationTroubleshootTestState? = { null },
private val quickFixAction: () -> NotificationTroubleshootTestState? = { null },
) : NotificationTroubleshootTest {
private val _state = MutableStateFlow(
NotificationTroubleshootTestState(
name = defaultName,
description = defaultDescription,
status = firstStatus
)
)
override val state: StateFlow<NotificationTroubleshootTestState> = _state.asStateFlow()
override suspend fun run(coroutineScope: CoroutineScope) {
updateState(NotificationTroubleshootTestState.Status.InProgress)
runAction()?.let {
_state.tryEmit(it)
}
}
override suspend fun reset() {
updateState(
name = defaultName,
description = defaultDescription,
status = firstStatus,
)
resetAction()?.let {
_state.emit(it)
}
}
override suspend fun quickFix(coroutineScope: CoroutineScope) {
updateState(NotificationTroubleshootTestState.Status.InProgress)
quickFixAction()?.let {
_state.emit(it)
}
}
suspend fun updateState(
status: NotificationTroubleshootTestState.Status,
name: String = defaultName,
description: String = defaultDescription,
) {
_state.emit(
NotificationTroubleshootTestState(
name = name,
description = description,
status = status,
)
)
}
}

View file

@ -1,128 +0,0 @@
/*
* Copyright (c) 2023 New Vector Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.element.android.features.preferences.impl.notifications.troubleshoot
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.architecture.AsyncAction
import io.element.android.libraries.core.notifications.NotificationTroubleshootTest
import io.element.android.libraries.core.notifications.NotificationTroubleshootTestState
import io.element.android.libraries.push.test.FakeGetCurrentPushProvider
import io.element.android.services.analytics.test.FakeAnalyticsService
import kotlinx.coroutines.test.runTest
import org.junit.Test
class TroubleshootNotificationsPresenterTests {
@Test
fun `present - initial state`() = runTest {
val presenter = createTroubleshootNotificationsPresenter()
moleculeFlow(RecompositionMode.Immediate) {
presenter.present()
}.test {
val initialState = awaitItem()
assertThat(initialState.testSuiteState.tests).isEmpty()
assertThat(initialState.testSuiteState.mainState).isEqualTo(AsyncAction.Uninitialized)
}
}
@Test
fun `present - start test`() = runTest {
val troubleshootTestSuite = createTroubleshootTestSuite(
tests = setOf(FakeNotificationTroubleshootTest())
)
val presenter = createTroubleshootNotificationsPresenter(
troubleshootTestSuite = troubleshootTestSuite,
)
moleculeFlow(RecompositionMode.Immediate) {
presenter.present()
}.test {
val initialState = awaitItem()
initialState.eventSink(TroubleshootNotificationsEvents.StartTests)
skipItems(1)
val stateAfterStart = awaitItem()
assertThat(stateAfterStart.testSuiteState.mainState).isEqualTo(AsyncAction.Loading)
}
}
@Test
fun `present - start failed test`() = runTest {
val troubleshootTestSuite = createTroubleshootTestSuite(
tests = setOf(
FakeNotificationTroubleshootTest(
firstStatus = NotificationTroubleshootTestState.Status.Failure(hasQuickFix = false)
)
)
)
val presenter = createTroubleshootNotificationsPresenter(
troubleshootTestSuite = troubleshootTestSuite,
)
moleculeFlow(RecompositionMode.Immediate) {
presenter.present()
}.test {
val initialState = awaitItem()
initialState.eventSink(TroubleshootNotificationsEvents.RetryFailedTests)
skipItems(1)
val stateAfterStart = awaitItem()
assertThat(stateAfterStart.testSuiteState.mainState).isEqualTo(AsyncAction.Loading)
}
}
@Test
fun `present - quick fix test`() = runTest {
val troubleshootTestSuite = createTroubleshootTestSuite(
tests = setOf(
FakeNotificationTroubleshootTest(
firstStatus = NotificationTroubleshootTestState.Status.Failure(hasQuickFix = false)
)
)
)
val presenter = createTroubleshootNotificationsPresenter(
troubleshootTestSuite = troubleshootTestSuite,
)
moleculeFlow(RecompositionMode.Immediate) {
presenter.present()
}.test {
skipItems(1)
val initialState = awaitItem()
assertThat(initialState.testSuiteState.mainState).isInstanceOf(AsyncAction.Failure::class.java)
initialState.eventSink(TroubleshootNotificationsEvents.QuickFix(0))
val stateAfterStart = awaitItem()
assertThat(stateAfterStart.testSuiteState.mainState).isEqualTo(AsyncAction.Loading)
}
}
private fun createTroubleshootTestSuite(
tests: Set<NotificationTroubleshootTest> = emptySet(),
currentPushProvider: String? = null,
): TroubleshootTestSuite {
return TroubleshootTestSuite(
notificationTroubleshootTests = tests,
getCurrentPushProvider = FakeGetCurrentPushProvider(currentPushProvider),
analyticsService = FakeAnalyticsService(),
)
}
private fun createTroubleshootNotificationsPresenter(
troubleshootTestSuite: TroubleshootTestSuite = createTroubleshootTestSuite(),
): TroubleshootNotificationsPresenter {
return TroubleshootNotificationsPresenter(
troubleshootTestSuite = troubleshootTestSuite,
)
}
}

View file

@ -1,115 +0,0 @@
/*
* Copyright (c) 2024 New Vector Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.element.android.features.preferences.impl.notifications.troubleshoot
import androidx.activity.ComponentActivity
import androidx.compose.ui.test.junit4.AndroidComposeTestRule
import androidx.compose.ui.test.junit4.createAndroidComposeRule
import androidx.compose.ui.test.onNodeWithText
import androidx.compose.ui.test.performClick
import androidx.test.ext.junit.runners.AndroidJUnit4
import io.element.android.tests.testutils.EnsureNeverCalled
import io.element.android.tests.testutils.EventsRecorder
import io.element.android.tests.testutils.ensureCalledOnce
import io.element.android.tests.testutils.pressBack
import org.junit.Rule
import org.junit.Test
import org.junit.rules.TestRule
import org.junit.runner.RunWith
import org.robolectric.annotation.Config
@RunWith(AndroidJUnit4::class)
class TroubleshootNotificationsViewTest {
@get:Rule
val rule = createAndroidComposeRule<ComponentActivity>()
@Test
fun `press menu back invokes the expected callback`() {
val eventsRecorder = EventsRecorder<TroubleshootNotificationsEvents>(expectEvents = false)
ensureCalledOnce {
rule.setTroubleshootNotificationsView(
state = aTroubleshootNotificationsState(
eventSink = eventsRecorder
),
onBackPressed = it,
)
rule.pressBack()
}
}
@Test
fun `clicking on run test emits the expected Event`() {
val eventsRecorder = EventsRecorder<TroubleshootNotificationsEvents>()
rule.setTroubleshootNotificationsView(
aTroubleshootNotificationsState(
eventSink = eventsRecorder
),
)
rule.onNodeWithText("Run tests").performClick()
eventsRecorder.assertSingle(TroubleshootNotificationsEvents.StartTests)
}
@Config(qualifiers = "h1024dp")
@Test
fun `clicking on run test again emits the expected Event`() {
val eventsRecorder = EventsRecorder<TroubleshootNotificationsEvents>()
rule.setTroubleshootNotificationsView(
aTroubleshootNotificationsState(
tests = listOf(aTroubleshootTestStateFailure(hasQuickFix = false)),
eventSink = eventsRecorder
),
)
rule.onNodeWithText("Run tests again").performClick()
eventsRecorder.assertList(
listOf(
TroubleshootNotificationsEvents.RetryFailedTests,
TroubleshootNotificationsEvents.StartTests,
)
)
}
@Config(qualifiers = "h1024dp")
@Test
fun `clicking on quick fix emits the expected Event`() {
val eventsRecorder = EventsRecorder<TroubleshootNotificationsEvents>()
rule.setTroubleshootNotificationsView(
aTroubleshootNotificationsState(
tests = listOf(aTroubleshootTestStateFailure(hasQuickFix = true)),
eventSink = eventsRecorder
),
)
rule.onNodeWithText("Attempt to fix").performClick()
eventsRecorder.assertList(
listOf(
TroubleshootNotificationsEvents.RetryFailedTests,
TroubleshootNotificationsEvents.QuickFix(0),
)
)
}
}
private fun <R : TestRule> AndroidComposeTestRule<R, ComponentActivity>.setTroubleshootNotificationsView(
state: TroubleshootNotificationsState,
onBackPressed: () -> Unit = EnsureNeverCalled(),
) {
setContent {
TroubleshootNotificationsView(
state = state,
onBackPressed = onBackPressed,
)
}
}