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