mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-27 04:43:54 +01:00
[Fixes Bug]: After moving between tabs on Bookmark fragment, Bookmarks never loads (#4951)
* Fixed the issue added tests * Added requested changes
This commit is contained in:
parent
932991e060
commit
a16dca9f56
2 changed files with 40 additions and 7 deletions
|
|
@ -188,6 +188,10 @@ public class BookmarkPicturesFragment extends DaggerFragment {
|
||||||
setAdapter(collection);
|
setAdapter(collection);
|
||||||
} else {
|
} else {
|
||||||
if (gridAdapter.containsAll(collection)) {
|
if (gridAdapter.containsAll(collection)) {
|
||||||
|
progressBar.setVisibility(GONE);
|
||||||
|
statusTextView.setVisibility(GONE);
|
||||||
|
gridView.setVisibility(VISIBLE);
|
||||||
|
gridView.setAdapter(gridAdapter);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
gridAdapter.addItems(collection);
|
gridAdapter.addItems(collection);
|
||||||
|
|
|
||||||
|
|
@ -6,12 +6,17 @@ import android.os.Bundle
|
||||||
import android.os.Looper.getMainLooper
|
import android.os.Looper.getMainLooper
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.View
|
import android.view.View
|
||||||
|
import android.view.View.GONE
|
||||||
|
import android.view.View.VISIBLE
|
||||||
import android.widget.GridView
|
import android.widget.GridView
|
||||||
import android.widget.ProgressBar
|
import android.widget.ProgressBar
|
||||||
import android.widget.RelativeLayout
|
import android.widget.RelativeLayout
|
||||||
import android.widget.TextView
|
import android.widget.TextView
|
||||||
import androidx.fragment.app.FragmentManager
|
import androidx.fragment.app.FragmentManager
|
||||||
import androidx.fragment.app.FragmentTransaction
|
import androidx.fragment.app.FragmentTransaction
|
||||||
|
import com.nhaarman.mockitokotlin2.any
|
||||||
|
import com.nhaarman.mockitokotlin2.times
|
||||||
|
import com.nhaarman.mockitokotlin2.verify
|
||||||
import fr.free.nrw.commons.Media
|
import fr.free.nrw.commons.Media
|
||||||
import fr.free.nrw.commons.R
|
import fr.free.nrw.commons.R
|
||||||
import fr.free.nrw.commons.TestAppAdapter
|
import fr.free.nrw.commons.TestAppAdapter
|
||||||
|
|
@ -19,6 +24,7 @@ import fr.free.nrw.commons.TestCommonsApplication
|
||||||
import fr.free.nrw.commons.category.GridViewAdapter
|
import fr.free.nrw.commons.category.GridViewAdapter
|
||||||
import fr.free.nrw.commons.media.MediaClient
|
import fr.free.nrw.commons.media.MediaClient
|
||||||
import fr.free.nrw.commons.profile.ProfileActivity
|
import fr.free.nrw.commons.profile.ProfileActivity
|
||||||
|
import media
|
||||||
import org.junit.Assert
|
import org.junit.Assert
|
||||||
import org.junit.Before
|
import org.junit.Before
|
||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
|
|
@ -46,9 +52,15 @@ class BookmarkPicturesFragmentUnitTests {
|
||||||
private lateinit var context: Context
|
private lateinit var context: Context
|
||||||
|
|
||||||
private lateinit var view: View
|
private lateinit var view: View
|
||||||
private lateinit var statusTextView: TextView
|
|
||||||
private lateinit var progressBar: ProgressBar
|
@Mock
|
||||||
private lateinit var gridView: GridView
|
lateinit var statusTextView: TextView
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
lateinit var progressBar: ProgressBar
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
lateinit var gridView: GridView
|
||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
private lateinit var parentLayout: RelativeLayout
|
private lateinit var parentLayout: RelativeLayout
|
||||||
|
|
@ -87,9 +99,6 @@ class BookmarkPicturesFragmentUnitTests {
|
||||||
|
|
||||||
view = LayoutInflater.from(activity)
|
view = LayoutInflater.from(activity)
|
||||||
.inflate(R.layout.fragment_bookmarks_pictures, null) as View
|
.inflate(R.layout.fragment_bookmarks_pictures, null) as View
|
||||||
statusTextView = view.findViewById(R.id.statusMessage)
|
|
||||||
progressBar = view.findViewById(R.id.loadingImagesProgressBar)
|
|
||||||
gridView = view.findViewById(R.id.bookmarkedPicturesList)
|
|
||||||
|
|
||||||
fragment.statusTextView = statusTextView
|
fragment.statusTextView = statusTextView
|
||||||
fragment.progressBar = progressBar
|
fragment.progressBar = progressBar
|
||||||
|
|
@ -102,7 +111,11 @@ class BookmarkPicturesFragmentUnitTests {
|
||||||
|
|
||||||
fragment.controller = controller
|
fragment.controller = controller
|
||||||
|
|
||||||
Whitebox.setInternalState(fragment, "gridAdapter", gridAdapter)
|
Whitebox.setInternalState(fragment, "gridAdapter", GridViewAdapter(
|
||||||
|
context,
|
||||||
|
0,
|
||||||
|
listOf(media())
|
||||||
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
@ -171,6 +184,22 @@ class BookmarkPicturesFragmentUnitTests {
|
||||||
method.invoke(fragment, throwable)
|
method.invoke(fragment, throwable)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Throws(Exception::class)
|
||||||
|
fun testHandleSuccess() {
|
||||||
|
gridAdapter.addItems(listOf(media()))
|
||||||
|
val method: Method = BookmarkPicturesFragment::class.java.getDeclaredMethod(
|
||||||
|
"handleSuccess",
|
||||||
|
List::class.java
|
||||||
|
)
|
||||||
|
method.isAccessible = true
|
||||||
|
method.invoke(fragment, listOf(media()))
|
||||||
|
verify(progressBar, times(1)).setVisibility(GONE)
|
||||||
|
verify(statusTextView, times(1)).setVisibility(GONE)
|
||||||
|
verify(gridView, times(1)).setVisibility(VISIBLE)
|
||||||
|
verify(gridView, times(1)).setAdapter(any())
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Throws(Exception::class)
|
@Throws(Exception::class)
|
||||||
fun testInitErrorView() {
|
fun testInitErrorView() {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue