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:
Devarsh Mavani 2022-03-20 08:40:25 +05:30 committed by GitHub
parent 00760ba1c6
commit fa0370438b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 777 additions and 5 deletions

View file

@ -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