mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-27 12:53:55 +01:00
Migrated Contributions Package From Butterknife to ViewBinding (#5593)
* Butterknife to ViewBinding * code fix to pass all tests * test fix * test fix * test fix * test fix * Update ContributionsFragmentUnitTests.kt * code cleanup and tests improved * tests fixed * adjustments and code cleanup * adjustments and code cleanup
This commit is contained in:
parent
2076bf9b29
commit
c94f607107
7 changed files with 127 additions and 190 deletions
|
|
@ -16,6 +16,7 @@ import fr.free.nrw.commons.Media
|
|||
import fr.free.nrw.commons.R
|
||||
import fr.free.nrw.commons.TestCommonsApplication
|
||||
import fr.free.nrw.commons.TestUtility.setFinalStatic
|
||||
import fr.free.nrw.commons.databinding.LayoutContributionBinding
|
||||
import fr.free.nrw.commons.media.MediaClient
|
||||
import fr.free.nrw.commons.profile.ProfileActivity
|
||||
import io.reactivex.disposables.CompositeDisposable
|
||||
|
|
@ -46,17 +47,6 @@ class ContributionViewHolderUnitTests {
|
|||
private lateinit var contributionViewHolder: ContributionViewHolder
|
||||
private lateinit var activity: ProfileActivity
|
||||
private lateinit var parent: View
|
||||
private lateinit var pauseResumeButton: ImageButton
|
||||
private lateinit var addToWikipediaButton: ImageButton
|
||||
private lateinit var cancelButton: ImageButton
|
||||
private lateinit var retryButton: ImageButton
|
||||
private lateinit var imageOptions: RelativeLayout
|
||||
private lateinit var imageView: SimpleDraweeView
|
||||
private lateinit var titleView: TextView
|
||||
private lateinit var authorView: TextView
|
||||
private lateinit var stateView: TextView
|
||||
private lateinit var seqNumView: TextView
|
||||
private lateinit var progressView: ProgressBar
|
||||
|
||||
@Mock
|
||||
private lateinit var callback: ContributionsListAdapter.Callback
|
||||
|
|
@ -76,6 +66,8 @@ class ContributionViewHolderUnitTests {
|
|||
@Mock
|
||||
private lateinit var media: Media
|
||||
|
||||
private lateinit var bindind : LayoutContributionBinding
|
||||
|
||||
@Before
|
||||
fun setUp() {
|
||||
MockitoAnnotations.initMocks(this)
|
||||
|
|
@ -85,42 +77,10 @@ class ContributionViewHolderUnitTests {
|
|||
parent = LayoutInflater.from(activity).inflate(R.layout.layout_contribution, null)
|
||||
contributionViewHolder = ContributionViewHolder(parent, callback, mediaClient)
|
||||
|
||||
pauseResumeButton = parent.findViewById(R.id.pauseResumeButton)
|
||||
Whitebox.setInternalState(contributionViewHolder, "pauseResumeButton", pauseResumeButton)
|
||||
bindind = LayoutContributionBinding.bind(parent)
|
||||
|
||||
addToWikipediaButton = parent.findViewById(R.id.wikipediaButton)
|
||||
Whitebox.setInternalState(
|
||||
contributionViewHolder,
|
||||
"addToWikipediaButton",
|
||||
addToWikipediaButton
|
||||
)
|
||||
Whitebox.setInternalState(contributionViewHolder, "binding", bindind)
|
||||
|
||||
cancelButton = parent.findViewById(R.id.cancelButton)
|
||||
Whitebox.setInternalState(contributionViewHolder, "cancelButton", cancelButton)
|
||||
|
||||
retryButton = parent.findViewById(R.id.retryButton)
|
||||
Whitebox.setInternalState(contributionViewHolder, "retryButton", retryButton)
|
||||
|
||||
imageOptions = parent.findViewById(R.id.image_options)
|
||||
Whitebox.setInternalState(contributionViewHolder, "imageOptions", imageOptions)
|
||||
|
||||
imageView = parent.findViewById(R.id.contributionImage)
|
||||
Whitebox.setInternalState(contributionViewHolder, "imageView", imageView)
|
||||
|
||||
titleView = parent.findViewById(R.id.contributionTitle)
|
||||
Whitebox.setInternalState(contributionViewHolder, "titleView", titleView)
|
||||
|
||||
authorView = parent.findViewById(R.id.authorView)
|
||||
Whitebox.setInternalState(contributionViewHolder, "authorView", authorView)
|
||||
|
||||
stateView = parent.findViewById(R.id.contributionState)
|
||||
Whitebox.setInternalState(contributionViewHolder, "stateView", stateView)
|
||||
|
||||
seqNumView = parent.findViewById(R.id.contributionSequenceNumber)
|
||||
Whitebox.setInternalState(contributionViewHolder, "seqNumView", seqNumView)
|
||||
|
||||
progressView = parent.findViewById(R.id.contributionProgress)
|
||||
Whitebox.setInternalState(contributionViewHolder, "progressView", progressView)
|
||||
setFinalStatic(
|
||||
ContributionViewHolder::class.java.getDeclaredField("compositeDisposable"),
|
||||
compositeDisposable)
|
||||
|
|
@ -185,7 +145,7 @@ class ContributionViewHolderUnitTests {
|
|||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testOnPauseResumeButtonClickedCaseFalse() {
|
||||
pauseResumeButton.tag = ""
|
||||
bindind.pauseResumeButton.tag = ""
|
||||
contributionViewHolder.onPauseResumeButtonClicked()
|
||||
}
|
||||
|
||||
|
|
@ -356,4 +316,4 @@ class ContributionViewHolderUnitTests {
|
|||
contributionViewHolder.init(0, contribution)
|
||||
Assert.assertNotNull(contributionViewHolder.imageRequest)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ import fr.free.nrw.commons.TestCommonsApplication
|
|||
import fr.free.nrw.commons.createTestClient
|
||||
import fr.free.nrw.commons.campaigns.CampaignView
|
||||
import fr.free.nrw.commons.campaigns.models.Campaign
|
||||
import fr.free.nrw.commons.databinding.FragmentContributionsBinding
|
||||
import fr.free.nrw.commons.kvstore.JsonKvStore
|
||||
import fr.free.nrw.commons.media.MediaDetailPagerFragment
|
||||
import fr.free.nrw.commons.mwapi.OkHttpJsonApiClient
|
||||
|
|
@ -120,21 +121,10 @@ class ContributionsFragmentUnitTests {
|
|||
|
||||
Whitebox.setInternalState(fragment, "contributionsListFragment", contributionsListFragment)
|
||||
Whitebox.setInternalState(fragment, "store", store)
|
||||
Whitebox.setInternalState(
|
||||
fragment,
|
||||
"limitedConnectionEnabledLayout",
|
||||
limitedConnectionEnabledLayout
|
||||
)
|
||||
Whitebox.setInternalState(fragment, "notificationCount", notificationCount)
|
||||
Whitebox.setInternalState(fragment, "notificationController", notificationController)
|
||||
Whitebox.setInternalState(fragment, "compositeDisposable", compositeDisposable)
|
||||
Whitebox.setInternalState(fragment, "okHttpJsonApiClient", okHttpJsonApiClient)
|
||||
Whitebox.setInternalState(
|
||||
fragment,
|
||||
"nearbyNotificationCardView",
|
||||
nearbyNotificationCardView
|
||||
)
|
||||
Whitebox.setInternalState(fragment, "campaignView", campaignView)
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -360,4 +350,4 @@ class ContributionsFragmentUnitTests {
|
|||
fragment.showDetail(0, false)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue