mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-27 12:53:55 +01:00
Moved tests over to Kotlin. (#1428)
This commit is contained in:
parent
6b2dd8c1df
commit
22772c851e
29 changed files with 1453 additions and 1679 deletions
67
app/src/test/kotlin/fr/free/nrw/commons/PageTitleTest.kt
Normal file
67
app/src/test/kotlin/fr/free/nrw/commons/PageTitleTest.kt
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
package fr.free.nrw.commons
|
||||
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.robolectric.RobolectricTestRunner
|
||||
import org.robolectric.annotation.Config
|
||||
import java.net.URLEncoder
|
||||
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
@Config(constants = BuildConfig::class, sdk = intArrayOf(21), application = TestCommonsApplication::class)
|
||||
class PageTitleTest {
|
||||
@Test
|
||||
fun displayTextShouldNotBeUnderscored() {
|
||||
val pageTitle = PageTitle("Ex_1 ")
|
||||
assertEquals("Ex 1", pageTitle.displayText)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun moreThanTwoColons() {
|
||||
val pageTitle = PageTitle("File:sample:a.jpg")
|
||||
assertEquals("File:Sample:a.jpg", pageTitle.prefixedText)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun getTextShouldReturnWithoutNamespace() {
|
||||
val pageTitle = PageTitle("File:sample.jpg")
|
||||
assertEquals("Sample.jpg", pageTitle.text)
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
fun capitalizeNameAfterNamespace() {
|
||||
val pageTitle = PageTitle("File:sample.jpg")
|
||||
assertEquals("File:Sample.jpg", pageTitle.prefixedText)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun prefixedTextShouldBeUnderscored() {
|
||||
val pageTitle = PageTitle("Ex 1 ")
|
||||
assertEquals("Ex_1", pageTitle.prefixedText)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun getMobileUriForTest() {
|
||||
val pageTitle = PageTitle("Test")
|
||||
assertEquals(BuildConfig.MOBILE_HOME_URL + "Test", pageTitle.mobileUri.toString())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun spaceBecomesUnderscoreInUri() {
|
||||
val pageTitle = PageTitle("File:Ex 1.jpg")
|
||||
assertEquals(BuildConfig.HOME_URL + "File:Ex_1.jpg", pageTitle.canonicalUri.toString())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun leaveSubpageNamesUncapitalizedInUri() {
|
||||
val pageTitle = PageTitle("User:Ex/subpage")
|
||||
assertEquals(BuildConfig.HOME_URL + "User:Ex/subpage", pageTitle.canonicalUri.toString())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun unicodeUri() {
|
||||
val pageTitle = PageTitle("User:例")
|
||||
assertEquals(BuildConfig.HOME_URL + "User:" + URLEncoder.encode("例", "utf-8"), pageTitle.canonicalUri.toString())
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue