porting directory tests to engine

This commit is contained in:
Adam Brown 2022-10-12 20:03:44 +01:00
parent 8f1d8cdcc1
commit d491bb844a
6 changed files with 42 additions and 24 deletions

View File

@ -9,4 +9,5 @@ dependencies {
kotlinFixtures(it)
testFixturesImplementation(testFixtures(project(":matrix:common")))
testFixturesImplementation(testFixtures(project(":core")))
}

View File

@ -0,0 +1,15 @@
package fake
import app.dapk.st.engine.ChatEngine
import app.dapk.st.matrix.common.RoomId
import io.mockk.every
import io.mockk.mockk
import test.delegateReturn
class FakeChatEngine : ChatEngine by mockk() {
fun givenMessages(roomId: RoomId, disableReadReceipts: Boolean) = every { messages(roomId, disableReadReceipts) }.delegateReturn()
fun givenDirectory() = every { directory() }.delegateReturn()
}

View File

@ -11,11 +11,10 @@ dependencies {
kotlinTest(it)
androidImportFixturesWorkaround(project, project(":matrix:services:sync"))
androidImportFixturesWorkaround(project, project(":matrix:services:message"))
androidImportFixturesWorkaround(project, project(":matrix:common"))
androidImportFixturesWorkaround(project, project(":core"))
androidImportFixturesWorkaround(project, project(":domains:store"))
androidImportFixturesWorkaround(project, project(":domains:android:viewmodel"))
androidImportFixturesWorkaround(project, project(":domains:android:stub"))
androidImportFixturesWorkaround(project, project(":chat-engine"))
}

View File

@ -1,25 +1,26 @@
package app.dapk.st.directory
import ViewModelTest
import app.dapk.st.engine.DirectoryItem
import app.dapk.st.engine.UnreadCount
import fake.FakeChatEngine
import fixture.aRoomOverview
import io.mockk.every
import io.mockk.mockk
import kotlinx.coroutines.flow.flowOf
import org.junit.Test
import test.delegateReturn
private val AN_OVERVIEW = aRoomOverview()
private val AN_OVERVIEW_STATE = RoomFoo(AN_OVERVIEW, UnreadCount(1), null)
private val AN_OVERVIEW_STATE = DirectoryItem(AN_OVERVIEW, UnreadCount(1), null)
class DirectoryViewModelTest {
private val runViewModelTest = ViewModelTest()
private val fakeDirectoryUseCase = FakeDirectoryUseCase()
private val fakeShortcutHandler = FakeShortcutHandler()
private val fakeChatEngine = FakeChatEngine()
private val viewModel = DirectoryViewModel(
fakeShortcutHandler.instance,
fakeDirectoryUseCase.instance,
fakeChatEngine,
runViewModelTest.testMutableStateFactory(),
)
@ -33,7 +34,7 @@ class DirectoryViewModelTest {
@Test
fun `when starting, then updates shortcuts and emits room state`() = runViewModelTest {
fakeShortcutHandler.instance.expectUnit { it.onDirectoryUpdate(listOf(AN_OVERVIEW)) }
fakeDirectoryUseCase.given().returns(flowOf(listOf(AN_OVERVIEW_STATE)))
fakeChatEngine.givenDirectory().returns(flowOf(listOf(AN_OVERVIEW_STATE)))
viewModel.test().start()
@ -44,9 +45,4 @@ class DirectoryViewModelTest {
class FakeShortcutHandler {
val instance = mockk<ShortcutHandler>()
}
class FakeDirectoryUseCase {
val instance = mockk<DirectoryUseCase>()
fun given() = every { instance.state() }.delegateReturn()
}

View File

@ -2,15 +2,17 @@ package app.dapk.st.messenger
import ViewModelTest
import app.dapk.st.core.Lce
import app.dapk.st.engine.*
import app.dapk.st.matrix.common.*
import app.dapk.st.engine.MessengerState
import app.dapk.st.engine.RoomState
import app.dapk.st.engine.SendMessage
import app.dapk.st.matrix.common.EventId
import app.dapk.st.matrix.common.RoomId
import app.dapk.st.matrix.common.UserId
import fake.FakeChatEngine
import fake.FakeMessageOptionsStore
import fixture.*
import io.mockk.every
import io.mockk.mockk
import kotlinx.coroutines.flow.flowOf
import org.junit.Test
import test.delegateReturn
private const val READ_RECEIPTS_ARE_DISABLED = true
private val A_ROOM_ID = aRoomId("messenger state room id")
@ -18,12 +20,6 @@ private const val A_MESSAGE_CONTENT = "message content"
private val AN_EVENT_ID = anEventId("state event")
private val A_SELF_ID = aUserId("self")
class FakeChatEngine : ChatEngine by mockk() {
fun givenMessages(roomId: RoomId, disableReadReceipts: Boolean) = every { messages(roomId, disableReadReceipts) }.delegateReturn()
}
class MessengerViewModelTest {
private val runViewModelTest = ViewModelTest()

View File

@ -0,0 +1,11 @@
package fake
import app.dapk.st.engine.DirectoryUseCase
import io.mockk.every
import io.mockk.mockk
import test.delegateReturn
internal class FakeDirectoryUseCase {
val instance = mockk<DirectoryUseCase>()
fun given() = every { instance.state() }.delegateReturn()
}