diff --git a/chat-engine/build.gradle b/chat-engine/build.gradle index 8aa6dcf..beab4c8 100644 --- a/chat-engine/build.gradle +++ b/chat-engine/build.gradle @@ -9,4 +9,5 @@ dependencies { kotlinFixtures(it) testFixturesImplementation(testFixtures(project(":matrix:common"))) + testFixturesImplementation(testFixtures(project(":core"))) } \ No newline at end of file diff --git a/chat-engine/src/testFixtures/kotlin/fake/FakeChatEngine.kt b/chat-engine/src/testFixtures/kotlin/fake/FakeChatEngine.kt new file mode 100644 index 0000000..823bc26 --- /dev/null +++ b/chat-engine/src/testFixtures/kotlin/fake/FakeChatEngine.kt @@ -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() + +} \ No newline at end of file diff --git a/features/directory/build.gradle b/features/directory/build.gradle index 44351f5..67b4807 100644 --- a/features/directory/build.gradle +++ b/features/directory/build.gradle @@ -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")) } \ No newline at end of file diff --git a/features/directory/src/test/kotlin/app/dapk/st/directory/DirectoryViewModelTest.kt b/features/directory/src/test/kotlin/app/dapk/st/directory/DirectoryViewModelTest.kt index 752805a..4b0b5a8 100644 --- a/features/directory/src/test/kotlin/app/dapk/st/directory/DirectoryViewModelTest.kt +++ b/features/directory/src/test/kotlin/app/dapk/st/directory/DirectoryViewModelTest.kt @@ -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() -} - -class FakeDirectoryUseCase { - val instance = mockk() - fun given() = every { instance.state() }.delegateReturn() } \ No newline at end of file diff --git a/features/messenger/src/test/kotlin/app/dapk/st/messenger/MessengerViewModelTest.kt b/features/messenger/src/test/kotlin/app/dapk/st/messenger/MessengerViewModelTest.kt index fce4662..fb8680a 100644 --- a/features/messenger/src/test/kotlin/app/dapk/st/messenger/MessengerViewModelTest.kt +++ b/features/messenger/src/test/kotlin/app/dapk/st/messenger/MessengerViewModelTest.kt @@ -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() diff --git a/matrix-chat-engine/src/test/kotlin/fake/FakeDirectoryUseCase.kt b/matrix-chat-engine/src/test/kotlin/fake/FakeDirectoryUseCase.kt new file mode 100644 index 0000000..434e0db --- /dev/null +++ b/matrix-chat-engine/src/test/kotlin/fake/FakeDirectoryUseCase.kt @@ -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() + fun given() = every { instance.state() }.delegateReturn() +} \ No newline at end of file