mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-27 21:03:54 +01:00
Pasted text should have fonts unified (for Caption/Description) (#4667)
* Changed hardcoded "More" to getStrings(R.string.more) for Unlogged user - MainActivity toolbar showed "More" when clicked on More options in other language than English * Changed hardcoded "More" to getStrings(R.string.more) for Logged user - MainActivity toolbar showed "More" when clicked on More options in other language than English * Added test for: MainActivity.setUpPager * Pasted text is now unformatted for caption and description * Removed other branch contribution * Added test * Rename .java to .kt * Test from Java to Kotlin; +small fix * PasteSensitiveTextInputEditTextTest - updated
This commit is contained in:
parent
ad0aa7d4ea
commit
e910b1d14f
5 changed files with 159 additions and 9 deletions
|
|
@ -0,0 +1,79 @@
|
|||
package fr.free.nrw.commons.ui
|
||||
|
||||
import android.R
|
||||
import android.content.Context
|
||||
import android.os.Build
|
||||
import android.util.AttributeSet
|
||||
import androidx.test.core.app.ApplicationProvider
|
||||
import androidx.test.runner.AndroidJUnit4
|
||||
import fr.free.nrw.commons.ui.PasteSensitiveTextInputEditText
|
||||
import org.junit.Assert
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import java.lang.Exception
|
||||
import kotlin.Throws
|
||||
|
||||
@RunWith(AndroidJUnit4::class)
|
||||
class PasteSensitiveTextInputEditTextTest {
|
||||
|
||||
private var context: Context? = null
|
||||
private var textView: PasteSensitiveTextInputEditText? = null
|
||||
|
||||
@Before
|
||||
fun setup() {
|
||||
context = ApplicationProvider.getApplicationContext()
|
||||
textView = PasteSensitiveTextInputEditText(context)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun onTextContextMenuItemPasteFormattingDisabled() {
|
||||
textView!!.setFormattingAllowed(false);
|
||||
textView!!.setText("Text")
|
||||
textView!!.onTextContextMenuItem(R.id.paste)
|
||||
Assert.assertEquals("Text", textView!!.text.toString())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun onTextContextMenuItemPasteFormattingAllowed() {
|
||||
textView!!.setFormattingAllowed(true);
|
||||
textView!!.setText("Text")
|
||||
textView!!.onTextContextMenuItem(R.id.paste)
|
||||
Assert.assertEquals("Text", textView!!.text.toString())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun onTextContextMenuItemPaste() {
|
||||
textView!!.setText("Text")
|
||||
textView!!.onTextContextMenuItem(R.id.paste)
|
||||
Assert.assertEquals("Text", textView!!.text.toString())
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
fun onTextContextMenuItemNotPaste() {
|
||||
textView!!.setText("Text")
|
||||
textView!!.onTextContextMenuItem(R.id.copy)
|
||||
Assert.assertEquals("Text", textView!!.text.toString())
|
||||
}
|
||||
|
||||
// this test has no real value, just % for test code coverage
|
||||
@Test
|
||||
fun extractFormattingAttributeSet(){
|
||||
val methodExtractFormattingAttribute = textView!!.javaClass.getDeclaredMethod(
|
||||
"extractFormattingAttribute", Context::class.java, AttributeSet::class.java)
|
||||
methodExtractFormattingAttribute.isAccessible = true
|
||||
methodExtractFormattingAttribute.invoke(textView, context, null)
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun setFormattingAllowed() {
|
||||
val fieldFormattingAllowed = textView!!.javaClass.getDeclaredField("formattingAllowed")
|
||||
fieldFormattingAllowed.isAccessible = true
|
||||
textView!!.setFormattingAllowed(true)
|
||||
Assert.assertTrue(fieldFormattingAllowed.getBoolean(textView))
|
||||
textView!!.setFormattingAllowed(false)
|
||||
Assert.assertFalse(fieldFormattingAllowed.getBoolean(textView))
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue