Add leave room test cases
This commit is contained in:
parent
f1e05e0a6f
commit
e990227f81
|
@ -15,14 +15,12 @@ import fake.FakeChatEngine
|
||||||
import fake.FakeJobBag
|
import fake.FakeJobBag
|
||||||
import fake.FakeMessageOptionsStore
|
import fake.FakeMessageOptionsStore
|
||||||
import fixture.*
|
import fixture.*
|
||||||
|
import io.mockk.coEvery
|
||||||
import io.mockk.every
|
import io.mockk.every
|
||||||
import io.mockk.mockk
|
import io.mockk.mockk
|
||||||
import kotlinx.coroutines.flow.flowOf
|
import kotlinx.coroutines.flow.flowOf
|
||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
import test.ReducerTestScope
|
import test.*
|
||||||
import test.delegateReturn
|
|
||||||
import test.expect
|
|
||||||
import test.testReducer
|
|
||||||
|
|
||||||
private const val READ_RECEIPTS_ARE_DISABLED = true
|
private const val READ_RECEIPTS_ARE_DISABLED = true
|
||||||
private val A_ROOM_ID = aRoomId("messenger state room id")
|
private val A_ROOM_ID = aRoomId("messenger state room id")
|
||||||
|
@ -37,11 +35,16 @@ private val AN_IMAGE_BUBBLE = BubbleModel.Image(
|
||||||
mockk(),
|
mockk(),
|
||||||
BubbleModel.Event("author-id", "author-name", edited = false, time = "10:27")
|
BubbleModel.Event("author-id", "author-name", edited = false, time = "10:27")
|
||||||
)
|
)
|
||||||
|
|
||||||
private val A_TEXT_BUBBLE = BubbleModel.Text(
|
private val A_TEXT_BUBBLE = BubbleModel.Text(
|
||||||
content = RichText(listOf(RichText.Part.Normal(A_MESSAGE_CONTENT))),
|
content = RichText(listOf(RichText.Part.Normal(A_MESSAGE_CONTENT))),
|
||||||
BubbleModel.Event("author-id", "author-name", edited = false, time = "10:27")
|
BubbleModel.Event("author-id", "author-name", edited = false, time = "10:27")
|
||||||
)
|
)
|
||||||
|
private val A_DIALOG_STATE = DialogState.PositiveNegative(
|
||||||
|
"a title",
|
||||||
|
"a subtitle",
|
||||||
|
positiveAction = ScreenAction.LeaveRoomConfirmation.Confirm,
|
||||||
|
negativeAction = ScreenAction.LeaveRoomConfirmation.Deny,
|
||||||
|
)
|
||||||
|
|
||||||
class MessengerReducerTest {
|
class MessengerReducerTest {
|
||||||
|
|
||||||
|
@ -72,6 +75,7 @@ class MessengerReducerTest {
|
||||||
roomState = Lce.Loading(),
|
roomState = Lce.Loading(),
|
||||||
composerState = ComposerState.Text(value = "", reply = null),
|
composerState = ComposerState.Text(value = "", reply = null),
|
||||||
viewerState = null,
|
viewerState = null,
|
||||||
|
dialogState = null,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -84,6 +88,7 @@ class MessengerReducerTest {
|
||||||
roomState = Lce.Loading(),
|
roomState = Lce.Loading(),
|
||||||
composerState = ComposerState.Text(value = "", reply = null),
|
composerState = ComposerState.Text(value = "", reply = null),
|
||||||
viewerState = null,
|
viewerState = null,
|
||||||
|
dialogState = null,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -96,6 +101,7 @@ class MessengerReducerTest {
|
||||||
roomState = Lce.Loading(),
|
roomState = Lce.Loading(),
|
||||||
composerState = ComposerState.Attachments(listOf(A_MESSAGE_ATTACHMENT), reply = null),
|
composerState = ComposerState.Attachments(listOf(A_MESSAGE_ATTACHMENT), reply = null),
|
||||||
viewerState = null,
|
viewerState = null,
|
||||||
|
dialogState = null,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -221,6 +227,60 @@ class MessengerReducerTest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `when LeaveRoom, then updates dialog state with leave room confirmation`() = runReducerTest {
|
||||||
|
reduce(ScreenAction.LeaveRoom)
|
||||||
|
|
||||||
|
assertOnlyDispatches(
|
||||||
|
ScreenAction.UpdateDialogState(
|
||||||
|
DialogState.PositiveNegative(
|
||||||
|
title = "Leave room",
|
||||||
|
subtitle = "Are you sure you want you leave the room? If the room is private you will need to be invited again to rejoin.",
|
||||||
|
negativeAction = ScreenAction.LeaveRoomConfirmation.Deny,
|
||||||
|
positiveAction = ScreenAction.LeaveRoomConfirmation.Confirm,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `when UpdateDialogState, then updates dialog state`() = runReducerTest {
|
||||||
|
reduce(ScreenAction.UpdateDialogState(dialogState = A_DIALOG_STATE))
|
||||||
|
|
||||||
|
assertOnlyStateChange { it.copy(dialogState = A_DIALOG_STATE) }
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `given can leave room, when LeaveConfirmation Confirm, then removes dialog and rejects room and emits OnLeftRoom`() = runReducerTest {
|
||||||
|
fakeChatEngine.expect { it.rejectRoom(A_ROOM_ID) }
|
||||||
|
|
||||||
|
reduce(ScreenAction.LeaveRoomConfirmation.Confirm)
|
||||||
|
|
||||||
|
assertDispatches(ScreenAction.UpdateDialogState(dialogState = null))
|
||||||
|
assertEvents(MessengerEvent.OnLeftRoom)
|
||||||
|
assertNoStateChange()
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `given leave room fails, when LeaveConfirmation Confirm, then removes dialog and emits toast`() = runReducerTest {
|
||||||
|
fakeChatEngine.expectError(error = RuntimeException("an error")) { fakeChatEngine.rejectRoom(A_ROOM_ID) }
|
||||||
|
|
||||||
|
reduce(ScreenAction.LeaveRoomConfirmation.Confirm)
|
||||||
|
|
||||||
|
assertDispatches(ScreenAction.UpdateDialogState(dialogState = null))
|
||||||
|
assertEvents(MessengerEvent.Toast("Failed to leave room"))
|
||||||
|
assertNoStateChange()
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `when LeaveConfirmation Deny, then removes dialog and does nothing`() = runReducerTest {
|
||||||
|
reduce(ScreenAction.LeaveRoomConfirmation.Deny)
|
||||||
|
|
||||||
|
assertDispatches(ScreenAction.UpdateDialogState(dialogState = null))
|
||||||
|
assertNoEvents()
|
||||||
|
assertNoStateChange()
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `when OpenGalleryPicker, then emits event`() = runReducerTest {
|
fun `when OpenGalleryPicker, then emits event`() = runReducerTest {
|
||||||
reduce(ScreenAction.OpenGalleryPicker)
|
reduce(ScreenAction.OpenGalleryPicker)
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
Subproject commit d596949ac2b923b02da55ddd78e2e26dc46af82a
|
Subproject commit 337a65b27b9911205e52a87c075be4bbf70a557d
|
Loading…
Reference in New Issue