Browse Source

Improve preview management for NotificationSettingsView

pull/2596/head
Benoit Marty 6 months ago committed by Benoit Marty
parent
commit
9f60a28b8c
  1. 25
      features/preferences/impl/src/main/kotlin/io/element/android/features/preferences/impl/notifications/NotificationSettingsStateProvider.kt
  2. 10
      features/preferences/impl/src/main/kotlin/io/element/android/features/preferences/impl/notifications/NotificationSettingsView.kt
  3. 14
      features/preferences/impl/src/test/kotlin/io/element/android/features/preferences/impl/notifications/NotificationSettingsViewTest.kt

25
features/preferences/impl/src/main/kotlin/io/element/android/features/preferences/impl/notifications/NotificationSettingsStateProvider.kt

@ -23,13 +23,15 @@ import io.element.android.libraries.matrix.api.room.RoomNotificationMode @@ -23,13 +23,15 @@ import io.element.android.libraries.matrix.api.room.RoomNotificationMode
open class NotificationSettingsStateProvider : PreviewParameterProvider<NotificationSettingsState> {
override val values: Sequence<NotificationSettingsState>
get() = sequenceOf(
aNotificationSettingsState(),
aNotificationSettingsState(changeNotificationSettingAction = AsyncAction.Loading),
aNotificationSettingsState(changeNotificationSettingAction = AsyncAction.Failure(Throwable("error"))),
aValidNotificationSettingsState(),
aValidNotificationSettingsState(changeNotificationSettingAction = AsyncAction.Loading),
aValidNotificationSettingsState(changeNotificationSettingAction = AsyncAction.Failure(Throwable("error"))),
aInvalidNotificationSettingsState(),
aInvalidNotificationSettingsState(fixFailed = true),
)
}
fun aNotificationSettingsState(
fun aValidNotificationSettingsState(
changeNotificationSettingAction: AsyncAction<Unit> = AsyncAction.Uninitialized,
atRoomNotificationsEnabled: Boolean = true,
callNotificationsEnabled: Boolean = true,
@ -51,3 +53,18 @@ fun aNotificationSettingsState( @@ -51,3 +53,18 @@ fun aNotificationSettingsState(
changeNotificationSettingAction = changeNotificationSettingAction,
eventSink = eventSink,
)
fun aInvalidNotificationSettingsState(
fixFailed: Boolean = false,
eventSink: (NotificationSettingsEvents) -> Unit = {},
) = NotificationSettingsState(
matrixSettings = NotificationSettingsState.MatrixSettings.Invalid(
fixFailed = fixFailed,
),
appSettings = NotificationSettingsState.AppSettings(
systemNotificationsEnabled = false,
appNotificationsEnabled = true,
),
changeNotificationSettingAction = AsyncAction.Uninitialized,
eventSink = eventSink,
)

10
features/preferences/impl/src/main/kotlin/io/element/android/features/preferences/impl/notifications/NotificationSettingsView.kt

@ -217,13 +217,3 @@ internal fun NotificationSettingsViewPreview(@PreviewParameter(NotificationSetti @@ -217,13 +217,3 @@ internal fun NotificationSettingsViewPreview(@PreviewParameter(NotificationSetti
onTroubleshootNotificationsClicked = {},
)
}
@PreviewsDayNight
@Composable
internal fun InvalidNotificationSettingsViewPreview() = ElementPreview {
InvalidNotificationSettingsView(
showError = false,
onContinueClicked = {},
onDismissError = {},
)
}

14
features/preferences/impl/src/test/kotlin/io/element/android/features/preferences/impl/notifications/NotificationSettingsViewTest.kt

@ -44,7 +44,7 @@ class NotificationSettingsViewTest { @@ -44,7 +44,7 @@ class NotificationSettingsViewTest {
val eventsRecorder = EventsRecorder<NotificationSettingsEvents>()
ensureCalledOnce {
rule.setNotificationSettingsView(
state = aNotificationSettingsState(
state = aValidNotificationSettingsState(
eventSink = eventsRecorder
),
onBackPressed = it
@ -60,7 +60,7 @@ class NotificationSettingsViewTest { @@ -60,7 +60,7 @@ class NotificationSettingsViewTest {
val eventsRecorder = EventsRecorder<NotificationSettingsEvents>()
ensureCalledOnce {
rule.setNotificationSettingsView(
state = aNotificationSettingsState(
state = aValidNotificationSettingsState(
eventSink = eventsRecorder
),
onTroubleshootNotificationsClicked = it
@ -76,7 +76,7 @@ class NotificationSettingsViewTest { @@ -76,7 +76,7 @@ class NotificationSettingsViewTest {
val eventsRecorder = EventsRecorder<NotificationSettingsEvents>()
ensureCalledOnceWithParam(false) {
rule.setNotificationSettingsView(
state = aNotificationSettingsState(
state = aValidNotificationSettingsState(
eventSink = eventsRecorder
),
onOpenEditDefault = it
@ -92,7 +92,7 @@ class NotificationSettingsViewTest { @@ -92,7 +92,7 @@ class NotificationSettingsViewTest {
val eventsRecorder = EventsRecorder<NotificationSettingsEvents>()
ensureCalledOnceWithParam(true) {
rule.setNotificationSettingsView(
state = aNotificationSettingsState(
state = aValidNotificationSettingsState(
eventSink = eventsRecorder
),
onOpenEditDefault = it
@ -117,7 +117,7 @@ class NotificationSettingsViewTest { @@ -117,7 +117,7 @@ class NotificationSettingsViewTest {
private fun testNotificationToggle(initialState: Boolean) {
val eventsRecorder = EventsRecorder<NotificationSettingsEvents>()
rule.setNotificationSettingsView(
state = aNotificationSettingsState(
state = aValidNotificationSettingsState(
appNotificationEnabled = initialState,
eventSink = eventsRecorder
),
@ -146,7 +146,7 @@ class NotificationSettingsViewTest { @@ -146,7 +146,7 @@ class NotificationSettingsViewTest {
private fun testAtRoomToggle(initialState: Boolean) {
val eventsRecorder = EventsRecorder<NotificationSettingsEvents>()
rule.setNotificationSettingsView(
state = aNotificationSettingsState(
state = aValidNotificationSettingsState(
atRoomNotificationsEnabled = initialState,
eventSink = eventsRecorder
),
@ -175,7 +175,7 @@ class NotificationSettingsViewTest { @@ -175,7 +175,7 @@ class NotificationSettingsViewTest {
private fun testInvitationToggle(initialState: Boolean) {
val eventsRecorder = EventsRecorder<NotificationSettingsEvents>()
rule.setNotificationSettingsView(
state = aNotificationSettingsState(
state = aValidNotificationSettingsState(
inviteForMeNotificationsEnabled = initialState,
eventSink = eventsRecorder
),

Loading…
Cancel
Save