test(tui-03): verify Disconnected resets snapshot state and reaches ConnectionReducer
This commit is contained in:
@@ -2,6 +2,7 @@ package com.correx.apps.tui.reducer
|
||||
|
||||
import com.correx.apps.server.protocol.ClientMessage
|
||||
import com.correx.apps.tui.input.Action
|
||||
import com.correx.apps.tui.state.ConnectionState
|
||||
import com.correx.apps.tui.state.InputMode
|
||||
import com.correx.apps.tui.state.TuiState
|
||||
import org.junit.jupiter.api.Assertions.assertEquals
|
||||
@@ -101,6 +102,22 @@ class RootReducerTest {
|
||||
assertEquals(1L, result.cursors["s2"])
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `Disconnected resets snapshot state and sets connection to disconnected`() {
|
||||
val state = TuiState(
|
||||
snapshotPhase = false,
|
||||
cursors = mapOf("s1" to 3L),
|
||||
connection = ConnectionState(connected = true),
|
||||
)
|
||||
|
||||
val (newState, _) = RootReducer.reduce(state, Action.Disconnected, fixedClock)
|
||||
|
||||
assertEquals(true, newState.snapshotPhase)
|
||||
assertTrue(newState.cursors.isEmpty())
|
||||
assertEquals(false, newState.connection.connected)
|
||||
assertEquals(state.sessions.sessions, newState.sessions.sessions)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `AppendChar followed by Backspace returns to original buffer`() {
|
||||
val initial = TuiState(inputMode = InputMode.ROUTER, inputBuffer = "ab")
|
||||
|
||||
@@ -87,6 +87,22 @@ class SnapshotPhaseReducerTest {
|
||||
assertEquals(8L, result.state.cursors["s1"])
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `Disconnected resets snapshotPhase, pendingEvents, and cursors`() {
|
||||
val state = TuiState(
|
||||
snapshotPhase = false,
|
||||
cursors = mapOf("s1" to 5L),
|
||||
pendingEvents = listOf(ServerMessage.ProtocolError("x")),
|
||||
)
|
||||
|
||||
val result = SnapshotPhaseReducer.process(state, Action.Disconnected)
|
||||
|
||||
assertEquals(true, result.state.snapshotPhase)
|
||||
assertTrue(result.state.pendingEvents.isEmpty())
|
||||
assertTrue(result.state.cursors.isEmpty())
|
||||
assertEquals(listOf(Action.Disconnected), result.actionsToDispatch)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `during snapshotPhase SessionSnapshot installs cursor and is forwarded to sub-reducers`() {
|
||||
val state = TuiState(snapshotPhase = true)
|
||||
|
||||
Reference in New Issue
Block a user