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
open class NotificationSettingsStateProvider : PreviewParameterProvider<NotificationSettingsState> { open class NotificationSettingsStateProvider : PreviewParameterProvider<NotificationSettingsState> {
override val values: Sequence<NotificationSettingsState> override val values: Sequence<NotificationSettingsState>
get() = sequenceOf( get() = sequenceOf(
aNotificationSettingsState(), aValidNotificationSettingsState(),
aNotificationSettingsState(changeNotificationSettingAction = AsyncAction.Loading), aValidNotificationSettingsState(changeNotificationSettingAction = AsyncAction.Loading),
aNotificationSettingsState(changeNotificationSettingAction = AsyncAction.Failure(Throwable("error"))), aValidNotificationSettingsState(changeNotificationSettingAction = AsyncAction.Failure(Throwable("error"))),
aInvalidNotificationSettingsState(),
aInvalidNotificationSettingsState(fixFailed = true),
) )
} }
fun aNotificationSettingsState( fun aValidNotificationSettingsState(
changeNotificationSettingAction: AsyncAction<Unit> = AsyncAction.Uninitialized, changeNotificationSettingAction: AsyncAction<Unit> = AsyncAction.Uninitialized,
atRoomNotificationsEnabled: Boolean = true, atRoomNotificationsEnabled: Boolean = true,
callNotificationsEnabled: Boolean = true, callNotificationsEnabled: Boolean = true,
@ -51,3 +53,18 @@ fun aNotificationSettingsState(
changeNotificationSettingAction = changeNotificationSettingAction, changeNotificationSettingAction = changeNotificationSettingAction,
eventSink = eventSink, 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
onTroubleshootNotificationsClicked = {}, 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 {
val eventsRecorder = EventsRecorder<NotificationSettingsEvents>() val eventsRecorder = EventsRecorder<NotificationSettingsEvents>()
ensureCalledOnce { ensureCalledOnce {
rule.setNotificationSettingsView( rule.setNotificationSettingsView(
state = aNotificationSettingsState( state = aValidNotificationSettingsState(
eventSink = eventsRecorder eventSink = eventsRecorder
), ),
onBackPressed = it onBackPressed = it
@ -60,7 +60,7 @@ class NotificationSettingsViewTest {
val eventsRecorder = EventsRecorder<NotificationSettingsEvents>() val eventsRecorder = EventsRecorder<NotificationSettingsEvents>()
ensureCalledOnce { ensureCalledOnce {
rule.setNotificationSettingsView( rule.setNotificationSettingsView(
state = aNotificationSettingsState( state = aValidNotificationSettingsState(
eventSink = eventsRecorder eventSink = eventsRecorder
), ),
onTroubleshootNotificationsClicked = it onTroubleshootNotificationsClicked = it
@ -76,7 +76,7 @@ class NotificationSettingsViewTest {
val eventsRecorder = EventsRecorder<NotificationSettingsEvents>() val eventsRecorder = EventsRecorder<NotificationSettingsEvents>()
ensureCalledOnceWithParam(false) { ensureCalledOnceWithParam(false) {
rule.setNotificationSettingsView( rule.setNotificationSettingsView(
state = aNotificationSettingsState( state = aValidNotificationSettingsState(
eventSink = eventsRecorder eventSink = eventsRecorder
), ),
onOpenEditDefault = it onOpenEditDefault = it
@ -92,7 +92,7 @@ class NotificationSettingsViewTest {
val eventsRecorder = EventsRecorder<NotificationSettingsEvents>() val eventsRecorder = EventsRecorder<NotificationSettingsEvents>()
ensureCalledOnceWithParam(true) { ensureCalledOnceWithParam(true) {
rule.setNotificationSettingsView( rule.setNotificationSettingsView(
state = aNotificationSettingsState( state = aValidNotificationSettingsState(
eventSink = eventsRecorder eventSink = eventsRecorder
), ),
onOpenEditDefault = it onOpenEditDefault = it
@ -117,7 +117,7 @@ class NotificationSettingsViewTest {
private fun testNotificationToggle(initialState: Boolean) { private fun testNotificationToggle(initialState: Boolean) {
val eventsRecorder = EventsRecorder<NotificationSettingsEvents>() val eventsRecorder = EventsRecorder<NotificationSettingsEvents>()
rule.setNotificationSettingsView( rule.setNotificationSettingsView(
state = aNotificationSettingsState( state = aValidNotificationSettingsState(
appNotificationEnabled = initialState, appNotificationEnabled = initialState,
eventSink = eventsRecorder eventSink = eventsRecorder
), ),
@ -146,7 +146,7 @@ class NotificationSettingsViewTest {
private fun testAtRoomToggle(initialState: Boolean) { private fun testAtRoomToggle(initialState: Boolean) {
val eventsRecorder = EventsRecorder<NotificationSettingsEvents>() val eventsRecorder = EventsRecorder<NotificationSettingsEvents>()
rule.setNotificationSettingsView( rule.setNotificationSettingsView(
state = aNotificationSettingsState( state = aValidNotificationSettingsState(
atRoomNotificationsEnabled = initialState, atRoomNotificationsEnabled = initialState,
eventSink = eventsRecorder eventSink = eventsRecorder
), ),
@ -175,7 +175,7 @@ class NotificationSettingsViewTest {
private fun testInvitationToggle(initialState: Boolean) { private fun testInvitationToggle(initialState: Boolean) {
val eventsRecorder = EventsRecorder<NotificationSettingsEvents>() val eventsRecorder = EventsRecorder<NotificationSettingsEvents>()
rule.setNotificationSettingsView( rule.setNotificationSettingsView(
state = aNotificationSettingsState( state = aValidNotificationSettingsState(
inviteForMeNotificationsEnabled = initialState, inviteForMeNotificationsEnabled = initialState,
eventSink = eventsRecorder eventSink = eventsRecorder
), ),

Loading…
Cancel
Save