Improve preview management for NotificationSettingsView
This commit is contained in:
parent
91de03e4b9
commit
9f60a28b8c
3 changed files with 28 additions and 21 deletions
|
|
@ -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(
|
|||
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,
|
||||
)
|
||||
|
|
|
|||
|
|
@ -217,13 +217,3 @@ internal fun NotificationSettingsViewPreview(@PreviewParameter(NotificationSetti
|
|||
onTroubleshootNotificationsClicked = {},
|
||||
)
|
||||
}
|
||||
|
||||
@PreviewsDayNight
|
||||
@Composable
|
||||
internal fun InvalidNotificationSettingsViewPreview() = ElementPreview {
|
||||
InvalidNotificationSettingsView(
|
||||
showError = false,
|
||||
onContinueClicked = {},
|
||||
onDismissError = {},
|
||||
)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 {
|
|||
val eventsRecorder = EventsRecorder<NotificationSettingsEvents>()
|
||||
ensureCalledOnce {
|
||||
rule.setNotificationSettingsView(
|
||||
state = aNotificationSettingsState(
|
||||
state = aValidNotificationSettingsState(
|
||||
eventSink = eventsRecorder
|
||||
),
|
||||
onTroubleshootNotificationsClicked = it
|
||||
|
|
@ -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 {
|
|||
val eventsRecorder = EventsRecorder<NotificationSettingsEvents>()
|
||||
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<NotificationSettingsEvents>()
|
||||
rule.setNotificationSettingsView(
|
||||
state = aNotificationSettingsState(
|
||||
state = aValidNotificationSettingsState(
|
||||
appNotificationEnabled = initialState,
|
||||
eventSink = eventsRecorder
|
||||
),
|
||||
|
|
@ -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 {
|
|||
private fun testInvitationToggle(initialState: Boolean) {
|
||||
val eventsRecorder = EventsRecorder<NotificationSettingsEvents>()
|
||||
rule.setNotificationSettingsView(
|
||||
state = aNotificationSettingsState(
|
||||
state = aValidNotificationSettingsState(
|
||||
inviteForMeNotificationsEnabled = initialState,
|
||||
eventSink = eventsRecorder
|
||||
),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue