Skip to content

Commit

Permalink
Merge pull request #109 from snuhcs-course/test/new-backup-setting-vi…
Browse files Browse the repository at this point in the history
…ewmodel

✅ Fix error in test
  • Loading branch information
JH747 authored Dec 9, 2023
2 parents fb71b44 + 3962d13 commit d2a371f
Showing 1 changed file with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,15 @@ class BackupSettingsViewModelTest {
private val mainThreadSurrogate = newSingleThreadContext("UI thread")

@MockK
private val mockSettingsRepository: SettingsRepository = mockk(relaxed = true)
private lateinit var mockSettingsRepository: SettingsRepository
private lateinit var viewModel: BackupSettingsViewModel


@OptIn(ExperimentalCoroutinesApi::class)
@Before
fun setup() {
Dispatchers.setMain(mainThreadSurrogate)
mockSettingsRepository = mockk(relaxed = true)
viewModel = BackupSettingsViewModel(mockSettingsRepository)
}

Expand Down Expand Up @@ -102,15 +103,16 @@ class BackupSettingsViewModelTest {

viewModel.backup()

val observedUiStates = viewModel.uiState.take(2).toList()
val observedUiStates = viewModel.uiState.take(1).toList()
val expectedValue2 = BackupSettingsUiState(
lastBackupDate = date,
isAutoBackupEnabled = false,
loading = !expectedValue1.loading,
buttonEnabled = !expectedValue1.buttonEnabled,
alert = BackupSettingsAlert.SUCCESS
)
assertEquals(listOf(expectedValue1, expectedValue2), observedUiStates)

assertEquals(expectedValue1, observedUiStates[0])
coVerify { mockSettingsRepository.setLastBackupDate(date) }
}

Expand Down

0 comments on commit d2a371f

Please sign in to comment.