From be6b946dc0fe370f095b256e51a615b82fffec10 Mon Sep 17 00:00:00 2001 From: MyungHyun Ryu Date: Thu, 7 Dec 2023 17:06:03 +0900 Subject: [PATCH 1/2] :white_check_mark: Fix error in test --- .../speechbuddy/viewmodel/BackupSettingsViewModelTest.kt | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/frontend/app/src/test/java/com/example/speechbuddy/viewmodel/BackupSettingsViewModelTest.kt b/frontend/app/src/test/java/com/example/speechbuddy/viewmodel/BackupSettingsViewModelTest.kt index b6ea4b7c..e279630e 100644 --- a/frontend/app/src/test/java/com/example/speechbuddy/viewmodel/BackupSettingsViewModelTest.kt +++ b/frontend/app/src/test/java/com/example/speechbuddy/viewmodel/BackupSettingsViewModelTest.kt @@ -29,7 +29,7 @@ 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 @@ -37,6 +37,7 @@ class BackupSettingsViewModelTest { @Before fun setup() { Dispatchers.setMain(mainThreadSurrogate) + mockSettingsRepository = mockk(relaxed = true) viewModel = BackupSettingsViewModel(mockSettingsRepository) } @@ -102,7 +103,7 @@ 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, @@ -110,7 +111,8 @@ class BackupSettingsViewModelTest { buttonEnabled = !expectedValue1.buttonEnabled, alert = BackupSettingsAlert.SUCCESS ) - assertEquals(listOf(expectedValue1, expectedValue2), observedUiStates) + + assertEquals(expectedValue1, observedUiStates) coVerify { mockSettingsRepository.setLastBackupDate(date) } } From 3962d13c27ad5915c851d3e1b1d31ba1e334955a Mon Sep 17 00:00:00 2001 From: JH Date: Sat, 9 Dec 2023 16:18:11 +0900 Subject: [PATCH 2/2] :white_check_mark: Fixed testcase --- .../speechbuddy/viewmodel/BackupSettingsViewModelTest.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/app/src/test/java/com/example/speechbuddy/viewmodel/BackupSettingsViewModelTest.kt b/frontend/app/src/test/java/com/example/speechbuddy/viewmodel/BackupSettingsViewModelTest.kt index e279630e..572f19a7 100644 --- a/frontend/app/src/test/java/com/example/speechbuddy/viewmodel/BackupSettingsViewModelTest.kt +++ b/frontend/app/src/test/java/com/example/speechbuddy/viewmodel/BackupSettingsViewModelTest.kt @@ -112,7 +112,7 @@ class BackupSettingsViewModelTest { alert = BackupSettingsAlert.SUCCESS ) - assertEquals(expectedValue1, observedUiStates) + assertEquals(expectedValue1, observedUiStates[0]) coVerify { mockSettingsRepository.setLastBackupDate(date) } }