diff --git a/features/search/build.gradle.kts b/features/search/build.gradle.kts index 4e73b0e..8372fea 100644 --- a/features/search/build.gradle.kts +++ b/features/search/build.gradle.kts @@ -43,8 +43,6 @@ dependencies { DAGGER_HILT_ANDROID_TEST LOCAL_TEST TESTING - - TURBINE } kapt { diff --git a/features/search/src/androidTest/java/com/theteampotato/gifit/home/view/SearchScreenTest.kt b/features/search/src/androidTest/java/com/theteampotato/gifit/home/view/SearchScreenTest.kt index 9c56b33..a6cf762 100644 --- a/features/search/src/androidTest/java/com/theteampotato/gifit/home/view/SearchScreenTest.kt +++ b/features/search/src/androidTest/java/com/theteampotato/gifit/home/view/SearchScreenTest.kt @@ -1,7 +1,5 @@ package com.theteampotato.gifit.home.view -import androidx.arch.core.executor.testing.InstantTaskExecutorRule -import androidx.compose.runtime.getValue import androidx.compose.ui.test.assertIsDisplayed import androidx.compose.ui.test.junit4.createComposeRule import androidx.compose.ui.test.onNodeWithText @@ -9,14 +7,11 @@ import com.theteampotato.gifit.domain.usecase.* import com.theteampotato.gifit.home.viewmodel.SearchViewModel import com.theteampotato.gifit.testing.DispatcherProvider -import com.theteampotato.gifit.testing.getOrAwaitValue import com.theteampotato.gifit.ui.GIFitTheme import dagger.hilt.android.testing.HiltAndroidRule import dagger.hilt.android.testing.HiltAndroidTest import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.test.StandardTestDispatcher -import kotlinx.coroutines.test.setMain import org.junit.Before import org.junit.Rule @@ -35,6 +30,8 @@ class SearchScreenTest { @Inject lateinit var isSearchResultExist: IsSearchResultExist @Inject lateinit var removeSearchResultFromFavorites: RemoveSearchResultFromFavorites @Inject lateinit var getSearchResult: GetSearchResult + @Inject lateinit var translateText: TranslateText + @Inject lateinit var readText: ReadText private lateinit var searchViewModel: SearchViewModel @@ -52,7 +49,9 @@ class SearchScreenTest { addSearchResultToFavorites = addSearchResultToFavorites, getSearchResult = getSearchResult, isSearchResultExist = isSearchResultExist, - removeSearchResultFromFavorites = removeSearchResultFromFavorites + removeSearchResultFromFavorites = removeSearchResultFromFavorites, + translateText = translateText, + readText = readText ) composeTestRule.setContent { @@ -73,10 +72,7 @@ class SearchScreenTest { val givenValue = "Ofis" val expectedValue = "Office" - //composeTestRule.o - searchViewModel.searchKeyword(givenValue) - //searchViewModel.mSearchResultLiveData.getOrAwaitValue() composeTestRule.onNodeWithText(expectedValue).assertIsDisplayed() } diff --git a/features/search/src/androidTest/java/com/theteampotato/gifit/home/viewmodel/SearchViewModelTest.kt b/features/search/src/androidTest/java/com/theteampotato/gifit/home/viewmodel/SearchViewModelTest.kt deleted file mode 100644 index e2249f7..0000000 --- a/features/search/src/androidTest/java/com/theteampotato/gifit/home/viewmodel/SearchViewModelTest.kt +++ /dev/null @@ -1,96 +0,0 @@ -package com.theteampotato.gifit.home.viewmodel - -import androidx.arch.core.executor.testing.InstantTaskExecutorRule -import app.cash.turbine.test - -import com.google.common.truth.Truth.assertThat -import com.theteampotato.gifit.domain.usecase.* - -import com.theteampotato.gifit.testing.DispatcherProvider - -import dagger.hilt.android.testing.HiltAndroidRule -import dagger.hilt.android.testing.HiltAndroidTest -import kotlinx.coroutines.* -import kotlinx.coroutines.test.StandardTestDispatcher - -import javax.inject.Inject - -import kotlinx.coroutines.test.runTest -import kotlinx.coroutines.test.setMain - -import org.junit.Before -import org.junit.Rule -import org.junit.Test -import timber.log.Timber - -import kotlin.time.Duration.Companion.seconds -import kotlin.time.ExperimentalTime - -@HiltAndroidTest -class SearchViewModelTest { - - @get:Rule - var hiltRule = HiltAndroidRule(this) - - @get:Rule - var instantTaskExecutorRule = InstantTaskExecutorRule() - - @Inject lateinit var addSearchResultEntry: AddSearchResultEntry - @Inject lateinit var addSearchResultToFavorites: AddSearchResultToFavorites - @Inject lateinit var isSearchResultExist: IsSearchResultExist - @Inject lateinit var removeSearchResultFromFavorites: RemoveSearchResultFromFavorites - @Inject lateinit var getSearchResult: GetSearchResult - - private lateinit var searchViewModel: SearchViewModel - - @Before - @OptIn(ExperimentalCoroutinesApi::class) - fun setup() { - hiltRule.inject() - - Dispatchers.setMain(StandardTestDispatcher()) - - searchViewModel = SearchViewModel( - dispatcherProvider = DispatcherProvider( - io = Dispatchers.Main, - ui = Dispatchers.Main, - default = Dispatchers.Main - ), - addSearchResultEntry = addSearchResultEntry, - addSearchResultToFavorites = addSearchResultToFavorites, - getSearchResult = getSearchResult, - isSearchResultExist = isSearchResultExist, - removeSearchResultFromFavorites = removeSearchResultFromFavorites - ) - } - - @Test - @OptIn(ExperimentalTime::class, ExperimentalCoroutinesApi::class) - fun keyword_should_return_expectedResult() = runTest { - val expectedResult = "School" - - searchViewModel.searchKeyword("Okul")?.test(timeout = 15.seconds) { - val searchResult = awaitItem() - val actualResult = searchResult?.translatedText - assertThat(actualResult).matches(expectedResult) - } - } - - @Test - @OptIn(ExperimentalTime::class, ExperimentalCoroutinesApi::class) - fun wrong_expected_result_does_not_match_with_actualResult() = runTest { - val expectedResult = "Student" - - searchViewModel.searchKeyword("Araba")?.test(timeout = 15.seconds) { - val searchResult = awaitItem() - val actualResult = searchResult?.translatedText - assertThat(actualResult).doesNotMatch(expectedResult) - } - } - - @Test - fun homeViewModel_is_not_null() { - assertThat(searchViewModel).isNotNull() - } - -} \ No newline at end of file