From 9f60a28b8c89d349078884b66cac25e3d8ea73ec Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Wed, 27 Mar 2024 21:52:15 +0100 Subject: [PATCH] Improve preview management for NotificationSettingsView --- .../NotificationSettingsStateProvider.kt | 25 ++++++++++++++++--- .../notifications/NotificationSettingsView.kt | 10 -------- .../NotificationSettingsViewTest.kt | 14 +++++------ 3 files changed, 28 insertions(+), 21 deletions(-) diff --git a/features/preferences/impl/src/main/kotlin/io/element/android/features/preferences/impl/notifications/NotificationSettingsStateProvider.kt b/features/preferences/impl/src/main/kotlin/io/element/android/features/preferences/impl/notifications/NotificationSettingsStateProvider.kt index 008f53d30b..dc1e972aa6 100644 --- a/features/preferences/impl/src/main/kotlin/io/element/android/features/preferences/impl/notifications/NotificationSettingsStateProvider.kt +++ b/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 open class NotificationSettingsStateProvider : PreviewParameterProvider { override val values: Sequence 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 = AsyncAction.Uninitialized, atRoomNotificationsEnabled: Boolean = true, callNotificationsEnabled: Boolean = true, @@ -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, +) diff --git a/features/preferences/impl/src/main/kotlin/io/element/android/features/preferences/impl/notifications/NotificationSettingsView.kt b/features/preferences/impl/src/main/kotlin/io/element/android/features/preferences/impl/notifications/NotificationSettingsView.kt index 5e3610b652..d62f972d71 100644 --- a/features/preferences/impl/src/main/kotlin/io/element/android/features/preferences/impl/notifications/NotificationSettingsView.kt +++ b/features/preferences/impl/src/main/kotlin/io/element/android/features/preferences/impl/notifications/NotificationSettingsView.kt @@ -217,13 +217,3 @@ internal fun NotificationSettingsViewPreview(@PreviewParameter(NotificationSetti onTroubleshootNotificationsClicked = {}, ) } - -@PreviewsDayNight -@Composable -internal fun InvalidNotificationSettingsViewPreview() = ElementPreview { - InvalidNotificationSettingsView( - showError = false, - onContinueClicked = {}, - onDismissError = {}, - ) -} diff --git a/features/preferences/impl/src/test/kotlin/io/element/android/features/preferences/impl/notifications/NotificationSettingsViewTest.kt b/features/preferences/impl/src/test/kotlin/io/element/android/features/preferences/impl/notifications/NotificationSettingsViewTest.kt index 980a0aa962..754885fba8 100644 --- a/features/preferences/impl/src/test/kotlin/io/element/android/features/preferences/impl/notifications/NotificationSettingsViewTest.kt +++ b/features/preferences/impl/src/test/kotlin/io/element/android/features/preferences/impl/notifications/NotificationSettingsViewTest.kt @@ -44,7 +44,7 @@ class NotificationSettingsViewTest { val eventsRecorder = EventsRecorder() ensureCalledOnce { rule.setNotificationSettingsView( - state = aNotificationSettingsState( + state = aValidNotificationSettingsState( eventSink = eventsRecorder ), onBackPressed = it @@ -60,7 +60,7 @@ class NotificationSettingsViewTest { val eventsRecorder = EventsRecorder() ensureCalledOnce { rule.setNotificationSettingsView( - state = aNotificationSettingsState( + state = aValidNotificationSettingsState( eventSink = eventsRecorder ), onTroubleshootNotificationsClicked = it @@ -76,7 +76,7 @@ class NotificationSettingsViewTest { val eventsRecorder = EventsRecorder() ensureCalledOnceWithParam(false) { rule.setNotificationSettingsView( - state = aNotificationSettingsState( + state = aValidNotificationSettingsState( eventSink = eventsRecorder ), onOpenEditDefault = it @@ -92,7 +92,7 @@ class NotificationSettingsViewTest { val eventsRecorder = EventsRecorder() ensureCalledOnceWithParam(true) { rule.setNotificationSettingsView( - state = aNotificationSettingsState( + state = aValidNotificationSettingsState( eventSink = eventsRecorder ), onOpenEditDefault = it @@ -117,7 +117,7 @@ class NotificationSettingsViewTest { private fun testNotificationToggle(initialState: Boolean) { val eventsRecorder = EventsRecorder() rule.setNotificationSettingsView( - state = aNotificationSettingsState( + state = aValidNotificationSettingsState( appNotificationEnabled = initialState, eventSink = eventsRecorder ), @@ -146,7 +146,7 @@ class NotificationSettingsViewTest { private fun testAtRoomToggle(initialState: Boolean) { val eventsRecorder = EventsRecorder() rule.setNotificationSettingsView( - state = aNotificationSettingsState( + state = aValidNotificationSettingsState( atRoomNotificationsEnabled = initialState, eventSink = eventsRecorder ), @@ -175,7 +175,7 @@ class NotificationSettingsViewTest { private fun testInvitationToggle(initialState: Boolean) { val eventsRecorder = EventsRecorder() rule.setNotificationSettingsView( - state = aNotificationSettingsState( + state = aValidNotificationSettingsState( inviteForMeNotificationsEnabled = initialState, eventSink = eventsRecorder ),