Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/issue-1535-zeir-growth-monitorin…
Browse files Browse the repository at this point in the history
…g' into issue-1535-zeir-growth-monitoring
  • Loading branch information
qaziabubakar-vd committed Sep 13, 2023
2 parents 5044a87 + 3f5bffa commit e2b96f4
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import androidx.lifecycle.viewModelScope
import androidx.navigation.NavController
import androidx.work.WorkManager
import androidx.work.workDataOf
import com.google.android.fhir.sync.SyncJobStatus
import dagger.hilt.android.lifecycle.HiltViewModel
import java.text.SimpleDateFormat
import java.time.OffsetDateTime
Expand Down Expand Up @@ -181,11 +182,13 @@ constructor(
}
is AppMainEvent.OpenRegistersBottomSheet -> displayRegisterBottomSheet(event)
is AppMainEvent.UpdateSyncState -> {
sharedPreferencesHelper.write(
SharedPreferenceKey.LAST_SYNC_TIMESTAMP.name,
formatLastSyncTimestamp(event.state.timestamp),
)
viewModelScope.launch { retrieveAppMainUiState() }
if (event.state is SyncJobStatus.Finished) {
sharedPreferencesHelper.write(
SharedPreferenceKey.LAST_SYNC_TIMESTAMP.name,
formatLastSyncTimestamp(event.state.timestamp),
)
viewModelScope.launch { retrieveAppMainUiState() }
}
}
is AppMainEvent.TriggerWorkflow ->
event.navMenu.actions?.handleClickEvent(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ import io.mockk.runs
import io.mockk.slot
import io.mockk.spyk
import java.io.Serializable
import java.time.OffsetDateTime
import kotlinx.coroutines.test.runTest
import org.hl7.fhir.r4.model.QuestionnaireResponse
import org.junit.Assert
Expand Down Expand Up @@ -65,7 +64,7 @@ class AppMainActivityTest : ActivityRobolectricTest() {

@BindValue val fhirCarePlanGenerator: FhirCarePlanGenerator = mockk()

@BindValue val eventBus: EventBus = mockk()
@BindValue val eventBus: EventBus = mockk(relaxUnitFun = true, relaxed = true)

lateinit var appMainActivity: AppMainActivity

Expand Down Expand Up @@ -107,12 +106,11 @@ class AppMainActivityTest : ActivityRobolectricTest() {
val syncJobStatusTimestamp = syncJobStatus.timestamp

appMainActivity.onSync(syncJobStatus)
Assert.assertNotNull(viewModel.retrieveLastSyncTimestamp())

// Timestamp updated to the SyncJobStatus timestamp
Assert.assertEquals(
// Timestamp last sync timestamp not updated
Assert.assertNotEquals(
viewModel.appMainUiState.value.lastSyncTime,
viewModel.formatLastSyncTimestamp(syncJobStatusTimestamp)!!,
viewModel.formatLastSyncTimestamp(syncJobStatusTimestamp),
)
}

Expand All @@ -123,11 +121,12 @@ class AppMainActivityTest : ActivityRobolectricTest() {
SharedPreferenceKey.LAST_SYNC_TIMESTAMP.name,
"2022-05-19",
)
appMainActivity.onSync(SyncJobStatus.Failed(listOf()))
val syncJobStatus = SyncJobStatus.Failed(listOf())
appMainActivity.onSync(syncJobStatus)

Assert.assertNotNull(viewModel.retrieveLastSyncTimestamp())
Assert.assertEquals(
appMainActivity.appMainViewModel.formatLastSyncTimestamp(OffsetDateTime.now()),
// Timestamp not update if status is Failed
Assert.assertNotEquals(
appMainActivity.appMainViewModel.formatLastSyncTimestamp(syncJobStatus.timestamp),
viewModel.appMainUiState.value.lastSyncTime,
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,21 +165,6 @@ class AppMainViewModelTest : RobolectricTest() {

@Test
fun testOnEventUpdateSyncStates() {
// Simulate sync state Failed
val syncJobStatusFailed = mockk<SyncJobStatus.Failed>()
val syncFailedTimeStamp = OffsetDateTime.now()
every { syncJobStatusFailed.timestamp } returns syncFailedTimeStamp
appMainViewModel.onEvent(
AppMainEvent.UpdateSyncState(
syncJobStatusFailed,
appMainViewModel.formatLastSyncTimestamp(syncJobStatusFailed.timestamp),
),
)
Assert.assertEquals(
sharedPreferencesHelper.read(SharedPreferenceKey.LAST_SYNC_TIMESTAMP.name, null),
appMainViewModel.appMainUiState.value.lastSyncTime,
)

// Simulate sync state Finished
val syncFinishedTimestamp = OffsetDateTime.now()
val syncFinishedSyncJobStatus = mockk<SyncJobStatus.Finished>()
Expand Down

0 comments on commit e2b96f4

Please sign in to comment.