Troubleshoot notifications screen

This commit is contained in:
Benoit Marty 2024-03-26 11:36:31 +01:00
parent 6c9ea2b920
commit 2bfe125a77
80 changed files with 3086 additions and 99 deletions

View file

@ -0,0 +1,29 @@
/*
* 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.libraries.core.notifications
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.flow.StateFlow
interface NotificationTroubleshootTest {
val order: Int
val state: StateFlow<NotificationTroubleshootTestState>
fun isRelevant(data: TestFilterData): Boolean = true
suspend fun run(coroutineScope: CoroutineScope)
fun reset()
suspend fun quickFix(coroutineScope: CoroutineScope) {}
}

View file

@ -0,0 +1,81 @@
/*
* 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.libraries.core.notifications
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.asStateFlow
/**
* A NotificationTroubleshootTest delegate, with common pattern for running and resetting.
*/
class NotificationTroubleshootTestDelegate(
private val defaultName: String,
private val defaultDescription: String,
private val visibleWhenIdle: Boolean = true,
private val hasQuickFix: Boolean = false,
private val fakeDelay: Long = 0L,
) {
private val _state: MutableStateFlow<NotificationTroubleshootTestState> = MutableStateFlow(
NotificationTroubleshootTestState(
name = defaultName,
description = defaultDescription,
status = NotificationTroubleshootTestState.Status.Idle(visibleWhenIdle),
)
)
val state: StateFlow<NotificationTroubleshootTestState> = _state.asStateFlow()
fun updateState(
status: NotificationTroubleshootTestState.Status,
name: String = defaultName,
description: String = defaultDescription,
) {
_state.tryEmit(
NotificationTroubleshootTestState(
name = name,
description = description,
status = status,
)
)
}
fun reset() {
updateState(NotificationTroubleshootTestState.Status.Idle(visibleWhenIdle))
}
suspend fun start() {
updateState(NotificationTroubleshootTestState.Status.InProgress)
delay(fakeDelay)
}
fun done(isSuccess: Boolean = true) {
updateState(
if (isSuccess) {
NotificationTroubleshootTestState.Status.Success
} else {
NotificationTroubleshootTestState.Status.Failure(hasQuickFix)
}
)
}
companion object {
const val SHORT_DELAY = 300L
const val LONG_DELAY = 500L
}
}

View file

@ -0,0 +1,31 @@
/*
* 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.libraries.core.notifications
data class NotificationTroubleshootTestState(
val name: String,
val description: String,
val status: Status,
) {
sealed interface Status {
data class Idle(val visible: Boolean) : Status
data object InProgress : Status
data object WaitingForUser : Status
data object Success : Status
data class Failure(val hasQuickFix: Boolean) : Status
}
}

View file

@ -0,0 +1,21 @@
/*
* 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.libraries.core.notifications
data class TestFilterData(
val currentPushProviderName: String?,
)