Fixes #4281 "Wrong language pre-selected in Nearby upload" (#4285)

* location added

* tests

* changes requested

* comments

* Test fixed, minor improvement
This commit is contained in:
Aditya-Srivastav 2021-03-04 18:21:28 +05:30 committed by GitHub
parent 91a5aa1abe
commit 7a5774e479
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 88 additions and 33 deletions

View file

@ -76,6 +76,7 @@ fun depictSearchItem(
fun place(
name: String = "name",
lang: String = "en",
label: Label? = null,
longDescription: String = "longDescription",
latLng: LatLng? = null,
@ -84,7 +85,7 @@ fun place(
pic: String = "pic",
destroyed: String = "destroyed"
): Place {
return Place(name, label, longDescription, latLng, category, siteLinks, pic, destroyed)
return Place(lang, name, label, longDescription, latLng, category, siteLinks, pic, destroyed)
}
fun entityId(wikiBaseEntityValue: WikiBaseEntityValue = wikiBaseEntityValue()) =

View file

@ -26,6 +26,7 @@ import org.robolectric.annotation.Config
@Config(sdk = [21], application = TestCommonsApplication::class)
class BookMarkLocationDaoTest {
private val columns = arrayOf(COLUMN_NAME,
COLUMN_LANGUAGE,
COLUMN_DESCRIPTION,
COLUMN_CATEGORY,
COLUMN_LABEL_TEXT,
@ -61,7 +62,7 @@ class BookMarkLocationDaoTest {
builder.setCommonsLink("commonsLink")
examplePlaceBookmark = Place("placeName", exampleLabel, "placeDescription"
examplePlaceBookmark = Place("en", "placeName", exampleLabel, "placeDescription"
, exampleLocation, "placeCategory", builder.build(),"picName","placeDestroyed")
testObject = BookmarkLocationsDao { client }
}
@ -86,6 +87,7 @@ class BookMarkLocationDaoTest {
createCursor(1).let { cursor ->
cursor.moveToFirst()
testObject.fromCursor(cursor).let {
assertEquals("en", it.language)
assertEquals("placeName", it.name)
assertEquals(Label.FOREST, it.label)
assertEquals("placeDescription", it.longDescription)
@ -149,8 +151,9 @@ class BookMarkLocationDaoTest {
assertTrue(testObject.updateBookmarkLocation(examplePlaceBookmark))
verify(client).insert(eq(BASE_URI), captor.capture())
captor.firstValue.let { cv ->
assertEquals(12, cv.size())
assertEquals(13, cv.size())
assertEquals(examplePlaceBookmark.name, cv.getAsString(COLUMN_NAME))
assertEquals(examplePlaceBookmark.language, cv.getAsString(COLUMN_LANGUAGE))
assertEquals(examplePlaceBookmark.longDescription, cv.getAsString(COLUMN_DESCRIPTION))
assertEquals(examplePlaceBookmark.label.text, cv.getAsString(COLUMN_LABEL_TEXT))
assertEquals(examplePlaceBookmark.category, cv.getAsString(COLUMN_CATEGORY))
@ -262,10 +265,17 @@ class BookMarkLocationDaoTest {
verify(database).execSQL("ALTER TABLE bookmarksLocations ADD COLUMN location_destroyed STRING;")
}
@Test
fun migrateTableVersionFrom_v13_to_v14() {
onUpdate(database, 13, 14)
verify(database).execSQL("ALTER TABLE bookmarksLocations ADD COLUMN location_lang STRING;")
}
private fun createCursor(rowCount: Int) = MatrixCursor(columns, rowCount).apply {
for (i in 0 until rowCount) {
addRow(listOf("placeName", "placeDescription","placeCategory", exampleLabel.text, exampleLabel.icon,
addRow(listOf("placeName", "en", "placeDescription", "placeCategory", exampleLabel.text, exampleLabel.icon,
exampleUri, builder.build().wikipediaLink, builder.build().wikidataLink, builder.build().commonsLink,
exampleLocation.latitude, exampleLocation.longitude, "picName", "placeDestroyed"))
}

View file

@ -33,8 +33,8 @@ class BookmarkLocationControllerTest {
private val mockBookmarkList: List<Place>
private get() {
val list = ArrayList<Place>()
list.add(Place("a place",null,"a description",null,"a cat",null,null,null))
list.add(Place("another place",null,"another description",null,"another cat",null,null,null))
list.add(Place("en","a place",null,"a description",null,"a cat",null,null,null))
list.add(Place("en","another place",null,"another description",null,"another cat",null,null,null))
return list
}