Skip to content

Commit

Permalink
Update failing tests that may be delayed
Browse files Browse the repository at this point in the history
  • Loading branch information
LZRS committed Feb 28, 2024
1 parent 6749a67 commit 3e11dd3
Show file tree
Hide file tree
Showing 32 changed files with 468 additions and 308 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import org.hl7.fhir.r4.model.Coding
import org.smartregister.fhircore.engine.configuration.ConfigurationRegistry
import org.smartregister.fhircore.engine.data.local.DefaultRepository
import org.smartregister.fhircore.engine.data.local.tracing.TracingRepository
import org.smartregister.fhircore.engine.util.DefaultDispatcherProvider
import org.smartregister.fhircore.engine.util.DispatcherProvider
import org.smartregister.fhircore.engine.util.SharedPreferencesHelper

@Singleton
Expand All @@ -34,7 +34,7 @@ constructor(
tracingRepository: TracingRepository,
defaultRepository: DefaultRepository,
configurationRegistry: ConfigurationRegistry,
dispatcherProvider: DefaultDispatcherProvider,
dispatcherProvider: DispatcherProvider,
sharedPreferencesHelper: SharedPreferencesHelper,
) :
TracingRegisterDao(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import org.hl7.fhir.r4.model.Coding
import org.smartregister.fhircore.engine.configuration.ConfigurationRegistry
import org.smartregister.fhircore.engine.data.local.DefaultRepository
import org.smartregister.fhircore.engine.data.local.tracing.TracingRepository
import org.smartregister.fhircore.engine.util.DefaultDispatcherProvider
import org.smartregister.fhircore.engine.util.DispatcherProvider
import org.smartregister.fhircore.engine.util.SharedPreferencesHelper

@Singleton
Expand All @@ -34,7 +34,7 @@ constructor(
defaultRepository: DefaultRepository,
tracingRepository: TracingRepository,
configurationRegistry: ConfigurationRegistry,
dispatcherProvider: DefaultDispatcherProvider,
dispatcherProvider: DispatcherProvider,
sharedPreferencesHelper: SharedPreferencesHelper,
) :
TracingRegisterDao(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ import org.smartregister.fhircore.engine.domain.model.ProfileData
import org.smartregister.fhircore.engine.domain.model.RegisterData
import org.smartregister.fhircore.engine.domain.repository.RegisterDao
import org.smartregister.fhircore.engine.domain.util.PaginationConstant
import org.smartregister.fhircore.engine.util.DefaultDispatcherProvider
import org.smartregister.fhircore.engine.util.DispatcherProvider
import org.smartregister.fhircore.engine.util.LOGGED_IN_PRACTITIONER
import org.smartregister.fhircore.engine.util.SharedPreferencesHelper
import org.smartregister.fhircore.engine.util.extension.asDdMmmYyyy
Expand All @@ -74,13 +74,12 @@ import org.smartregister.fhircore.engine.util.extension.safeSubList
import org.smartregister.fhircore.engine.util.extension.toAgeDisplay
import timber.log.Timber

abstract class TracingRegisterDao
constructor(
abstract class TracingRegisterDao(
open val fhirEngine: FhirEngine,
val defaultRepository: DefaultRepository,
private val tracingRepository: TracingRepository,
val configurationRegistry: ConfigurationRegistry,
val dispatcherProvider: DefaultDispatcherProvider,
val dispatcherProvider: DispatcherProvider,
val sharedPreferencesHelper: SharedPreferencesHelper,
) : RegisterDao {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ import org.smartregister.fhircore.engine.trace.PerformanceReporter
import org.smartregister.fhircore.engine.util.SharedPreferencesHelper

@InstallIn(SingletonComponent::class)
@Module(includes = [NetworkModule::class, DispatcherModule::class])
@Module
class CoreModule {

@Singleton
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import org.smartregister.fhircore.engine.di.NetworkModule.Companion.TIMEOUT_DURA
* Provide [FhirEngine] dependency in isolation so we can replace it with a fake dependency in test
*/
@InstallIn(SingletonComponent::class)
@Module(includes = [CoreModule::class])
@Module
class FhirEngineModule {

@Singleton
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,15 @@ import androidx.compose.ui.text.intl.Locale
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.lifecycle.LiveData
import org.smartregister.fhircore.engine.domain.util.DataLoadState
import org.smartregister.fhircore.engine.ui.theme.BlueTextColor
import org.smartregister.fhircore.engine.ui.theme.LighterBlue
import org.smartregister.fhircore.engine.util.annotation.ExcludeFromJacocoGeneratedReport

@Composable
fun InfoCard(viewModel: SettingsViewModel) {
val state by viewModel.profileData.observeAsState()
fun InfoCard(profileData: LiveData<DataLoadState<ProfileData>>) {
val state by profileData.observeAsState()

when (state) {
is DataLoadState.Loading ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ fun SettingsScreen(
.padding(vertical = 20.dp)
.verticalScroll(rememberScrollState()),
) {
InfoCard(viewModel = settingsViewModel)
InfoCard(profileData = settingsViewModel.profileData)
Divider(color = DividerColor)
UserProfileRow(
icon = Icons.Rounded.Download,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* Copyright 2021 Ona Systems, Inc
*
* 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 org.smartregister.fhircore.engine.app

import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.test.UnconfinedTestDispatcher

@OptIn(ExperimentalCoroutinesApi::class) val testDispatcher = UnconfinedTestDispatcher()
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Copyright 2021 Ona Systems, Inc
*
* 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 org.smartregister.fhircore.engine.app.di.module

import dagger.Module
import dagger.Provides
import dagger.hilt.components.SingletonComponent
import dagger.hilt.testing.TestInstallIn
import javax.inject.Singleton
import org.smartregister.fhircore.engine.app.testDispatcher
import org.smartregister.fhircore.engine.di.DispatcherModule
import org.smartregister.fhircore.engine.util.DispatcherProvider

@Module
@TestInstallIn(components = [SingletonComponent::class], replaces = [DispatcherModule::class])
class FakeDispatcherModule {

@Provides
@Singleton
fun provideDispatcherProvider(): DispatcherProvider =
object : DispatcherProvider {

override fun main() = testDispatcher

override fun default() = testDispatcher

override fun io() = testDispatcher

override fun unconfined() = testDispatcher
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ import org.smartregister.fhircore.engine.data.remote.model.response.OAuthRespons
import org.smartregister.fhircore.engine.data.remote.shared.TokenAuthenticator
import org.smartregister.fhircore.engine.robolectric.RobolectricTest
import org.smartregister.fhircore.engine.rule.CoroutineTestRule
import org.smartregister.fhircore.engine.util.DispatcherProvider
import org.smartregister.fhircore.engine.util.SecureSharedPreference
import org.smartregister.fhircore.engine.util.toPasswordHash
import retrofit2.HttpException
Expand All @@ -69,6 +70,8 @@ class TokenAuthenticatorTest : RobolectricTest() {
@Inject lateinit var secureSharedPreference: SecureSharedPreference

@Inject lateinit var configService: ConfigService

@Inject lateinit var dispatcherProvider: DispatcherProvider
private val oAuthService: OAuthService = mockk()
private lateinit var tokenAuthenticator: TokenAuthenticator
private val accountManager = mockk<AccountManager>()
Expand All @@ -85,7 +88,7 @@ class TokenAuthenticatorTest : RobolectricTest() {
secureSharedPreference = secureSharedPreference,
configService = configService,
oAuthService = oAuthService,
dispatcherProvider = coroutineRule.testDispatcherProvider,
dispatcherProvider = dispatcherProvider,
accountManager = accountManager,
context = context,
),
Expand Down Expand Up @@ -234,7 +237,7 @@ class TokenAuthenticatorTest : RobolectricTest() {
secureSharedPreference = secureSharedPreference,
configService = configService,
oAuthService = oAuthService,
dispatcherProvider = coroutineRule.testDispatcherProvider,
dispatcherProvider = dispatcherProvider,
accountManager = accountManager,
context = context,
),
Expand Down Expand Up @@ -428,7 +431,7 @@ class TokenAuthenticatorTest : RobolectricTest() {
secureSharedPreference = secureSharedPreference,
configService = configService,
oAuthService = oAuthService,
dispatcherProvider = coroutineRule.testDispatcherProvider,
dispatcherProvider = dispatcherProvider,
accountManager = accountManager,
context = context,
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import dagger.hilt.android.testing.HiltAndroidTest
import io.mockk.coEvery
import io.mockk.coVerify
import io.mockk.mockk
import javax.inject.Inject
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.test.StandardTestDispatcher
Expand All @@ -46,6 +47,7 @@ import org.smartregister.fhircore.engine.configuration.view.PinViewConfiguration
import org.smartregister.fhircore.engine.data.remote.fhir.resource.FhirResourceDataSource
import org.smartregister.fhircore.engine.robolectric.RobolectricTest
import org.smartregister.fhircore.engine.rule.CoroutineTestRule
import org.smartregister.fhircore.engine.util.DispatcherProvider
import org.smartregister.fhircore.engine.util.SharedPreferencesHelper

@HiltAndroidTest
Expand All @@ -57,6 +59,8 @@ class ConfigurationRegistryTest : RobolectricTest() {
val context = ApplicationProvider.getApplicationContext<Context>()

@get:Rule(order = 1) val coroutineRule = CoroutineTestRule()

@Inject lateinit var dispatcherProvider: DispatcherProvider
private val testAppId = "default"
private lateinit var fhirResourceDataSource: FhirResourceDataSource
lateinit var configurationRegistry: ConfigurationRegistry
Expand All @@ -75,7 +79,7 @@ class ConfigurationRegistryTest : RobolectricTest() {
fhirEngine,
fhirResourceDataSource,
sharedPreferencesHelper,
coroutineRule.testDispatcherProvider,
dispatcherProvider,
)
coEvery { fhirResourceDataSource.loadData(any()) } returns
Bundle().apply { entry = mutableListOf() }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import io.mockk.slot
import io.mockk.spyk
import io.mockk.unmockkStatic
import io.mockk.verify
import javax.inject.Inject
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.test.runBlockingTest
Expand All @@ -61,7 +62,7 @@ import org.smartregister.fhircore.engine.app.fakes.Faker
import org.smartregister.fhircore.engine.configuration.app.ConfigService
import org.smartregister.fhircore.engine.robolectric.RobolectricTest
import org.smartregister.fhircore.engine.rule.CoroutineTestRule
import org.smartregister.fhircore.engine.util.DefaultDispatcherProvider
import org.smartregister.fhircore.engine.util.DispatcherProvider
import org.smartregister.fhircore.engine.util.SharedPreferencesHelper
import org.smartregister.fhircore.engine.util.extension.generateMissingId
import org.smartregister.fhircore.engine.util.extension.generateMissingVersionId
Expand All @@ -72,15 +73,15 @@ import org.smartregister.fhircore.engine.util.extension.loadRelatedPersons
@HiltAndroidTest
class DefaultRepositoryTest : RobolectricTest() {

private val dispatcherProvider = spyk(DefaultDispatcherProvider())

@get:Rule(order = 0) val hiltRule = HiltAndroidRule(this)

@OptIn(ExperimentalCoroutinesApi::class)
@get:Rule(order = 2)
var coroutineRule = CoroutineTestRule()
private val configurationRegistry = Faker.buildTestConfigurationRegistry()

@Inject lateinit var dispatcherProvider: DispatcherProvider

@BindValue val sharedPreferencesHelper = mockk<SharedPreferencesHelper>(relaxed = true)

private val configService: ConfigService = mockk()
Expand Down Expand Up @@ -126,7 +127,7 @@ class DefaultRepositoryTest : RobolectricTest() {
val defaultRepository =
DefaultRepository(
fhirEngine = fhirEngine,
dispatcherProvider = coroutineRule.testDispatcherProvider,
dispatcherProvider = dispatcherProvider,
sharedPreferencesHelper = sharedPreferencesHelper,
configurationRegistry = configurationRegistry,
configService = configService,
Expand Down Expand Up @@ -167,7 +168,7 @@ class DefaultRepositoryTest : RobolectricTest() {
val defaultRepository =
DefaultRepository(
fhirEngine = fhirEngine,
dispatcherProvider = coroutineRule.testDispatcherProvider,
dispatcherProvider = dispatcherProvider,
sharedPreferencesHelper = sharedPreferencesHelper,
configurationRegistry = configurationRegistry,
configService = configService,
Expand All @@ -189,7 +190,7 @@ class DefaultRepositoryTest : RobolectricTest() {
val defaultRepository =
DefaultRepository(
fhirEngine = fhirEngine,
dispatcherProvider = coroutineRule.testDispatcherProvider,
dispatcherProvider = dispatcherProvider,
sharedPreferencesHelper = sharedPreferencesHelper,
configurationRegistry = configurationRegistry,
configService = configService,
Expand All @@ -209,7 +210,7 @@ class DefaultRepositoryTest : RobolectricTest() {
val defaultRepository =
DefaultRepository(
fhirEngine = fhirEngine,
dispatcherProvider = coroutineRule.testDispatcherProvider,
dispatcherProvider = dispatcherProvider,
sharedPreferencesHelper = sharedPreferencesHelper,
configurationRegistry = configurationRegistry,
configService = configService,
Expand All @@ -232,7 +233,7 @@ class DefaultRepositoryTest : RobolectricTest() {
val defaultRepository =
DefaultRepository(
fhirEngine = fhirEngine,
dispatcherProvider = coroutineRule.testDispatcherProvider,
dispatcherProvider = dispatcherProvider,
sharedPreferencesHelper = sharedPreferencesHelper,
configurationRegistry = configurationRegistry,
configService = configService,
Expand All @@ -258,7 +259,7 @@ class DefaultRepositoryTest : RobolectricTest() {
val defaultRepository =
DefaultRepository(
fhirEngine = fhirEngine,
dispatcherProvider = coroutineRule.testDispatcherProvider,
dispatcherProvider = dispatcherProvider,
sharedPreferencesHelper = sharedPreferencesHelper,
configurationRegistry = configurationRegistry,
configService = configService,
Expand All @@ -280,7 +281,7 @@ class DefaultRepositoryTest : RobolectricTest() {
val defaultRepository =
DefaultRepository(
fhirEngine = fhirEngine,
dispatcherProvider = coroutineRule.testDispatcherProvider,
dispatcherProvider = dispatcherProvider,
sharedPreferencesHelper = sharedPreferencesHelper,
configurationRegistry = configurationRegistry,
configService = configService,
Expand All @@ -301,7 +302,7 @@ class DefaultRepositoryTest : RobolectricTest() {
val defaultRepository =
DefaultRepository(
fhirEngine = fhirEngine,
dispatcherProvider = coroutineRule.testDispatcherProvider,
dispatcherProvider = dispatcherProvider,
sharedPreferencesHelper = sharedPreferencesHelper,
configurationRegistry = configurationRegistry,
configService = configService,
Expand All @@ -326,7 +327,7 @@ class DefaultRepositoryTest : RobolectricTest() {
val defaultRepository =
DefaultRepository(
fhirEngine = fhirEngine,
dispatcherProvider = coroutineRule.testDispatcherProvider,
dispatcherProvider = dispatcherProvider,
sharedPreferencesHelper = sharedPreferencesHelper,
configurationRegistry = configurationRegistry,
configService = configService,
Expand Down Expand Up @@ -371,7 +372,7 @@ class DefaultRepositoryTest : RobolectricTest() {
val defaultRepository =
DefaultRepository(
fhirEngine = fhirEngine,
dispatcherProvider = coroutineRule.testDispatcherProvider,
dispatcherProvider = dispatcherProvider,
sharedPreferencesHelper = sharedPreferencesHelper,
configurationRegistry = configurationRegistry,
configService = configService,
Expand Down
Loading

0 comments on commit 3e11dd3

Please sign in to comment.