Skip to content

Commit

Permalink
Merge pull request #74 from TheTeamPotato/task/refactor-code-before-i…
Browse files Browse the repository at this point in the history
…nitial-release

Task/refactor code before initial release
  • Loading branch information
isoguzay authored Mar 21, 2022
2 parents b4d8326 + 3515d36 commit 78e13b6
Show file tree
Hide file tree
Showing 21 changed files with 40 additions and 266 deletions.
22 changes: 7 additions & 15 deletions buildSrc/src/main/kotlin/Dependencies.kt
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,7 @@ object Libraries {

object Coroutines {
private const val COROUTINES_ANDROID_VERSION = "1.6.0"

object Test {
const val TEST =
"org.jetbrains.kotlinx:kotlinx-coroutines-test:$COROUTINES_ANDROID_VERSION"
}
const val TEST = "org.jetbrains.kotlinx:kotlinx-coroutines-test:$COROUTINES_ANDROID_VERSION"
}
}

Expand Down Expand Up @@ -188,10 +184,6 @@ object Libraries {

// Internal Libraries
val DependencyHandler.TESTING
//get() = androidTestImplementation(project(Modules.TESTING))
get() = implementation(project(Modules.TESTING))

val DependencyHandler.TESTING_IMPL
get() = implementation(project(Modules.TESTING))

fun DependencyHandler.testing() {
Expand Down Expand Up @@ -362,15 +354,15 @@ private fun DependencyHandler.test() {
}

fun DependencyHandler.androidInstrumentationTest() {
testImplementation(Libraries.Test.AndroidX.ARCH)
testImplementation(Libraries.Test.AndroidX.CORE)
testImplementation(Libraries.Test.AndroidX.JUNIT_KTX)
testImplementation(Libraries.Test.AndroidX.JUNIT_RUNNER)
testImplementation(Libraries.Test.AndroidX.JUNIT_RULES)
androidTestImplementation(Libraries.Test.AndroidX.ARCH)
androidTestImplementation(Libraries.Test.AndroidX.CORE)
androidTestImplementation(Libraries.Test.AndroidX.JUNIT_KTX)
androidTestImplementation(Libraries.Test.AndroidX.JUNIT_RUNNER)
androidTestImplementation(Libraries.Test.AndroidX.JUNIT_RULES)
}

private fun DependencyHandler.coroutinesTest() {
androidTestImplementation(Libraries.Kotlin.Coroutines.Test.TEST)
androidTestImplementation(Libraries.Kotlin.Coroutines.TEST)
}

fun DependencyHandler.hiltTest() {
Expand Down
4 changes: 2 additions & 2 deletions features/favorites/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ dependencies {
LOCAL_TEST
TESTING

testImplementation(project(Modules.TESTING))
testImplementation(Libraries.Kotlin.Coroutines.Test.TEST)
//MODULE_TESTING
//testImplementation(Libraries.Kotlin.Coroutines.TEST)
}

kapt {
Expand Down
3 changes: 0 additions & 3 deletions features/history/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,6 @@ dependencies {
DAGGER_HILT_ANDROID_TEST
LOCAL_TEST
TESTING

testImplementation(project(Modules.TESTING))
testImplementation(Libraries.Kotlin.Coroutines.Test.TEST)
}

kapt {
Expand Down
3 changes: 0 additions & 3 deletions features/language-selection/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,6 @@ dependencies {
DAGGER_HILT_ANDROID_TEST
LOCAL_TEST
TESTING

testImplementation(project(Modules.TESTING))
testImplementation(Libraries.Kotlin.Coroutines.Test.TEST)
}

kapt {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@ package com.theteampotato.gifit.language_selection.viewmodel

import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope

import com.theteampotato.gifit.domain.usecase.DownloadTranslationModel
import com.theteampotato.gifit.domain.usecase.SetSelectedLanguage

import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.launch

import java.lang.Exception
import javax.inject.Inject

import kotlinx.coroutines.launch

@HiltViewModel
class LanguageSelectionViewModel @Inject constructor(
private val downloadTranslationModel: DownloadTranslationModel,
Expand Down
4 changes: 0 additions & 4 deletions features/search/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,6 @@ dependencies {
DAGGER_HILT_ANDROID_TEST
LOCAL_TEST
TESTING

testImplementation(project(Modules.TESTING))
testImplementation(Libraries.Kotlin.Coroutines.Test.TEST)
TURBINE
}

kapt {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,17 @@
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
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
Expand All @@ -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

Expand All @@ -52,7 +49,9 @@ class SearchScreenTest {
addSearchResultToFavorites = addSearchResultToFavorites,
getSearchResult = getSearchResult,
isSearchResultExist = isSearchResultExist,
removeSearchResultFromFavorites = removeSearchResultFromFavorites
removeSearchResultFromFavorites = removeSearchResultFromFavorites,
translateText = translateText,
readText = readText
)

composeTestRule.setContent {
Expand All @@ -73,10 +72,7 @@ class SearchScreenTest {
val givenValue = "Ofis"
val expectedValue = "Office"

//composeTestRule.o

searchViewModel.searchKeyword(givenValue)
//searchViewModel.mSearchResultLiveData.getOrAwaitValue()

composeTestRule.onNodeWithText(expectedValue).assertIsDisplayed()
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@ package com.theteampotato.gifit.splash.viewmodel

import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope

import com.theteampotato.gifit.domain.usecase.GetSelectedLanguage

import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.withContext

import javax.inject.Inject

import kotlinx.coroutines.withContext

@HiltViewModel
class SplashViewModel @Inject constructor(
private val getSelectedLanguage: GetSelectedLanguage
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,31 +25,31 @@ class SearchResultEntityDaoTest : GIFitRoomDatabaseTest() {
var instantTaskExecutorRule = InstantTaskExecutorRule()

private lateinit var searchResultDao: SearchResultDao
private lateinit var SearchResultEntity: SearchResultEntity
private lateinit var searchResultEntity: SearchResultEntity
private lateinit var listOfResultEntities: List<SearchResultEntity>

@Before
fun init() = runBlocking {
searchResultDao = database.searchResultDao()
SearchResultEntity = TestUtil.newSearch()
searchResultEntity = TestUtil.newSearch()
listOfResultEntities = TestUtil.newListOfSearch()
}

@Test
fun verify_inserted_testData_then_searchString_entity_should_be_equalTo_searchResult_searchString(): Unit = runBlocking {
searchResultDao.insert(SearchResultEntity)
searchResultDao.insert(searchResultEntity)
val results = searchResultDao.getAll().getOrAwaitValue()
assertThat(results[0].searchText).isEqualTo(SearchResultEntity.searchText)
assertThat(results[0].searchText).isEqualTo(searchResultEntity.searchText)
}

@Test
fun verify_deleted_testData_then_check_searchString_should_be_contain(): Unit = runBlocking {
searchResultDao.insertAll(listOfResultEntities)
searchResultDao.insert(SearchResultEntity)
searchResultDao.insert(searchResultEntity)
val result = searchResultDao.getResultById(2).getOrAwaitValue()
searchResultDao.delete(result)
val results = searchResultDao.getAll().getOrAwaitValue()
assertThat(results[2].searchText).contains(SearchResultEntity.searchText)
assertThat(results[2].searchText).contains(searchResultEntity.searchText)
}

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.theteampotato.gifit.data.local.repository
package com.theteampotato.gifit.data.local

import androidx.lifecycle.LiveData

interface BaseLocalRepository<T> {
interface ILocalOperations<T> {

suspend fun insert(entity : T) : Long

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ interface SearchResultDao : BaseDao<SearchResultEntity> {
fun getResultById(id: Int): LiveData<SearchResultEntity>

@Query("SELECT * FROM SearchResult WHERE id = :id and isFavorite = 1")
fun getFavoritesResultById(id: Int): LiveData<SearchResultEntity>
fun getFavoritesResultById(id: Int): Flow<SearchResultEntity>

@Query("SELECT * FROM SearchResult WHERE isFavorite = 1")
fun getAllFavoritesResults(): Flow<List<SearchResultEntity>>
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.theteampotato.gifit.data.local.datasource

import androidx.lifecycle.LiveData
import com.theteampotato.gifit.data.local.ILocalOperations

import com.theteampotato.gifit.data.local.dao.SearchResultDao
import com.theteampotato.gifit.data.local.entity.SearchResultEntity
Expand All @@ -11,7 +12,7 @@ import kotlinx.coroutines.flow.Flow

class LocalDataSource @Inject constructor(
private val searchResultDao: SearchResultDao
) : ILocalDataSource<SearchResultEntity> {
) : ILocalOperations<SearchResultEntity> {

override suspend fun insert(SearchResultEntity: SearchResultEntity) =
searchResultDao.insert(SearchResultEntity)
Expand All @@ -36,10 +37,6 @@ class LocalDataSource @Inject constructor(
return searchResultDao.getAll()
}

fun getFavoritesResultById(id: Int): LiveData<SearchResultEntity> {
return searchResultDao.getFavoritesResultById(id)
}

fun getAllFavoritesResults() = searchResultDao.getAllFavoritesResults()

fun favoriteLastSearchResult(id: Long) {
Expand Down
Loading

0 comments on commit 78e13b6

Please sign in to comment.