Skip to content

Commit a50cbae

Browse files
macgillsashishkumar468
authored andcommitted
commons-app#3749 Improve MediaClient UnitTests (commons-app#3846)
* commons-app#3468 Switch from RvRenderer to AdapterDelegates - replace SearchDepictionsRenderer * commons-app#3468 Switch from RvRenderer to AdapterDelegates - replace UploadCategoryDepictionsRenderer * commons-app#3468 Switch from RvRenderer to AdapterDelegates - update BaseAdapter to be easier to use * commons-app#3468 Switch from RvRenderer to AdapterDelegates - replace SearchImagesRenderer * commons-app#3468 Switch from RvRenderer to AdapterDelegates - replace SearchCategoriesRenderer * commons-app#3468 Switch from RvRenderer to AdapterDelegates - replace NotificationRenderer * commons-app#3468 Switch from RvRenderer to AdapterDelegates - replace UploadDepictsRenderer * commons-app#3468 Switch from RvRenderer to AdapterDelegates - replace PlaceRenderer * commons-app#3756 Convert SearchDepictionsFragment to use Pagination - convert SearchDepictionsFragment * commons-app#3756 Convert SearchDepictionsFragment to use Pagination - fix presenter unit tests now that view is not nullable - fix Category prefix imports * commons-app#3756 Convert SearchDepictionsFragment to use Pagination - test DataSource related classes * commons-app#3756 Convert SearchDepictionsFragment to use Pagination - reset rx scheduler - ignore failing test * commons-app#3760 Convert SearchCategoriesFragment to use Pagination - extract functionality of pagination to base classes - add category pagination * commons-app#3772 Convert SearchImagesFragment to use Pagination - convert SearchImagesFragment - tidy up showing the empty view - make search fragments show snackbar with appropriate text * commons-app#3772 Convert SearchImagesFragment to use Pagination - allow viewpager to load more data * commons-app#3760 remove test that got re-added by merge * commons-app#3760 remove duplicate dependency * commons-app#3772 fix compilation * commons-app#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 * commons-app#3808 Construct media objects that depict an item id correctly - use generator to construct media for DepictedImages * commons-app#3810 Convert DepictedImagesFragment to use Pagination - extract common media paging methods - convert to DepictedImages to use pagination * commons-app#3810 Convert DepictedImagesFragment to use Pagination - rename base classes to better reflect usage * commons-app#3810 Convert DepictedImagesFragment to use Pagination - map to empty result with no pages * commons-app#3810 Convert DepictedImagesFragment to use Pagination - align test with returned values * commons-app#3780 Create media using a combination of Entities & MwQueryResult - update wikicode to align with expected behaviour * commons-app#3780 Create media using a combination of Entities & MwQueryResult - replace old site of thumbnail title with most relevant caption * commons-app#3818 Convert SubDepictionListFragment to use Pagination - replace SubDepictionList with Child and Parent Fragments - replace contracts with simple presenter declarations - move classes to appropriate packages - delete unused network models - delete duplicated paging classes * commons-app#3820 Convert CategoryImagesListFragment to use Pagination - replace CategoryImagesListFragment with CategoriesMediaFragment - disallow the construction of media objects without imageinfo * commons-app#3822 Convert SubCategoryImagesListFragment to use Pagination - convert subcategories - add continuation support in category client - rely on interfaces for callbacks of PageableMediaFragments * commons-app#3822 Convert SubCategoryImagesListFragment to use Pagination - convert parent categories - delete list fragment - creat base class to support continuation requests in clients * commons-app#3822 Convert SubCategoryImagesListFragment to use Pagination - add tests for ParentCategoriesDataSource * commons-app#3822 Convert SubCategoryImagesListFragment to use Pagination - remove no longer applicable test * commons-app#3749 Improve MediaClient UnitTests - test rewrite * commons-app#3749 Improve MediaClient UnitTests - align with buildConfig property
1 parent 22638b0 commit a50cbae

File tree

2 files changed

+171
-207
lines changed

2 files changed

+171
-207
lines changed

app/src/main/java/fr/free/nrw/commons/media/MediaClient.kt

+15-17
Original file line numberDiff line numberDiff line change
@@ -107,21 +107,6 @@ class MediaClient @Inject constructor(
107107
)
108108
}
109109

110-
private fun mediaFromPageAndEntity(pages: List<MwQueryPage>): Single<List<Media>> {
111-
return if (pages.isEmpty())
112-
Single.just(emptyList())
113-
else
114-
getEntities(pages.map { "$PAGE_ID_PREFIX${it.pageId()}" })
115-
.map {
116-
pages.zip(it.entities().values)
117-
.mapNotNull { (page, entity) ->
118-
page.imageInfo()?.let {
119-
mediaConverter.convert(page, entity, it)
120-
}
121-
}
122-
}
123-
}
124-
125110
/**
126111
* Fetches Media object from the imageInfo API
127112
*
@@ -141,7 +126,6 @@ class MediaClient @Inject constructor(
141126
fun getPictureOfTheDay(): Single<Media> {
142127
val date = CommonsDateUtil.getIso8601DateFormatShort().format(Date())
143128
return responseMapper(mediaInterface.getMediaWithGenerator("Template:Potd/$date")).map { it.first() }
144-
145129
}
146130

147131
fun getPageHtml(title: String?): Single<String> {
@@ -156,7 +140,6 @@ class MediaClient @Inject constructor(
156140
mediaDetailInterface.getEntity(entityIds.joinToString("|"))
157141
}
158142

159-
160143
fun doesPageContainMedia(title: String?): Single<Boolean> {
161144
return pageMediaInterface.getMediaList(title)
162145
.map { it.items.isNotEmpty() }
@@ -175,4 +158,19 @@ class MediaClient @Inject constructor(
175158
it.query()?.pages() ?: emptyList()
176159
}.flatMap(::mediaFromPageAndEntity)
177160
}
161+
162+
private fun mediaFromPageAndEntity(pages: List<MwQueryPage>): Single<List<Media>> {
163+
return if (pages.isEmpty())
164+
Single.just(emptyList())
165+
else
166+
getEntities(pages.map { "$PAGE_ID_PREFIX${it.pageId()}" })
167+
.map {
168+
pages.zip(it.entities().values)
169+
.mapNotNull { (page, entity) ->
170+
page.imageInfo()?.let {
171+
mediaConverter.convert(page, entity, it)
172+
}
173+
}
174+
}
175+
}
178176
}

0 commit comments

Comments
 (0)