From 8a95a77d7aa3d4e014648ad3d5072438cb37c759 Mon Sep 17 00:00:00 2001 From: Adam Brown Date: Wed, 12 Oct 2022 20:07:23 +0100 Subject: [PATCH] porting settings tests to engine --- .../src/testFixtures/kotlin/fake/FakeChatEngine.kt | 4 ++++ features/settings/build.gradle | 3 +-- .../app/dapk/st/settings/SettingsViewModelTest.kt | 12 ++++-------- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/chat-engine/src/testFixtures/kotlin/fake/FakeChatEngine.kt b/chat-engine/src/testFixtures/kotlin/fake/FakeChatEngine.kt index 823bc26..8028923 100644 --- a/chat-engine/src/testFixtures/kotlin/fake/FakeChatEngine.kt +++ b/chat-engine/src/testFixtures/kotlin/fake/FakeChatEngine.kt @@ -2,9 +2,11 @@ package fake import app.dapk.st.engine.ChatEngine import app.dapk.st.matrix.common.RoomId +import io.mockk.coEvery import io.mockk.every import io.mockk.mockk import test.delegateReturn +import java.io.InputStream class FakeChatEngine : ChatEngine by mockk() { @@ -12,4 +14,6 @@ class FakeChatEngine : ChatEngine by mockk() { fun givenDirectory() = every { directory() }.delegateReturn() + fun givenImportKeys(inputStream: InputStream, passphrase: String) = coEvery { inputStream.importRoomKeys(passphrase) }.delegateReturn() + } \ No newline at end of file diff --git a/features/settings/build.gradle b/features/settings/build.gradle index fc553d4..7eb18c8 100644 --- a/features/settings/build.gradle +++ b/features/settings/build.gradle @@ -12,11 +12,10 @@ dependencies { kotlinTest(it) - androidImportFixturesWorkaround(project, project(":matrix:services:sync")) - androidImportFixturesWorkaround(project, project(":matrix:services:crypto")) 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/settings/src/test/kotlin/app/dapk/st/settings/SettingsViewModelTest.kt b/features/settings/src/test/kotlin/app/dapk/st/settings/SettingsViewModelTest.kt index 87477c4..98c4f12 100644 --- a/features/settings/src/test/kotlin/app/dapk/st/settings/SettingsViewModelTest.kt +++ b/features/settings/src/test/kotlin/app/dapk/st/settings/SettingsViewModelTest.kt @@ -3,9 +3,8 @@ package app.dapk.st.settings import ViewModelTest import app.dapk.st.core.Lce import app.dapk.st.design.components.SpiderPage -import app.dapk.st.matrix.crypto.ImportResult +import app.dapk.st.engine.ImportResult import fake.* -import fake.FakeStoreCleaner import fixture.aRoomId import internalfake.FakeSettingsItemFactory import internalfake.FakeUriFilenameResolver @@ -35,20 +34,18 @@ internal class SettingsViewModelTest { private val fakeStoreCleaner = FakeStoreCleaner() private val fakeContentResolver = FakeContentResolver() - private val fakeCryptoService = FakeCryptoService() - private val fakeSyncService = FakeSyncService() private val fakeUriFilenameResolver = FakeUriFilenameResolver() private val fakePushTokenRegistrars = FakePushRegistrars() private val fakeSettingsItemFactory = FakeSettingsItemFactory() private val fakeThemeStore = FakeThemeStore() private val fakeLoggingStore = FakeLoggingStore() private val fakeMessageOptionsStore = FakeMessageOptionsStore() + private val fakeChatEngine = FakeChatEngine() private val viewModel = SettingsViewModel( + fakeChatEngine, fakeStoreCleaner, fakeContentResolver.instance, - fakeCryptoService, - fakeSyncService, fakeUriFilenameResolver.instance, fakeSettingsItemFactory.instance, fakePushTokenRegistrars.instance, @@ -174,9 +171,8 @@ internal class SettingsViewModelTest { @Test fun `given success when importing room keys, then emits progress`() = runViewModelTest { - fakeSyncService.expectUnit { it.forceManualRefresh(A_LIST_OF_ROOM_IDS) } fakeContentResolver.givenFile(A_URI.instance).returns(AN_INPUT_STREAM.instance) - fakeCryptoService.givenImportKeys(AN_INPUT_STREAM.instance, A_PASSPHRASE).returns(flowOf(AN_IMPORT_SUCCESS)) + fakeChatEngine.givenImportKeys(AN_INPUT_STREAM.instance, A_PASSPHRASE).returns(flowOf(AN_IMPORT_SUCCESS)) viewModel .test(initialState = SettingsScreenState(A_IMPORT_ROOM_KEYS_PAGE_WITH_SELECTION))