apps-android-commons/app/src/test/kotlin/ModelFunctions.kt
Seán Mac Gillicuddy 4b22583b60
#3780 Create media using a combination of Entities & MwQueryResult (#3786)
* #3468 Switch from RvRenderer to AdapterDelegates - replace SearchDepictionsRenderer

* #3468 Switch from RvRenderer to AdapterDelegates - replace UploadCategoryDepictionsRenderer

* #3468 Switch from RvRenderer to AdapterDelegates - update BaseAdapter to be easier to use

* #3468 Switch from RvRenderer to AdapterDelegates - replace SearchImagesRenderer

* #3468 Switch from RvRenderer to AdapterDelegates - replace SearchCategoriesRenderer

* #3468 Switch from RvRenderer to AdapterDelegates - replace NotificationRenderer

* #3468 Switch from RvRenderer to AdapterDelegates - replace UploadDepictsRenderer

* #3468 Switch from RvRenderer to AdapterDelegates - replace PlaceRenderer

* #3756 Convert SearchDepictionsFragment to use Pagination - convert SearchDepictionsFragment

* #3756 Convert SearchDepictionsFragment to use Pagination - fix presenter unit tests now that view is not nullable - fix Category prefix imports

* #3756 Convert SearchDepictionsFragment to use Pagination - test DataSource related classes

* #3756 Convert SearchDepictionsFragment to use Pagination - reset rx scheduler - ignore failing test

* #3760 Convert SearchCategoriesFragment to use Pagination - extract functionality of pagination to base classes - add category pagination

* #3772 Convert SearchImagesFragment to use Pagination  - convert SearchImagesFragment - tidy up showing the empty view - make search fragments show snackbar with appropriate text

* #3772 Convert SearchImagesFragment to use Pagination  - allow viewpager to load more data

* #3760 remove test that got re-added by merge

* #3760 remove duplicate dependency

* #3772 fix compilation

* #3780 Create media using a combination of Entities & MwQueryResult - construct media with an entity - move fields from media down to contribution - move dynamic fields outside of media - remove unused constructors - remove all unnecessary fetching of captions/descriptions - bump database version

* #3808 Construct media objects that depict an item id correctly - use generator to construct media for DepictedImages

* #3780 Create media using a combination of Entities & MwQueryResult - update wikicode to align with expected behaviour

* #3780 Create media using a combination of Entities & MwQueryResult - replace old site of thumbnail title with most relevant caption
2020-06-25 17:20:01 +10:00

120 lines
3.6 KiB
Kotlin

import com.nhaarman.mockitokotlin2.mock
import com.nhaarman.mockitokotlin2.whenever
import fr.free.nrw.commons.Media
import fr.free.nrw.commons.category.CategoryItem
import fr.free.nrw.commons.location.LatLng
import fr.free.nrw.commons.nearby.Label
import fr.free.nrw.commons.nearby.Place
import fr.free.nrw.commons.nearby.Sitelinks
import fr.free.nrw.commons.upload.structure.depictions.DepictedItem
import org.wikipedia.wikidata.*
import java.util.*
fun depictedItem(
name: String = "label",
description: String = "desc",
imageUrl: String = "",
instanceOfs: List<String> = listOf(),
commonsCategories: List<String> = listOf(),
isSelected: Boolean = false,
id: String = "entityId"
) = DepictedItem(
name = name,
description = description,
imageUrl = imageUrl,
instanceOfs = instanceOfs,
commonsCategories = commonsCategories,
isSelected = isSelected,
id = id
)
fun categoryItem(name: String = "name", selected: Boolean = false) =
CategoryItem(name, selected)
fun media(
thumbUrl: String? = "thumbUrl",
imageUrl: String? = "imageUrl",
filename: String? = "filename",
fallbackDescription: String? = "fallbackDescription",
dateUploaded: Date? = Date(),
license: String? = "license",
licenseUrl: String? = "licenseUrl",
creator: String? = "creator",
pageId: String = "pageId",
categories: List<String>? = listOf("categories"),
coordinates: LatLng? = LatLng(0.0, 0.0, 0.0f),
captions: Map<String?, String?> = mapOf("en" to "caption"),
descriptions: Map<String?, String?> = mapOf("en" to "description"),
depictionIds: List<String> = listOf("depictionId")
) = Media(
thumbUrl,
imageUrl,
filename,
fallbackDescription,
dateUploaded,
license,
licenseUrl,
creator,
pageId,
categories,
coordinates,
captions,
descriptions,
depictionIds
)
fun place(
name: String = "name",
label: Label? = null,
longDescription: String = "longDescription",
latLng: LatLng? = null,
category: String = "category",
siteLinks: Sitelinks? = null,
pic: String = "pic",
destroyed: String = "destroyed"
): Place {
return Place(name, label, longDescription, latLng, category, siteLinks, pic, destroyed)
}
fun entityId(wikiBaseEntityValue: WikiBaseEntityValue = wikiBaseEntityValue()) =
DataValue.EntityId(wikiBaseEntityValue)
fun wikiBaseEntityValue(
entityType: String = "type",
id: String = "id",
numericId: Long = 0
) = WikiBaseEntityValue(entityType, id, numericId)
fun statement(
mainSnak: Snak_partial = snak(),
rank: String = "rank",
type: String = "type"
) = Statement_partial(mainSnak, type, rank)
fun snak(
snakType: String = "type",
property: String = "property",
dataValue: DataValue = valueString("")
) = Snak_partial(snakType, property, dataValue)
fun valueString(value: String) = DataValue.ValueString(value)
fun entity(
labels: Map<String, String> = emptyMap(),
descriptions: Map<String, String> = emptyMap(),
statements: Map<String, List<Statement_partial>>? = emptyMap(),
id: String = "id"
) = mock<Entities.Entity>().apply {
val mockedLabels = labels.mockLabels()
whenever(labels()).thenReturn(mockedLabels)
val mockedDescriptions = descriptions.mockLabels()
whenever(descriptions()).thenReturn(mockedDescriptions)
whenever(this.statements).thenReturn(statements)
whenever(id()).thenReturn(id)
}
private fun Map<String, String>.mockLabels(): Map<String, Entities.Label> {
return mapValues { entry ->
mock<Entities.Label>().also { whenever(it.value()).thenReturn(entry.value) }
}
}