From dad2260ea21e5bb2e45038c8b2cb01f1ee64508c Mon Sep 17 00:00:00 2001 From: Ammar Githam Date: Sat, 12 Jun 2021 12:43:15 +0900 Subject: [PATCH] Add GraphQLRepository to ProfileFragmentViewModel constructor --- .../fragments/main/ProfileFragment.java | 1 + .../viewmodels/ProfileFragmentViewModel.kt | 8 ++--- .../ProfileFragmentViewModelTest.kt | 36 ++++++++++++++----- 3 files changed, 32 insertions(+), 13 deletions(-) diff --git a/app/src/main/java/awais/instagrabber/fragments/main/ProfileFragment.java b/app/src/main/java/awais/instagrabber/fragments/main/ProfileFragment.java index 85b2c908..b1f239e2 100644 --- a/app/src/main/java/awais/instagrabber/fragments/main/ProfileFragment.java +++ b/app/src/main/java/awais/instagrabber/fragments/main/ProfileFragment.java @@ -349,6 +349,7 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe FriendshipRepository.Companion.getInstance(), StoriesRepository.Companion.getInstance(), MediaRepository.Companion.getInstance(), + GraphQLRepository.Companion.getInstance(), this, getArguments() )).get(ProfileFragmentViewModel.class); diff --git a/app/src/main/java/awais/instagrabber/viewmodels/ProfileFragmentViewModel.kt b/app/src/main/java/awais/instagrabber/viewmodels/ProfileFragmentViewModel.kt index 65ca2ef8..5234767c 100644 --- a/app/src/main/java/awais/instagrabber/viewmodels/ProfileFragmentViewModel.kt +++ b/app/src/main/java/awais/instagrabber/viewmodels/ProfileFragmentViewModel.kt @@ -6,10 +6,7 @@ import androidx.lifecycle.* import androidx.savedstate.SavedStateRegistryOwner import awais.instagrabber.repositories.responses.User import awais.instagrabber.utils.extensions.TAG -import awais.instagrabber.webservices.FriendshipRepository -import awais.instagrabber.webservices.MediaRepository -import awais.instagrabber.webservices.StoriesRepository -import awais.instagrabber.webservices.UserRepository +import awais.instagrabber.webservices.* class ProfileFragmentViewModel( state: SavedStateHandle, @@ -17,6 +14,7 @@ class ProfileFragmentViewModel( friendshipRepository: FriendshipRepository, storiesRepository: StoriesRepository, mediaRepository: MediaRepository, + graphQLRepository: GraphQLRepository, ) : ViewModel() { private val _profile = MutableLiveData() val profile: LiveData = _profile @@ -38,6 +36,7 @@ class ProfileFragmentViewModelFactory( private val friendshipRepository: FriendshipRepository, private val storiesRepository: StoriesRepository, private val mediaRepository: MediaRepository, + private val graphQLRepository: GraphQLRepository, owner: SavedStateRegistryOwner, defaultArgs: Bundle? = null, ) : AbstractSavedStateViewModelFactory(owner, defaultArgs) { @@ -52,6 +51,7 @@ class ProfileFragmentViewModelFactory( friendshipRepository, storiesRepository, mediaRepository, + graphQLRepository, ) as T } } diff --git a/app/src/test/java/awais/instagrabber/viewmodels/ProfileFragmentViewModelTest.kt b/app/src/test/java/awais/instagrabber/viewmodels/ProfileFragmentViewModelTest.kt index d4523ad4..5fe63921 100644 --- a/app/src/test/java/awais/instagrabber/viewmodels/ProfileFragmentViewModelTest.kt +++ b/app/src/test/java/awais/instagrabber/viewmodels/ProfileFragmentViewModelTest.kt @@ -2,15 +2,9 @@ package awais.instagrabber.viewmodels import androidx.lifecycle.SavedStateHandle import androidx.test.ext.junit.runners.AndroidJUnit4 -import awais.instagrabber.repositories.FriendshipService -import awais.instagrabber.repositories.MediaService -import awais.instagrabber.repositories.StoriesService -import awais.instagrabber.repositories.UserService +import awais.instagrabber.repositories.* import awais.instagrabber.repositories.responses.* -import awais.instagrabber.webservices.FriendshipRepository -import awais.instagrabber.webservices.MediaRepository -import awais.instagrabber.webservices.StoriesRepository -import awais.instagrabber.webservices.UserRepository +import awais.instagrabber.webservices.* import org.junit.Test import org.junit.runner.RunWith @@ -116,6 +110,28 @@ internal class ProfileFragmentViewModelTest { } } + private val graphQLService = object : GraphQLService { + override suspend fun fetch(queryParams: Map): String { + TODO("Not yet implemented") + } + + override suspend fun getUser(username: String): String { + TODO("Not yet implemented") + } + + override suspend fun getPost(shortcode: String): String { + TODO("Not yet implemented") + } + + override suspend fun getTag(tag: String): String { + TODO("Not yet implemented") + } + + override suspend fun getLocation(locationId: Long): String { + TODO("Not yet implemented") + } + } + @Test fun testNoUsernameNoCurrentUser() { val state = SavedStateHandle( @@ -127,12 +143,14 @@ internal class ProfileFragmentViewModelTest { val friendshipRepository = FriendshipRepository(friendshipService) val storiesRepository = StoriesRepository(storiesService) val mediaRepository = MediaRepository(mediaService) + val graphQLRepository = GraphQLRepository(graphQLService) val viewModel = ProfileFragmentViewModel( state, userRepository, friendshipRepository, storiesRepository, - mediaRepository + mediaRepository, + graphQLRepository, ) } } \ No newline at end of file