mirror of
https://github.com/Novaloop-AG/element-x-android.git
synced 2026-11-02 12:07:28 +00:00
Merge remote-tracking branch 'origin/develop' into HEAD
This commit is contained in:
+5
-5
@@ -11,9 +11,9 @@ package io.element.android.features.poll.impl.history
|
||||
import io.element.android.features.poll.impl.history.model.PollHistoryFilter
|
||||
import io.element.android.libraries.matrix.api.core.EventId
|
||||
|
||||
sealed interface PollHistoryEvents {
|
||||
data object LoadMore : PollHistoryEvents
|
||||
data class SelectPollAnswer(val pollStartId: EventId, val answerIds: List<String>) : PollHistoryEvents
|
||||
data class EndPoll(val pollStartId: EventId) : PollHistoryEvents
|
||||
data class SelectFilter(val filter: PollHistoryFilter) : PollHistoryEvents
|
||||
sealed interface PollHistoryEvent {
|
||||
data object LoadMore : PollHistoryEvent
|
||||
data class SelectPollAnswer(val pollStartId: EventId, val answerIds: List<String>) : PollHistoryEvent
|
||||
data class EndPoll(val pollStartId: EventId) : PollHistoryEvent
|
||||
data class SelectFilter(val filter: PollHistoryFilter) : PollHistoryEvent
|
||||
}
|
||||
+5
-5
@@ -64,12 +64,12 @@ class PollHistoryPresenter(
|
||||
}
|
||||
}
|
||||
val coroutineScope = rememberCoroutineScope()
|
||||
fun handleEvent(event: PollHistoryEvents) {
|
||||
fun handleEvent(event: PollHistoryEvent) {
|
||||
when (event) {
|
||||
is PollHistoryEvents.LoadMore -> {
|
||||
is PollHistoryEvent.LoadMore -> {
|
||||
coroutineScope.loadMore(timeline)
|
||||
}
|
||||
is PollHistoryEvents.SelectPollAnswer -> sessionCoroutineScope.launch {
|
||||
is PollHistoryEvent.SelectPollAnswer -> sessionCoroutineScope.launch {
|
||||
sendPollResponseAction.execute(
|
||||
timeline = timeline,
|
||||
pollStartId = event.pollStartId,
|
||||
@@ -78,10 +78,10 @@ class PollHistoryPresenter(
|
||||
Timber.e(error, "Failed to send poll response")
|
||||
}
|
||||
}
|
||||
is PollHistoryEvents.EndPoll -> sessionCoroutineScope.launch {
|
||||
is PollHistoryEvent.EndPoll -> sessionCoroutineScope.launch {
|
||||
endPollAction.execute(timeline = timeline, pollStartId = event.pollStartId)
|
||||
}
|
||||
is PollHistoryEvents.SelectFilter -> {
|
||||
is PollHistoryEvent.SelectFilter -> {
|
||||
activeFilter = event.filter
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -18,7 +18,7 @@ data class PollHistoryState(
|
||||
val hasMoreToLoad: Boolean,
|
||||
val activeFilter: PollHistoryFilter,
|
||||
val pollHistoryItems: PollHistoryItems,
|
||||
val eventSink: (PollHistoryEvents) -> Unit,
|
||||
val eventSink: (PollHistoryEvent) -> Unit,
|
||||
) {
|
||||
fun pollHistoryForFilter(filter: PollHistoryFilter): ImmutableList<PollHistoryItem> {
|
||||
return when (filter) {
|
||||
|
||||
+1
-1
@@ -48,7 +48,7 @@ internal fun aPollHistoryState(
|
||||
currentItems: List<PollHistoryItem> = listOf(
|
||||
aPollHistoryItem(),
|
||||
),
|
||||
eventSink: (PollHistoryEvents) -> Unit = {},
|
||||
eventSink: (PollHistoryEvent) -> Unit = {},
|
||||
) = PollHistoryState(
|
||||
isLoading = isLoading,
|
||||
hasMoreToLoad = hasMoreToLoad,
|
||||
|
||||
+4
-4
@@ -62,15 +62,15 @@ fun PollHistoryView(
|
||||
modifier: Modifier = Modifier,
|
||||
) {
|
||||
fun onLoadMore() {
|
||||
state.eventSink(PollHistoryEvents.LoadMore)
|
||||
state.eventSink(PollHistoryEvent.LoadMore)
|
||||
}
|
||||
|
||||
fun onSelectAnswer(pollStartId: EventId, answerIds: List<String>) {
|
||||
state.eventSink(PollHistoryEvents.SelectPollAnswer(pollStartId, answerIds))
|
||||
state.eventSink(PollHistoryEvent.SelectPollAnswer(pollStartId, answerIds))
|
||||
}
|
||||
|
||||
fun onEndPoll(pollStartId: EventId) {
|
||||
state.eventSink(PollHistoryEvents.EndPoll(pollStartId))
|
||||
state.eventSink(PollHistoryEvent.EndPoll(pollStartId))
|
||||
}
|
||||
|
||||
Scaffold(
|
||||
@@ -97,7 +97,7 @@ fun PollHistoryView(
|
||||
}
|
||||
PollHistoryFilterButtons(
|
||||
activeFilter = state.activeFilter,
|
||||
onSelectFilter = { state.eventSink(PollHistoryEvents.SelectFilter(it)) },
|
||||
onSelectFilter = { state.eventSink(PollHistoryEvent.SelectFilter(it)) },
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(horizontal = 16.dp, vertical = 8.dp),
|
||||
|
||||
+5
-5
@@ -88,12 +88,12 @@ class PollHistoryPresenterTest {
|
||||
}.test {
|
||||
awaitItem().also { state ->
|
||||
assertThat(state.activeFilter).isEqualTo(PollHistoryFilter.ONGOING)
|
||||
state.eventSink(PollHistoryEvents.SelectFilter(PollHistoryFilter.PAST))
|
||||
state.eventSink(PollHistoryEvent.SelectFilter(PollHistoryFilter.PAST))
|
||||
}
|
||||
skipItems(1)
|
||||
awaitItem().also { state ->
|
||||
assertThat(state.activeFilter).isEqualTo(PollHistoryFilter.PAST)
|
||||
state.eventSink(PollHistoryEvents.SelectFilter(PollHistoryFilter.ONGOING))
|
||||
state.eventSink(PollHistoryEvent.SelectFilter(PollHistoryFilter.ONGOING))
|
||||
}
|
||||
awaitItem().also { state ->
|
||||
assertThat(state.activeFilter).isEqualTo(PollHistoryFilter.ONGOING)
|
||||
@@ -114,10 +114,10 @@ class PollHistoryPresenterTest {
|
||||
presenter.present()
|
||||
}.test {
|
||||
val state = awaitItem()
|
||||
state.eventSink(PollHistoryEvents.EndPoll(AN_EVENT_ID))
|
||||
state.eventSink(PollHistoryEvent.EndPoll(AN_EVENT_ID))
|
||||
runCurrent()
|
||||
endPollAction.verifyExecutionCount(1)
|
||||
state.eventSink(PollHistoryEvents.SelectPollAnswer(AN_EVENT_ID, listOf("answer")))
|
||||
state.eventSink(PollHistoryEvent.SelectPollAnswer(AN_EVENT_ID, listOf("answer")))
|
||||
runCurrent()
|
||||
sendPollResponseAction.verifyExecutionCount(1)
|
||||
cancelAndConsumeRemainingEvents()
|
||||
@@ -139,7 +139,7 @@ class PollHistoryPresenterTest {
|
||||
skipItems(1)
|
||||
val loadedState = awaitItem()
|
||||
assertThat(loadedState.isLoading).isFalse()
|
||||
loadedState.eventSink(PollHistoryEvents.LoadMore)
|
||||
loadedState.eventSink(PollHistoryEvent.LoadMore)
|
||||
backwardPaginationStatus.getAndUpdate { it.copy(isPaginating = true) }
|
||||
awaitItem().also { state ->
|
||||
assertThat(state.isLoading).isTrue()
|
||||
|
||||
+10
-10
@@ -35,7 +35,7 @@ import org.robolectric.annotation.Config
|
||||
class PollHistoryViewTest : RobolectricTest() {
|
||||
@Test
|
||||
fun `clicking on back invokes the expected callback`() = runAndroidComposeUiTest {
|
||||
val eventsRecorder = EventsRecorder<PollHistoryEvents>(expectEvents = false)
|
||||
val eventsRecorder = EventsRecorder<PollHistoryEvent>(expectEvents = false)
|
||||
ensureCalledOnce {
|
||||
setPollHistoryViewView(
|
||||
aPollHistoryState(
|
||||
@@ -50,7 +50,7 @@ class PollHistoryViewTest : RobolectricTest() {
|
||||
@Config(qualifiers = "h1024dp")
|
||||
@Test
|
||||
fun `clicking on edit poll invokes the expected callback`() = runAndroidComposeUiTest {
|
||||
val eventsRecorder = EventsRecorder<PollHistoryEvents>(expectEvents = false)
|
||||
val eventsRecorder = EventsRecorder<PollHistoryEvent>(expectEvents = false)
|
||||
val eventId = EventId("\$anEventId")
|
||||
val state = aPollHistoryState(
|
||||
currentItems = listOf(
|
||||
@@ -76,7 +76,7 @@ class PollHistoryViewTest : RobolectricTest() {
|
||||
@Config(qualifiers = "h1024dp")
|
||||
@Test
|
||||
fun `clicking on poll end emits the expected Event`() = runAndroidComposeUiTest {
|
||||
val eventsRecorder = EventsRecorder<PollHistoryEvents>()
|
||||
val eventsRecorder = EventsRecorder<PollHistoryEvent>()
|
||||
val eventId = EventId("\$anEventId")
|
||||
val state = aPollHistoryState(
|
||||
currentItems = listOf(
|
||||
@@ -102,14 +102,14 @@ class PollHistoryViewTest : RobolectricTest() {
|
||||
eventsRecorder.assertEmpty()
|
||||
clickOn(CommonStrings.action_ok)
|
||||
eventsRecorder.assertSingle(
|
||||
PollHistoryEvents.EndPoll(eventId)
|
||||
PollHistoryEvent.EndPoll(eventId)
|
||||
)
|
||||
}
|
||||
|
||||
@Config(qualifiers = "h1024dp")
|
||||
@Test
|
||||
fun `clicking on poll answer emits the expected Event`() = runAndroidComposeUiTest {
|
||||
val eventsRecorder = EventsRecorder<PollHistoryEvents>()
|
||||
val eventsRecorder = EventsRecorder<PollHistoryEvent>()
|
||||
val eventId = EventId("\$anEventId")
|
||||
val state = aPollHistoryState(
|
||||
currentItems = listOf(
|
||||
@@ -133,13 +133,13 @@ class PollHistoryViewTest : RobolectricTest() {
|
||||
useUnmergedTree = true,
|
||||
).performClick()
|
||||
eventsRecorder.assertSingle(
|
||||
PollHistoryEvents.SelectPollAnswer(eventId, listOf(answer.id))
|
||||
PollHistoryEvent.SelectPollAnswer(eventId, listOf(answer.id))
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `clicking on past tab emits the expected Event`() = runAndroidComposeUiTest {
|
||||
val eventsRecorder = EventsRecorder<PollHistoryEvents>()
|
||||
val eventsRecorder = EventsRecorder<PollHistoryEvent>()
|
||||
setPollHistoryViewView(
|
||||
aPollHistoryState(
|
||||
eventSink = eventsRecorder
|
||||
@@ -147,14 +147,14 @@ class PollHistoryViewTest : RobolectricTest() {
|
||||
)
|
||||
clickOn(R.string.screen_polls_history_filter_past)
|
||||
eventsRecorder.assertSingle(
|
||||
PollHistoryEvents.SelectFilter(filter = PollHistoryFilter.PAST)
|
||||
PollHistoryEvent.SelectFilter(filter = PollHistoryFilter.PAST)
|
||||
)
|
||||
}
|
||||
|
||||
@Config(qualifiers = "h1024dp")
|
||||
@Test
|
||||
fun `clicking on load more emits the expected Event`() = runAndroidComposeUiTest {
|
||||
val eventsRecorder = EventsRecorder<PollHistoryEvents>()
|
||||
val eventsRecorder = EventsRecorder<PollHistoryEvent>()
|
||||
setPollHistoryViewView(
|
||||
aPollHistoryState(
|
||||
hasMoreToLoad = true,
|
||||
@@ -163,7 +163,7 @@ class PollHistoryViewTest : RobolectricTest() {
|
||||
)
|
||||
clickOn(CommonStrings.action_load_more)
|
||||
eventsRecorder.assertSingle(
|
||||
PollHistoryEvents.LoadMore
|
||||
PollHistoryEvent.LoadMore
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user