mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-27 12:53:55 +01:00
Feature/refactor contributions (#3046)
* * Refactored ContributionsListFragment to use RecyclerView * Added ContributionsPresenter * Extracted out the cursor to presenter * Probable fix for #3028 * Improved the logic for cache in ContributionViewHolder * Some more refactoring * While displaying images in ContributionsList, check if status is not completed && local uri exists, use that uri to show image * typo correction in LocalDataSource * Fixed formatting in ContributionsPresenter * retain adapter position when orientation changes * retain child position with its id * Made ContributionViewHolder not implement ViewHolder * Code formatting, review suggested changes * initialise the rv layout managers only when needed * added test cases for ContributionPresenter * removed not needed semi colon * added more java docs and code formatting
This commit is contained in:
parent
108e28c89a
commit
60b1eb1957
22 changed files with 814 additions and 592 deletions
|
|
@ -0,0 +1,110 @@
|
|||
package fr.free.nrw.commons.contributions
|
||||
|
||||
import android.database.Cursor
|
||||
import androidx.loader.content.CursorLoader
|
||||
import androidx.loader.content.Loader
|
||||
import com.nhaarman.mockito_kotlin.verify
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import org.mockito.Mock
|
||||
import org.mockito.Mockito
|
||||
import org.mockito.MockitoAnnotations
|
||||
|
||||
/**
|
||||
* The unit test class for ContributionsPresenter
|
||||
*/
|
||||
class ContributionsPresenterTest {
|
||||
@Mock
|
||||
internal var repository: ContributionsRepository? = null
|
||||
@Mock
|
||||
internal var view: ContributionsContract.View? = null
|
||||
|
||||
private var contributionsPresenter: ContributionsPresenter? = null
|
||||
|
||||
private lateinit var cursor: Cursor
|
||||
|
||||
lateinit var contribution: Contribution
|
||||
|
||||
lateinit var loader: Loader<Cursor>
|
||||
|
||||
/**
|
||||
* initial setup
|
||||
*/
|
||||
@Before
|
||||
@Throws(Exception::class)
|
||||
fun setUp() {
|
||||
MockitoAnnotations.initMocks(this)
|
||||
cursor = Mockito.mock(Cursor::class.java)
|
||||
contribution = Mockito.mock(Contribution::class.java)
|
||||
contributionsPresenter = ContributionsPresenter(repository)
|
||||
loader = Mockito.mock(CursorLoader::class.java)
|
||||
contributionsPresenter?.onAttachView(view)
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Test presenter actions onGetContributionFromCursor
|
||||
*/
|
||||
@Test
|
||||
fun testGetContributionFromCursor() {
|
||||
contributionsPresenter?.getContributionsFromCursor(cursor)
|
||||
verify(repository)?.getContributionFromCursor(cursor)
|
||||
}
|
||||
|
||||
/**
|
||||
* Test presenter actions onDeleteContribution
|
||||
*/
|
||||
@Test
|
||||
fun testDeleteContribution() {
|
||||
contributionsPresenter?.deleteUpload(contribution)
|
||||
verify(repository)?.deleteContributionFromDB(contribution)
|
||||
}
|
||||
|
||||
/**
|
||||
* Test presenter actions on loaderFinished and has non zero media objects
|
||||
*/
|
||||
@Test
|
||||
fun testOnLoaderFinishedNonZeroContributions() {
|
||||
Mockito.`when`(cursor.count).thenReturn(1)
|
||||
contributionsPresenter?.onLoadFinished(loader, cursor)
|
||||
verify(view)?.showProgress(false)
|
||||
verify(view)?.showWelcomeTip(false)
|
||||
verify(view)?.showNoContributionsUI(false)
|
||||
verify(view)?.setUploadCount(cursor.count)
|
||||
}
|
||||
|
||||
/**
|
||||
* Test presenter actions on loaderFinished and has Zero media objects
|
||||
*/
|
||||
@Test
|
||||
fun testOnLoaderFinishedZeroContributions() {
|
||||
Mockito.`when`(cursor.count).thenReturn(0)
|
||||
contributionsPresenter?.onLoadFinished(loader, cursor)
|
||||
verify(view)?.showProgress(false)
|
||||
verify(view)?.showWelcomeTip(true)
|
||||
verify(view)?.showNoContributionsUI(true)
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Test presenter actions on loader reset
|
||||
*/
|
||||
@Test
|
||||
fun testOnLoaderReset() {
|
||||
contributionsPresenter?.onLoaderReset(loader)
|
||||
verify(view)?.showProgress(false)
|
||||
verify(view)?.showWelcomeTip(true)
|
||||
verify(view)?.showNoContributionsUI(true)
|
||||
}
|
||||
|
||||
/**
|
||||
* Test presenter actions on loader change
|
||||
*/
|
||||
@Test
|
||||
fun testOnChanged() {
|
||||
contributionsPresenter?.onChanged()
|
||||
verify(view)?.onDataSetChanged()
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue