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