diff --git a/features/settings/src/test/kotlin/app/dapk/st/settings/SettingsItemFactoryTest.kt b/features/settings/src/test/kotlin/app/dapk/st/settings/SettingsItemFactoryTest.kt index 2c4c5e9..d8885d9 100644 --- a/features/settings/src/test/kotlin/app/dapk/st/settings/SettingsItemFactoryTest.kt +++ b/features/settings/src/test/kotlin/app/dapk/st/settings/SettingsItemFactoryTest.kt @@ -1,25 +1,38 @@ package app.dapk.st.settings import app.dapk.st.core.BuildMeta +import app.dapk.st.push.PushTokenRegistrars +import app.dapk.st.push.Registrar import internalfixture.aSettingHeaderItem import internalfixture.aSettingTextItem +import io.mockk.coEvery +import io.mockk.every +import io.mockk.mockk +import kotlinx.coroutines.test.runTest import org.amshove.kluent.shouldBeEqualTo import org.junit.Test +import test.delegateReturn + +private val A_SELECTION = Registrar("A_SELECTION") class SettingsItemFactoryTest { private val buildMeta = BuildMeta(versionName = "a-version-name", versionCode = 100) + private val fakePushTokenRegistrars = FakePushRegistrars() - private val settingsItemFactory = SettingsItemFactory(buildMeta, ) + private val settingsItemFactory = SettingsItemFactory(buildMeta, fakePushTokenRegistrars.instance) @Test - fun `when creating root items, then is expected`() { + fun `when creating root items, then is expected`() = runTest { + fakePushTokenRegistrars.givenCurrentSelection().returns(A_SELECTION) + val result = settingsItemFactory.root() result shouldBeEqualTo listOf( aSettingHeaderItem("General"), aSettingTextItem(SettingItem.Id.Encryption, "Encryption"), aSettingTextItem(SettingItem.Id.EventLog, "Event log"), + aSettingTextItem(SettingItem.Id.PushProvider, "Push provider", A_SELECTION.id), aSettingHeaderItem("Data"), aSettingTextItem(SettingItem.Id.ClearCache, "Clear cache"), aSettingHeaderItem("Account"), @@ -29,4 +42,12 @@ class SettingsItemFactoryTest { aSettingTextItem(SettingItem.Id.Ignored, "Version", buildMeta.versionName), ) } +} + +class FakePushRegistrars { + + val instance = mockk() + + fun givenCurrentSelection() = coEvery { instance.currentSelection() }.delegateReturn() + } \ 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 51f79c8..5fd5279 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 @@ -34,6 +34,7 @@ internal class SettingsViewModelTest { private val fakeCryptoService = FakeCryptoService() private val fakeSyncService = FakeSyncService() private val fakeUriFilenameResolver = FakeUriFilenameResolver() + private val fakePushTokenRegistrars = FakePushRegistrars() private val fakeSettingsItemFactory = FakeSettingsItemFactory() private val viewModel = SettingsViewModel( @@ -43,6 +44,7 @@ internal class SettingsViewModelTest { fakeSyncService, fakeUriFilenameResolver.instance, fakeSettingsItemFactory.instance, + fakePushTokenRegistrars.instance, runViewModelTest.testMutableStateFactory(), ) diff --git a/features/settings/src/test/kotlin/internalfake/FakeSettingsItemFactory.kt b/features/settings/src/test/kotlin/internalfake/FakeSettingsItemFactory.kt index 1b90817..226cec9 100644 --- a/features/settings/src/test/kotlin/internalfake/FakeSettingsItemFactory.kt +++ b/features/settings/src/test/kotlin/internalfake/FakeSettingsItemFactory.kt @@ -1,6 +1,7 @@ package internalfake import app.dapk.st.settings.SettingsItemFactory +import io.mockk.coEvery import io.mockk.every import io.mockk.mockk import test.delegateReturn @@ -8,5 +9,5 @@ import test.delegateReturn internal class FakeSettingsItemFactory { val instance = mockk() - fun givenRoot() = every { instance.root() }.delegateReturn() + fun givenRoot() = coEvery { instance.root() }.delegateReturn() } \ No newline at end of file