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

@ -1,31 +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.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)
suspend fun reset()
suspend fun quickFix(coroutineScope: CoroutineScope) {
error("Quick fix not implemented, you need to override this method in your test")
}
}

View file

@ -1,81 +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.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()
suspend fun updateState(
status: NotificationTroubleshootTestState.Status,
name: String = defaultName,
description: String = defaultDescription,
) {
_state.emit(
NotificationTroubleshootTestState(
name = name,
description = description,
status = status,
)
)
}
suspend fun reset() {
updateState(NotificationTroubleshootTestState.Status.Idle(visibleWhenIdle))
}
suspend fun start() {
updateState(NotificationTroubleshootTestState.Status.InProgress)
delay(fakeDelay)
}
suspend 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

@ -1,31 +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.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

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