Browse Source

Add MediaRepository to ProfileFragmentViewModel constructor

renovate/org.robolectric-robolectric-4.x
Ammar Githam 4 years ago
parent
commit
2a0295e325
  1. 1
      app/src/main/java/awais/instagrabber/fragments/main/ProfileFragment.java
  2. 8
      app/src/main/java/awais/instagrabber/viewmodels/ProfileFragmentViewModel.kt
  3. 47
      app/src/test/java/awais/instagrabber/viewmodels/ProfileFragmentViewModelTest.kt

1
app/src/main/java/awais/instagrabber/fragments/main/ProfileFragment.java

@ -348,6 +348,7 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe
UserRepository.Companion.getInstance(),
FriendshipRepository.Companion.getInstance(),
StoriesRepository.Companion.getInstance(),
MediaRepository.Companion.getInstance(),
this,
getArguments()
)).get(ProfileFragmentViewModel.class);

8
app/src/main/java/awais/instagrabber/viewmodels/ProfileFragmentViewModel.kt

@ -7,6 +7,7 @@ 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
@ -15,6 +16,7 @@ class ProfileFragmentViewModel(
userRepository: UserRepository,
friendshipRepository: FriendshipRepository,
storiesRepository: StoriesRepository,
mediaRepository: MediaRepository,
) : ViewModel() {
private val _profile = MutableLiveData<User?>()
val profile: LiveData<User?> = _profile
@ -26,7 +28,7 @@ class ProfileFragmentViewModel(
private set
init {
Log.d(TAG, "${state.keys()} $userRepository $friendshipRepository $storiesRepository")
Log.d(TAG, "${state.keys()} $userRepository $friendshipRepository $storiesRepository $mediaRepository")
}
}
@ -35,6 +37,7 @@ class ProfileFragmentViewModelFactory(
private val userRepository: UserRepository,
private val friendshipRepository: FriendshipRepository,
private val storiesRepository: StoriesRepository,
private val mediaRepository: MediaRepository,
owner: SavedStateRegistryOwner,
defaultArgs: Bundle? = null,
) : AbstractSavedStateViewModelFactory(owner, defaultArgs) {
@ -47,7 +50,8 @@ class ProfileFragmentViewModelFactory(
handle,
userRepository,
friendshipRepository,
storiesRepository
storiesRepository,
mediaRepository,
) as T
}
}

47
app/src/test/java/awais/instagrabber/viewmodels/ProfileFragmentViewModelTest.kt

@ -3,10 +3,12 @@ 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.responses.*
import awais.instagrabber.webservices.FriendshipRepository
import awais.instagrabber.webservices.MediaRepository
import awais.instagrabber.webservices.StoriesRepository
import awais.instagrabber.webservices.UserRepository
import org.junit.Test
@ -50,7 +52,7 @@ internal class ProfileFragmentViewModelTest {
}
}
private val storiesService = object: StoriesService {
private val storiesService = object : StoriesService {
override suspend fun fetch(mediaId: Long): String {
TODO("Not yet implemented")
}
@ -80,6 +82,40 @@ internal class ProfileFragmentViewModelTest {
}
}
private val mediaService = object : MediaService {
override suspend fun fetch(mediaId: Long): MediaInfoResponse {
TODO("Not yet implemented")
}
override suspend fun fetchLikes(mediaId: String, action: String): LikersResponse {
TODO("Not yet implemented")
}
override suspend fun action(action: String, mediaId: String, signedForm: Map<String, String>): String {
TODO("Not yet implemented")
}
override suspend fun editCaption(mediaId: String, signedForm: Map<String, String>): String {
TODO("Not yet implemented")
}
override suspend fun translate(form: Map<String, String>): String {
TODO("Not yet implemented")
}
override suspend fun uploadFinish(retryContext: String, queryParams: Map<String, String>, signedForm: Map<String, String>): String {
TODO("Not yet implemented")
}
override suspend fun delete(mediaId: String, mediaType: String, signedForm: Map<String, String>): String {
TODO("Not yet implemented")
}
override suspend fun archive(mediaId: String, signedForm: Map<String, String>): String {
TODO("Not yet implemented")
}
}
@Test
fun testNoUsernameNoCurrentUser() {
val state = SavedStateHandle(
@ -90,6 +126,13 @@ internal class ProfileFragmentViewModelTest {
val userRepository = UserRepository(userService)
val friendshipRepository = FriendshipRepository(friendshipService)
val storiesRepository = StoriesRepository(storiesService)
val viewModel = ProfileFragmentViewModel(state, userRepository, friendshipRepository, storiesRepository)
val mediaRepository = MediaRepository(mediaService)
val viewModel = ProfileFragmentViewModel(
state,
userRepository,
friendshipRepository,
storiesRepository,
mediaRepository
)
}
}
Loading…
Cancel
Save