JoinRoomByAddressEvents -> JoinRoomByAddressEvent
This commit is contained in:
@@ -8,8 +8,8 @@
|
||||
|
||||
package io.element.android.features.startchat.impl.joinbyaddress
|
||||
|
||||
sealed interface JoinRoomByAddressEvents {
|
||||
data object Dismiss : JoinRoomByAddressEvents
|
||||
data object Continue : JoinRoomByAddressEvents
|
||||
data class UpdateAddress(val address: String) : JoinRoomByAddressEvents
|
||||
sealed interface JoinRoomByAddressEvent {
|
||||
data object Dismiss : JoinRoomByAddressEvent
|
||||
data object Continue : JoinRoomByAddressEvent
|
||||
data class UpdateAddress(val address: String) : JoinRoomByAddressEvent
|
||||
}
|
||||
@@ -49,16 +49,16 @@ class JoinRoomByAddressPresenter(
|
||||
var internalAddressState by remember { mutableStateOf<RoomAddressState>(RoomAddressState.Unknown) }
|
||||
var validateAddress: Boolean by remember { mutableStateOf(false) }
|
||||
|
||||
fun handleEvent(event: JoinRoomByAddressEvents) {
|
||||
fun handleEvent(event: JoinRoomByAddressEvent) {
|
||||
when (event) {
|
||||
JoinRoomByAddressEvents.Continue -> {
|
||||
JoinRoomByAddressEvent.Continue -> {
|
||||
when (val currentState = internalAddressState) {
|
||||
is RoomAddressState.RoomFound -> onRoomFound(currentState)
|
||||
else -> validateAddress = true
|
||||
}
|
||||
}
|
||||
JoinRoomByAddressEvents.Dismiss -> navigator.onDismissJoinRoomByAddress()
|
||||
is JoinRoomByAddressEvents.UpdateAddress -> {
|
||||
JoinRoomByAddressEvent.Dismiss -> navigator.onDismissJoinRoomByAddress()
|
||||
is JoinRoomByAddressEvent.UpdateAddress -> {
|
||||
validateAddress = false
|
||||
address = event.address.trim()
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ import io.element.android.libraries.matrix.api.room.alias.ResolvedRoomAlias
|
||||
data class JoinRoomByAddressState(
|
||||
val address: String,
|
||||
val addressState: RoomAddressState,
|
||||
val eventSink: (JoinRoomByAddressEvents) -> Unit
|
||||
val eventSink: (JoinRoomByAddressEvent) -> Unit
|
||||
)
|
||||
|
||||
@Immutable
|
||||
|
||||
@@ -30,7 +30,7 @@ open class JoinRoomByAddressStateProvider : PreviewParameterProvider<JoinRoomByA
|
||||
fun aJoinRoomByAddressState(
|
||||
address: String = "",
|
||||
addressState: RoomAddressState = RoomAddressState.Unknown,
|
||||
eventSink: (JoinRoomByAddressEvents) -> Unit = {},
|
||||
eventSink: (JoinRoomByAddressEvent) -> Unit = {},
|
||||
) = JoinRoomByAddressState(
|
||||
address = address,
|
||||
addressState = addressState,
|
||||
|
||||
@@ -50,7 +50,7 @@ fun JoinRoomByAddressView(
|
||||
modifier = modifier,
|
||||
sheetState = sheetState,
|
||||
onDismissRequest = {
|
||||
state.eventSink(JoinRoomByAddressEvents.Dismiss)
|
||||
state.eventSink(JoinRoomByAddressEvent.Dismiss)
|
||||
},
|
||||
) {
|
||||
Column(
|
||||
@@ -64,10 +64,10 @@ fun JoinRoomByAddressView(
|
||||
addressState = state.addressState,
|
||||
requestFocus = sheetState.isVisible,
|
||||
onAddressChange = {
|
||||
state.eventSink(JoinRoomByAddressEvents.UpdateAddress(it))
|
||||
state.eventSink(JoinRoomByAddressEvent.UpdateAddress(it))
|
||||
},
|
||||
onContinue = {
|
||||
state.eventSink(JoinRoomByAddressEvents.Continue)
|
||||
state.eventSink(JoinRoomByAddressEvent.Continue)
|
||||
},
|
||||
)
|
||||
Spacer(modifier = Modifier.height(24.dp))
|
||||
@@ -76,7 +76,7 @@ fun JoinRoomByAddressView(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
showProgress = state.addressState is RoomAddressState.Resolving,
|
||||
onClick = {
|
||||
state.eventSink(JoinRoomByAddressEvents.Continue)
|
||||
state.eventSink(JoinRoomByAddressEvent.Continue)
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
@@ -44,12 +44,12 @@ class JoinBaseRoomByAddressPresenterTest {
|
||||
)
|
||||
presenter.test {
|
||||
with(awaitItem()) {
|
||||
eventSink(JoinRoomByAddressEvents.UpdateAddress("invalid_address"))
|
||||
eventSink(JoinRoomByAddressEvent.UpdateAddress("invalid_address"))
|
||||
}
|
||||
with(awaitItem()) {
|
||||
assertThat(address).isEqualTo("invalid_address")
|
||||
assertThat(addressState).isEqualTo(RoomAddressState.Unknown)
|
||||
eventSink(JoinRoomByAddressEvents.Continue)
|
||||
eventSink(JoinRoomByAddressEvent.Continue)
|
||||
}
|
||||
// The address should be marked as invalid only after the user tries to continue
|
||||
with(awaitItem()) {
|
||||
@@ -71,12 +71,12 @@ class JoinBaseRoomByAddressPresenterTest {
|
||||
)
|
||||
presenter.test {
|
||||
with(awaitItem()) {
|
||||
eventSink(JoinRoomByAddressEvents.UpdateAddress("#ö:invalid.org"))
|
||||
eventSink(JoinRoomByAddressEvent.UpdateAddress("#ö:invalid.org"))
|
||||
}
|
||||
with(awaitItem()) {
|
||||
assertThat(address).isEqualTo("#ö:invalid.org")
|
||||
assertThat(addressState).isEqualTo(RoomAddressState.Unknown)
|
||||
eventSink(JoinRoomByAddressEvents.Continue)
|
||||
eventSink(JoinRoomByAddressEvent.Continue)
|
||||
}
|
||||
// The address should not be marked as valid
|
||||
with(awaitItem()) {
|
||||
@@ -107,12 +107,12 @@ class JoinBaseRoomByAddressPresenterTest {
|
||||
)
|
||||
presenter.test {
|
||||
with(awaitItem()) {
|
||||
eventSink(JoinRoomByAddressEvents.UpdateAddress("#ö:invalid.org"))
|
||||
eventSink(JoinRoomByAddressEvent.UpdateAddress("#ö:invalid.org"))
|
||||
}
|
||||
with(awaitItem()) {
|
||||
assertThat(address).isEqualTo("#ö:invalid.org")
|
||||
assertThat(addressState).isEqualTo(RoomAddressState.Unknown)
|
||||
eventSink(JoinRoomByAddressEvents.Continue)
|
||||
eventSink(JoinRoomByAddressEvent.Continue)
|
||||
}
|
||||
// The address should not be marked as valid
|
||||
with(awaitItem()) {
|
||||
@@ -141,12 +141,12 @@ class JoinBaseRoomByAddressPresenterTest {
|
||||
)
|
||||
presenter.test {
|
||||
with(awaitItem()) {
|
||||
eventSink(JoinRoomByAddressEvents.UpdateAddress("#ö:invalid.org"))
|
||||
eventSink(JoinRoomByAddressEvent.UpdateAddress("#ö:invalid.org"))
|
||||
}
|
||||
with(awaitItem()) {
|
||||
assertThat(address).isEqualTo("#ö:invalid.org")
|
||||
assertThat(addressState).isEqualTo(RoomAddressState.Unknown)
|
||||
eventSink(JoinRoomByAddressEvents.Continue)
|
||||
eventSink(JoinRoomByAddressEvent.Continue)
|
||||
}
|
||||
// The address should not be marked as valid
|
||||
with(awaitItem()) {
|
||||
@@ -171,7 +171,7 @@ class JoinBaseRoomByAddressPresenterTest {
|
||||
val presenter = createJoinRoomByAddressPresenter(navigator = navigator)
|
||||
presenter.test {
|
||||
with(awaitItem()) {
|
||||
eventSink(JoinRoomByAddressEvents.UpdateAddress("#room_found:matrix.org"))
|
||||
eventSink(JoinRoomByAddressEvent.UpdateAddress("#room_found:matrix.org"))
|
||||
}
|
||||
with(awaitItem()) {
|
||||
assertThat(address).isEqualTo("#room_found:matrix.org")
|
||||
@@ -180,7 +180,7 @@ class JoinBaseRoomByAddressPresenterTest {
|
||||
with(awaitItem()) {
|
||||
assertThat(address).isEqualTo("#room_found:matrix.org")
|
||||
assertThat(addressState).isInstanceOf(RoomAddressState.RoomFound::class.java)
|
||||
eventSink(JoinRoomByAddressEvents.Continue)
|
||||
eventSink(JoinRoomByAddressEvent.Continue)
|
||||
}
|
||||
assert(openRoomLambda).isCalledOnce()
|
||||
assert(dismissJoinRoomByAddressLambda).isCalledOnce()
|
||||
@@ -196,12 +196,12 @@ class JoinBaseRoomByAddressPresenterTest {
|
||||
)
|
||||
presenter.test {
|
||||
with(awaitItem()) {
|
||||
eventSink(JoinRoomByAddressEvents.UpdateAddress("#room_not_found:matrix.org"))
|
||||
eventSink(JoinRoomByAddressEvent.UpdateAddress("#room_not_found:matrix.org"))
|
||||
}
|
||||
with(awaitItem()) {
|
||||
assertThat(address).isEqualTo("#room_not_found:matrix.org")
|
||||
assertThat(addressState).isEqualTo(RoomAddressState.Unknown)
|
||||
eventSink(JoinRoomByAddressEvents.Continue)
|
||||
eventSink(JoinRoomByAddressEvent.Continue)
|
||||
}
|
||||
with(awaitItem()) {
|
||||
assertThat(address).isEqualTo("#room_not_found:matrix.org")
|
||||
@@ -223,7 +223,7 @@ class JoinBaseRoomByAddressPresenterTest {
|
||||
val presenter = createJoinRoomByAddressPresenter(navigator = navigator)
|
||||
presenter.test {
|
||||
with(awaitItem()) {
|
||||
eventSink(JoinRoomByAddressEvents.Dismiss)
|
||||
eventSink(JoinRoomByAddressEvent.Dismiss)
|
||||
}
|
||||
assert(dismissJoinRoomByAddressLambda).isCalledOnce()
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ class JoinBaseRoomByAddressViewTest {
|
||||
|
||||
@Test
|
||||
fun `entering text emits the expected event`() {
|
||||
val eventsRecorder = EventsRecorder<JoinRoomByAddressEvents>()
|
||||
val eventsRecorder = EventsRecorder<JoinRoomByAddressEvent>()
|
||||
rule.setJoinRoomByAddressView(
|
||||
aJoinRoomByAddressState(
|
||||
eventSink = eventsRecorder,
|
||||
@@ -39,19 +39,19 @@ class JoinBaseRoomByAddressViewTest {
|
||||
)
|
||||
val text = rule.activity.getString(R.string.screen_start_chat_join_room_by_address_action)
|
||||
rule.onNodeWithText(text).performTextInput("#address:matrix.org")
|
||||
eventsRecorder.assertSingle(JoinRoomByAddressEvents.UpdateAddress("#address:matrix.org"))
|
||||
eventsRecorder.assertSingle(JoinRoomByAddressEvent.UpdateAddress("#address:matrix.org"))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `clicking on continue emits the expected event`() {
|
||||
val eventsRecorder = EventsRecorder<JoinRoomByAddressEvents>()
|
||||
val eventsRecorder = EventsRecorder<JoinRoomByAddressEvent>()
|
||||
rule.setJoinRoomByAddressView(
|
||||
aJoinRoomByAddressState(
|
||||
eventSink = eventsRecorder,
|
||||
)
|
||||
)
|
||||
rule.clickOn(CommonStrings.action_continue)
|
||||
eventsRecorder.assertSingle(JoinRoomByAddressEvents.Continue)
|
||||
eventsRecorder.assertSingle(JoinRoomByAddressEvent.Continue)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user