Add some refactoring and first simple test on RoomListPresenter

This commit is contained in:
ganfra 2023-01-18 17:57:34 +01:00
parent b3aa9f7ba2
commit 1f2a9026ea
30 changed files with 520 additions and 140 deletions

View file

@ -26,5 +26,5 @@ data class RoomListState(
val roomList: ImmutableList<RoomListRoomSummary>,
val filter: String,
val isLoginOut: Boolean,
val eventSink: (RoomListEvents) -> Unit = {}
val eventSink: (RoomListEvents) -> Unit
)

View file

@ -1,32 +0,0 @@
/*
* Copyright (c) 2022 New Vector Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.element.android.x.features.roomlist
import org.junit.Assert.assertEquals
import org.junit.Test
/**
* Example local unit test, which will execute on the development machine (host).
*
* See [testing documentation](http://d.android.com/tools/testing).
*/
class ExampleUnitTest {
@Test
fun addition_isCorrect() {
assertEquals(4, 2 + 2)
}
}

View file

@ -0,0 +1,43 @@
/*
* Copyright (c) 2023 New Vector Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.element.android.x.features.roomlist
import app.cash.molecule.RecompositionClock
import app.cash.molecule.moleculeFlow
import app.cash.turbine.test
import com.google.common.truth.Truth.assertThat
import io.element.android.x.matrix.FakeMatrixClient
import io.element.android.x.matrix.core.SessionId
import kotlinx.coroutines.test.runTest
import org.junit.Test
class RoomListPresenterTests {
@Test
fun `present - should start with no user and then load user with success`() = runTest {
val presenter = RoomListPresenter(FakeMatrixClient(SessionId("sessionId")), LastMessageFormatter())
moleculeFlow(RecompositionClock.Immediate) {
presenter.present()
}.test {
val initialState = awaitItem()
assertThat(initialState.matrixUser).isNull()
val withUserState = awaitItem()
assertThat(withUserState).isNotNull()
}
}
}