mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-27 04:43:54 +01:00
In app feedback (#4845)
* rebase * Progress * Completed UI and POST Request * removed invalid string resource * Removed unused code & Added string resources * Resolved Code style issues * Javadoc for getters & setters * Codestyle fixes * Minor Fixes * wip * Tests * Comments * Fixed Tests * Minor changes * minor change * Comments * Minor Fixes * fixed tests * Removed Butterknife * Fixed tests * Removed Unecessary strings * Minor chnages * Minor fix * Minor changes * Minor changes * Implemented Suggestions * Removed Redundant Toast
This commit is contained in:
parent
00760ba1c6
commit
fa0370438b
12 changed files with 777 additions and 5 deletions
|
|
@ -0,0 +1,44 @@
|
|||
package fr.free.nrw.commons.feedback
|
||||
|
||||
import android.content.Context
|
||||
import fr.free.nrw.commons.FakeContextWrapper
|
||||
import fr.free.nrw.commons.TestAppAdapter
|
||||
import fr.free.nrw.commons.TestCommonsApplication
|
||||
import fr.free.nrw.commons.feedback.model.Feedback
|
||||
import org.junit.Assert
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.mockito.Mock
|
||||
import org.mockito.Mockito.doReturn
|
||||
import org.mockito.Mockito.mock
|
||||
import org.mockito.MockitoAnnotations
|
||||
import org.robolectric.RobolectricTestRunner
|
||||
import org.robolectric.RuntimeEnvironment
|
||||
import org.robolectric.annotation.Config
|
||||
import org.wikipedia.AppAdapter
|
||||
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
@Config(sdk = [21], application = TestCommonsApplication::class)
|
||||
class FeedbackContentCreatorUnitTests {
|
||||
private lateinit var creator: FeedbackContentCreator
|
||||
private lateinit var feedback: Feedback
|
||||
|
||||
@Mock
|
||||
private lateinit var context: Context
|
||||
|
||||
@Before
|
||||
fun setup() {
|
||||
MockitoAnnotations.initMocks(this)
|
||||
AppAdapter.set(TestAppAdapter())
|
||||
context = RuntimeEnvironment.application.applicationContext
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testToString() {
|
||||
feedback = Feedback("123", "apiLevel", "title", "androidVersion", "deviceModel", "mfg", "deviceName", "wifi")
|
||||
creator = FeedbackContentCreator(context, feedback)
|
||||
Assert.assertNotNull(creator.toString())
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,87 @@
|
|||
package fr.free.nrw.commons.feedback
|
||||
|
||||
import android.content.Context
|
||||
import android.os.Looper.getMainLooper
|
||||
import android.text.Editable
|
||||
import com.nhaarman.mockitokotlin2.doReturn
|
||||
import fr.free.nrw.commons.TestAppAdapter
|
||||
import fr.free.nrw.commons.TestCommonsApplication
|
||||
import fr.free.nrw.commons.contributions.MainActivity
|
||||
import fr.free.nrw.commons.databinding.DialogFeedbackBinding
|
||||
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 org.mockito.Mock
|
||||
import org.mockito.Mockito.`when`
|
||||
import org.mockito.Mockito.mock
|
||||
import org.mockito.MockitoAnnotations
|
||||
import org.powermock.reflect.Whitebox
|
||||
import org.robolectric.Robolectric
|
||||
import org.robolectric.RobolectricTestRunner
|
||||
import org.robolectric.RuntimeEnvironment
|
||||
import org.robolectric.Shadows.shadowOf
|
||||
import org.robolectric.annotation.Config
|
||||
import org.robolectric.annotation.LooperMode
|
||||
import org.wikipedia.AppAdapter
|
||||
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
@Config(sdk = [21], application = TestCommonsApplication::class)
|
||||
@LooperMode(LooperMode.Mode.PAUSED)
|
||||
class FeedbackDialogTests {
|
||||
private lateinit var dialogFeedbackBinding: DialogFeedbackBinding
|
||||
|
||||
@Mock
|
||||
private val onFeedbackSubmitCallback: OnFeedbackSubmitCallback? = null
|
||||
private lateinit var dialog: FeedbackDialog
|
||||
|
||||
private lateinit var context: Context
|
||||
|
||||
@Before
|
||||
fun setUp() {
|
||||
MockitoAnnotations.initMocks(this)
|
||||
|
||||
context = RuntimeEnvironment.application.applicationContext
|
||||
AppAdapter.set(TestAppAdapter())
|
||||
|
||||
val activity = Robolectric.buildActivity(MainActivity::class.java).create().get()
|
||||
|
||||
dialog = FeedbackDialog(activity.applicationContext, onFeedbackSubmitCallback)
|
||||
dialogFeedbackBinding = DialogFeedbackBinding.inflate(dialog.layoutInflater)
|
||||
dialog.show()
|
||||
|
||||
Whitebox.setInternalState(dialog, "onFeedbackSubmitCallback", onFeedbackSubmitCallback)
|
||||
Whitebox.setInternalState(dialog, "dialogFeedbackBinding", dialogFeedbackBinding)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testOnCreate() {
|
||||
dialog.onCreate(null)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testSubmitFeedbackError() {
|
||||
val editable = mock(Editable::class.java)
|
||||
val ed = mock(PasteSensitiveTextInputEditText::class.java)
|
||||
Whitebox.setInternalState(dialogFeedbackBinding, "feedbackItemEditText", ed)
|
||||
`when`(ed?.text).thenReturn(editable)
|
||||
doReturn(editable).`when`(dialogFeedbackBinding.feedbackItemEditText)?.text
|
||||
doReturn("").`when`(editable).toString()
|
||||
dialog.submitFeedback()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testSubmitFeedback() {
|
||||
shadowOf(getMainLooper()).idle()
|
||||
val editable: Editable = mock(Editable::class.java)
|
||||
val ed = mock(PasteSensitiveTextInputEditText::class.java)
|
||||
Whitebox.setInternalState(dialogFeedbackBinding, "feedbackItemEditText", ed)
|
||||
`when`(ed?.text).thenReturn(editable)
|
||||
`when`(editable.toString()).thenReturn("1234")
|
||||
|
||||
Assert.assertEquals(dialogFeedbackBinding.feedbackItemEditText?.text.toString(), "1234")
|
||||
dialog.submitFeedback()
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,65 @@
|
|||
package fr.free.nrw.commons.feedback
|
||||
|
||||
import fr.free.nrw.commons.feedback.model.Feedback
|
||||
import org.junit.Assert
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
|
||||
class FeedbackUnitTests {
|
||||
private lateinit var feedback: Feedback
|
||||
|
||||
@Before
|
||||
fun setup() {
|
||||
feedback = Feedback("123", "apiLevel", "title", "androidVersion", "deviceModel", "mfg", "deviceName", "wifi")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testVersion() {
|
||||
feedback.version = "456"
|
||||
Assert.assertEquals(feedback.version, "456")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testApiLevel() {
|
||||
Assert.assertEquals(feedback.apiLevel, "apiLevel")
|
||||
feedback.apiLevel = "29"
|
||||
Assert.assertEquals(feedback.apiLevel, "29")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testTitle() {
|
||||
feedback.title = "myTitle"
|
||||
Assert.assertEquals(feedback.title, "myTitle")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testAndroidVersion() {
|
||||
feedback.androidVersion = "PIE"
|
||||
Assert.assertEquals(feedback.androidVersion, "PIE")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testDeviceModel() {
|
||||
feedback.deviceModel = "My Device"
|
||||
Assert.assertEquals(feedback.deviceModel, "My Device")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testDeviceMfg() {
|
||||
feedback.deviceManufacturer = "MYCOMPANY"
|
||||
Assert.assertEquals(feedback.deviceManufacturer, "MYCOMPANY")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testDeviceName() {
|
||||
feedback.device = "my_name"
|
||||
Assert.assertEquals(feedback.device, "my_name")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testNetworkType() {
|
||||
feedback.networkType = "network"
|
||||
Assert.assertEquals(feedback.networkType, "network")
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,5 +1,6 @@
|
|||
package fr.free.nrw.commons.navtab
|
||||
|
||||
import android.app.Dialog
|
||||
import android.content.ComponentName
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
|
|
@ -7,20 +8,33 @@ import android.net.Uri
|
|||
import android.os.Looper
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.widget.Button
|
||||
import android.widget.TextView
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
import androidx.fragment.app.FragmentManager
|
||||
import androidx.fragment.app.FragmentTransaction
|
||||
import fr.free.nrw.commons.CommonsApplication
|
||||
import fr.free.nrw.commons.R
|
||||
import fr.free.nrw.commons.TestAppAdapter
|
||||
import fr.free.nrw.commons.TestCommonsApplication
|
||||
import fr.free.nrw.commons.actions.PageEditClient
|
||||
import fr.free.nrw.commons.feedback.FeedbackDialog
|
||||
import fr.free.nrw.commons.feedback.model.Feedback
|
||||
import fr.free.nrw.commons.kvstore.JsonKvStore
|
||||
import fr.free.nrw.commons.profile.ProfileActivity
|
||||
import fr.free.nrw.commons.utils.ConfigUtils
|
||||
import fr.free.nrw.commons.utils.ConfigUtils.getVersionNameWithSha
|
||||
import io.reactivex.Observable
|
||||
import io.reactivex.Single
|
||||
import io.reactivex.SingleSource
|
||||
import io.reactivex.functions.Function
|
||||
import org.junit.Assert
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.mockito.ArgumentMatchers
|
||||
import org.mockito.Mock
|
||||
import org.mockito.Mockito.`when`
|
||||
import org.mockito.Mockito.*
|
||||
import org.mockito.MockitoAnnotations
|
||||
import org.powermock.reflect.Whitebox
|
||||
import org.robolectric.Robolectric
|
||||
|
|
@ -31,7 +45,10 @@ import org.robolectric.annotation.Config
|
|||
import org.robolectric.annotation.LooperMode
|
||||
import org.robolectric.shadows.ShadowActivity
|
||||
import org.robolectric.shadows.ShadowAlertDialog
|
||||
import org.robolectric.shadows.ShadowDialog
|
||||
import org.wikipedia.AppAdapter
|
||||
import java.lang.reflect.Method
|
||||
import java.util.concurrent.Callable
|
||||
|
||||
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
|
|
@ -51,10 +68,14 @@ class MoreBottomSheetFragmentUnitTests {
|
|||
@Mock
|
||||
private lateinit var morePeerReview: TextView
|
||||
|
||||
@Mock
|
||||
private lateinit var pageEditClient: PageEditClient
|
||||
|
||||
@Before
|
||||
fun setUp() {
|
||||
MockitoAnnotations.initMocks(this)
|
||||
context = RuntimeEnvironment.application.applicationContext
|
||||
AppAdapter.set(TestAppAdapter())
|
||||
|
||||
activity = Robolectric.buildActivity(ProfileActivity::class.java).create().get()
|
||||
fragment = MoreBottomSheetFragment()
|
||||
|
|
@ -65,6 +86,7 @@ class MoreBottomSheetFragmentUnitTests {
|
|||
|
||||
Whitebox.setInternalState(fragment, "store", store)
|
||||
Whitebox.setInternalState(fragment, "morePeerReview", morePeerReview)
|
||||
Whitebox.setInternalState(fragment, "pageEditClient", pageEditClient)
|
||||
|
||||
`when`(store.getBoolean(CommonsApplication.IS_LIMITED_CONNECTION_MODE_ENABLED)).thenReturn(
|
||||
true
|
||||
|
|
@ -101,8 +123,18 @@ class MoreBottomSheetFragmentUnitTests {
|
|||
fun testOnFeedbackClicked() {
|
||||
Shadows.shadowOf(Looper.getMainLooper()).idle()
|
||||
fragment.onFeedbackClicked()
|
||||
val dialog: AlertDialog = ShadowAlertDialog.getLatestDialog() as AlertDialog
|
||||
Assert.assertEquals(dialog.isShowing, true)
|
||||
ShadowDialog.getLatestDialog().findViewById<Button>(R.id.btn_submit_feedback).performClick()
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testUploadFeedback() {
|
||||
Shadows.shadowOf(Looper.getMainLooper()).idle()
|
||||
val feedback = mock(Feedback::class.java)
|
||||
val observable: Observable<Boolean> = Observable.just(false)
|
||||
val observable2: Observable<Boolean> = Observable.just(true)
|
||||
doReturn(observable, observable2).`when`(pageEditClient).prependEdit(anyString(), anyString(), anyString())
|
||||
fragment.uploadFeedback(feedback)
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue