mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-26 20:33:53 +01:00
Fix failing tests for updateDepictsProperty method (#5795)
* tests: fix failing testUpdateDepictsProperty * replace deprecated circular progress bar with material progress bar * refactor: update SettingsActivity to not use custom appCompatDeletegate It is required because that delegate is automatically handled in new libraries.
This commit is contained in:
parent
ec4a6bc0c4
commit
190135d36c
8 changed files with 107 additions and 84 deletions
|
|
@ -47,7 +47,7 @@ dependencies {
|
||||||
|
|
||||||
implementation 'com.jakewharton.timber:timber:4.7.1'
|
implementation 'com.jakewharton.timber:timber:4.7.1'
|
||||||
implementation 'com.github.deano2390:MaterialShowcaseView:1.2.0'
|
implementation 'com.github.deano2390:MaterialShowcaseView:1.2.0'
|
||||||
implementation 'com.dinuscxj:circleprogressbar:1.1.1'
|
implementation "com.google.android.material:material:1.9.0"
|
||||||
implementation 'com.karumi:dexter:5.0.0'
|
implementation 'com.karumi:dexter:5.0.0'
|
||||||
implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
|
implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -306,6 +306,7 @@ public class AchievementsFragment extends CommonsDaggerSupportFragment {
|
||||||
if (uploadCount==0){
|
if (uploadCount==0){
|
||||||
setZeroAchievements();
|
setZeroAchievements();
|
||||||
}else {
|
}else {
|
||||||
|
|
||||||
binding.imagesUploadedProgressbar.setVisibility(View.VISIBLE);
|
binding.imagesUploadedProgressbar.setVisibility(View.VISIBLE);
|
||||||
binding.imagesUploadedProgressbar.setProgress
|
binding.imagesUploadedProgressbar.setProgress
|
||||||
(100*uploadCount/levelInfo.getMaxUploadCount());
|
(100*uploadCount/levelInfo.getMaxUploadCount());
|
||||||
|
|
@ -342,8 +343,8 @@ public class AchievementsFragment extends CommonsDaggerSupportFragment {
|
||||||
private void setImageRevertPercentage(int notRevertPercentage){
|
private void setImageRevertPercentage(int notRevertPercentage){
|
||||||
binding.imageRevertsProgressbar.setVisibility(View.VISIBLE);
|
binding.imageRevertsProgressbar.setVisibility(View.VISIBLE);
|
||||||
binding.imageRevertsProgressbar.setProgress(notRevertPercentage);
|
binding.imageRevertsProgressbar.setProgress(notRevertPercentage);
|
||||||
String revertPercentage = Integer.toString(notRevertPercentage);
|
final String revertPercentage = Integer.toString(notRevertPercentage);
|
||||||
binding.imageRevertsProgressbar.setProgressTextFormatPattern(revertPercentage + "%%");
|
binding.tvRevertedImages.setText(revertPercentage + "%");
|
||||||
binding.imagesRevertLimitText.setText(getResources().getString(R.string.achievements_revert_limit_message)+ levelInfo.getMinNonRevertPercentage() + "%");
|
binding.imagesRevertLimitText.setText(getResources().getString(R.string.achievements_revert_limit_message)+ levelInfo.getMinNonRevertPercentage() + "%");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -357,10 +358,8 @@ public class AchievementsFragment extends CommonsDaggerSupportFragment {
|
||||||
binding.thanksReceived.setText(String.valueOf(achievements.getThanksReceived()));
|
binding.thanksReceived.setText(String.valueOf(achievements.getThanksReceived()));
|
||||||
binding.imagesUsedByWikiProgressBar.setProgress
|
binding.imagesUsedByWikiProgressBar.setProgress
|
||||||
(100 * achievements.getUniqueUsedImages() / levelInfo.getMaxUniqueImages());
|
(100 * achievements.getUniqueUsedImages() / levelInfo.getMaxUniqueImages());
|
||||||
if(binding.tvWikiPb != null) {
|
binding.tvWikiPb.setText(achievements.getUniqueUsedImages() + "/"
|
||||||
binding.tvWikiPb.setText
|
+ levelInfo.getMaxUniqueImages());
|
||||||
(achievements.getUniqueUsedImages() + "/" + levelInfo.getMaxUniqueImages());
|
|
||||||
}
|
|
||||||
binding.imageFeatured.setText(String.valueOf(achievements.getFeaturedImages()));
|
binding.imageFeatured.setText(String.valueOf(achievements.getFeaturedImages()));
|
||||||
binding.qualityImages.setText(String.valueOf(achievements.getQualityImages()));
|
binding.qualityImages.setText(String.valueOf(achievements.getQualityImages()));
|
||||||
String levelUpInfoString = getString(R.string.level).toUpperCase();
|
String levelUpInfoString = getString(R.string.level).toUpperCase();
|
||||||
|
|
|
||||||
|
|
@ -65,10 +65,10 @@ public class QuizResultActivity extends AppCompatActivity {
|
||||||
* @param score
|
* @param score
|
||||||
*/
|
*/
|
||||||
public void setScore(int score) {
|
public void setScore(int score) {
|
||||||
int per = score * MULTIPLIER_TO_GET_PERCENTAGE;
|
final int scorePercent = score * MULTIPLIER_TO_GET_PERCENTAGE;
|
||||||
binding.resultProgressBar.setProgress(per);
|
binding.resultProgressBar.setProgress(scorePercent);
|
||||||
binding.resultProgressBar.setProgressTextFormatPattern(score +" / " + NUMBER_OF_QUESTIONS);
|
binding.tvResultProgress.setText(score +" / " + NUMBER_OF_QUESTIONS);
|
||||||
String message = getResources().getString(R.string.congratulatory_message_quiz,per + "%");
|
final String message = getResources().getString(R.string.congratulatory_message_quiz,scorePercent + "%");
|
||||||
binding.congratulatoryMessage.setText(message);
|
binding.congratulatoryMessage.setText(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ import fr.free.nrw.commons.theme.BaseActivity;
|
||||||
public class SettingsActivity extends BaseActivity {
|
public class SettingsActivity extends BaseActivity {
|
||||||
|
|
||||||
private ActivitySettingsBinding binding;
|
private ActivitySettingsBinding binding;
|
||||||
private AppCompatDelegate settingsDelegate;
|
// private AppCompatDelegate settingsDelegate;
|
||||||
/**
|
/**
|
||||||
* to be called when the activity starts
|
* to be called when the activity starts
|
||||||
* @param savedInstanceState the previously saved state
|
* @param savedInstanceState the previously saved state
|
||||||
|
|
@ -39,10 +39,10 @@ public class SettingsActivity extends BaseActivity {
|
||||||
@Override
|
@Override
|
||||||
protected void onPostCreate(Bundle savedInstanceState) {
|
protected void onPostCreate(Bundle savedInstanceState) {
|
||||||
super.onPostCreate(savedInstanceState);
|
super.onPostCreate(savedInstanceState);
|
||||||
if (settingsDelegate == null) {
|
// if (settingsDelegate == null) {
|
||||||
settingsDelegate = AppCompatDelegate.create(this, null);
|
// settingsDelegate = AppCompatDelegate.create(this, null);
|
||||||
}
|
// }
|
||||||
settingsDelegate.onPostCreate(savedInstanceState);
|
// settingsDelegate.onPostCreate(savedInstanceState);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -47,9 +47,9 @@ class WikiBaseClient @Inject constructor(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun postDeleteClaims(entityId: String, data: String): Observable<Boolean> {
|
fun postDeleteClaims(entityId: String, data: String?): Observable<Boolean> {
|
||||||
return csrfToken().switchMap { editToken ->
|
return csrfToken().switchMap { editToken ->
|
||||||
wikiBaseInterface.postDeleteClaims(editToken, entityId, data)
|
wikiBaseInterface.postDeleteClaims(editToken, entityId, data!!)
|
||||||
.map { response: MwPostResponse -> response.successVal == 1 }
|
.map { response: MwPostResponse -> response.successVal == 1 }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -41,20 +41,37 @@
|
||||||
android:textSize="32sp"
|
android:textSize="32sp"
|
||||||
android:layout_marginTop="@dimen/activity_margin_vertical" />
|
android:layout_marginTop="@dimen/activity_margin_vertical" />
|
||||||
|
|
||||||
<com.dinuscxj.progressbar.CircleProgressBar
|
<FrameLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="@dimen/dimen_250"
|
android:layout_height="@dimen/dimen_250"
|
||||||
android:layout_marginRight="@dimen/activity_margin_horizontal"
|
android:layout_marginRight="@dimen/activity_margin_horizontal"
|
||||||
android:layout_marginLeft="@dimen/activity_margin_horizontal"
|
android:layout_marginLeft="@dimen/activity_margin_horizontal"
|
||||||
android:layout_marginTop="@dimen/activity_margin_vertical"
|
android:layout_marginTop="@dimen/activity_margin_vertical">
|
||||||
android:progress="50"
|
|
||||||
app:progress_end_color="#8C8B98"
|
<com.google.android.material.progressindicator.CircularProgressIndicator
|
||||||
app:progress_start_color="#3A3381"
|
android:id="@+id/result_progress_bar"
|
||||||
app:progress_stroke_width="@dimen/first_fab"
|
android:layout_width="match_parent"
|
||||||
app:progress_text_size="@dimen/large_gap"
|
android:layout_height="@dimen/dimen_250"
|
||||||
app:progress_text_format_pattern="4/5"
|
android:layout_gravity="center"
|
||||||
app:style="solid_line"
|
android:indeterminate="false"
|
||||||
android:id="@+id/result_progress_bar"/>
|
app:showAnimationBehavior="outward"
|
||||||
|
app:indicatorColor="#3A3381"
|
||||||
|
app:indicatorSize="128dp"
|
||||||
|
app:trackThickness="@dimen/first_fab"
|
||||||
|
app:trackColor="#B7B6B6" />
|
||||||
|
|
||||||
|
<androidx.appcompat.widget.AppCompatTextView
|
||||||
|
android:id="@+id/tv_result_progress"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:padding="@dimen/progressbar_padding"
|
||||||
|
android:gravity="center"
|
||||||
|
android:maxLines="1"
|
||||||
|
android:textColor="@color/secondaryColor"
|
||||||
|
app:autoSizeMaxTextSize="@dimen/large_gap"
|
||||||
|
app:autoSizeStepGranularity="1sp"
|
||||||
|
app:autoSizeTextType="uniform" />
|
||||||
|
</FrameLayout>
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
|
|
|
||||||
|
|
@ -133,27 +133,20 @@
|
||||||
android:layout_width="@dimen/dimen_40"
|
android:layout_width="@dimen/dimen_40"
|
||||||
android:layout_height="@dimen/dimen_40"
|
android:layout_height="@dimen/dimen_40"
|
||||||
android:layout_alignParentEnd="true"
|
android:layout_alignParentEnd="true"
|
||||||
android:layout_alignParentRight="true"
|
android:layout_marginEnd="32dp">
|
||||||
android:layout_marginEnd="32dp"
|
|
||||||
android:layout_marginRight="32dp">
|
|
||||||
|
|
||||||
<com.dinuscxj.progressbar.CircleProgressBar
|
<com.google.android.material.progressindicator.CircularProgressIndicator
|
||||||
|
android:id="@+id/images_uploaded_progressbar"
|
||||||
android:layout_width="@dimen/dimen_40"
|
android:layout_width="@dimen/dimen_40"
|
||||||
android:layout_height="@dimen/dimen_40"
|
android:layout_height="@dimen/dimen_40"
|
||||||
android:layout_alignParentRight="true"
|
android:indeterminate="false"
|
||||||
android:layout_alignParentEnd="true"
|
|
||||||
android:layout_marginEnd="@dimen/large_gap"
|
android:layout_marginEnd="@dimen/large_gap"
|
||||||
android:layout_marginRight="@dimen/large_gap"
|
app:showAnimationBehavior="outward"
|
||||||
android:id="@+id/images_uploaded_progressbar"
|
app:indicatorColor="@color/primaryColor"
|
||||||
android:progress="50"
|
app:indicatorSize="32dp"
|
||||||
app:progress_text_size="@dimen/progressbar_text"
|
app:trackThickness="@dimen/progressbar_stroke"
|
||||||
app:progress_end_color="#8C8B98"
|
app:trackColor="#B7B6B6"
|
||||||
app:progress_start_color="#3A3381"
|
android:visibility="gone"/>
|
||||||
app:progress_stroke_width="@dimen/progressbar_stroke"
|
|
||||||
app:progress_text_format_pattern=""
|
|
||||||
android:visibility="gone"
|
|
||||||
app:progress_text_color="@color/secondaryColor"
|
|
||||||
app:style="solid_line" />
|
|
||||||
|
|
||||||
<androidx.appcompat.widget.AppCompatTextView
|
<androidx.appcompat.widget.AppCompatTextView
|
||||||
android:id="@+id/tv_uploaded_images"
|
android:id="@+id/tv_uploaded_images"
|
||||||
|
|
@ -228,24 +221,38 @@
|
||||||
android:layout_marginStart="@dimen/activity_margin_horizontal"
|
android:layout_marginStart="@dimen/activity_margin_horizontal"
|
||||||
android:layout_below="@id/images_reverted_info"/>
|
android:layout_below="@id/images_reverted_info"/>
|
||||||
|
|
||||||
<com.dinuscxj.progressbar.CircleProgressBar
|
<FrameLayout
|
||||||
android:layout_width="@dimen/dimen_40"
|
android:layout_width="@dimen/dimen_40"
|
||||||
android:layout_height="@dimen/dimen_40"
|
android:layout_height="@dimen/dimen_40"
|
||||||
android:layout_alignParentRight="true"
|
|
||||||
android:layout_alignParentEnd="true"
|
android:layout_alignParentEnd="true"
|
||||||
android:layout_marginRight="@dimen/large_gap"
|
android:layout_marginEnd="32dp">
|
||||||
android:layout_marginEnd="@dimen/large_gap"
|
|
||||||
android:progress="50"
|
|
||||||
android:visibility="gone"
|
|
||||||
android:id="@+id/image_reverts_progressbar"
|
|
||||||
app:progress_end_color="#8C8B98"
|
|
||||||
app:progress_start_color="#3A3381"
|
|
||||||
app:progress_text_size="@dimen/progressbar_text"
|
|
||||||
app:progress_stroke_width="@dimen/progressbar_stroke"
|
|
||||||
app:progress_text_format_pattern="92%%"
|
|
||||||
app:progress_text_color="@color/secondaryColor"
|
|
||||||
app:style="solid_line" />
|
|
||||||
|
|
||||||
|
<com.google.android.material.progressindicator.CircularProgressIndicator
|
||||||
|
android:id="@+id/image_reverts_progressbar"
|
||||||
|
android:layout_width="@dimen/dimen_40"
|
||||||
|
android:layout_height="@dimen/dimen_40"
|
||||||
|
android:indeterminate="false"
|
||||||
|
android:layout_marginEnd="@dimen/large_gap"
|
||||||
|
app:showAnimationBehavior="outward"
|
||||||
|
app:indicatorColor="@color/primaryColor"
|
||||||
|
app:indicatorSize="32dp"
|
||||||
|
app:trackThickness="@dimen/progressbar_stroke"
|
||||||
|
app:trackColor="#B7B6B6"
|
||||||
|
android:visibility="gone"/>
|
||||||
|
|
||||||
|
<androidx.appcompat.widget.AppCompatTextView
|
||||||
|
android:id="@+id/tv_reverted_images"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:padding="@dimen/progressbar_padding"
|
||||||
|
android:gravity="center"
|
||||||
|
android:maxLines="1"
|
||||||
|
android:textColor="@color/secondaryColor"
|
||||||
|
app:autoSizeMaxTextSize="@dimen/progressbar_text"
|
||||||
|
app:autoSizeMinTextSize="2sp"
|
||||||
|
app:autoSizeStepGranularity="1sp"
|
||||||
|
app:autoSizeTextType="uniform" />
|
||||||
|
</FrameLayout>
|
||||||
</RelativeLayout>
|
</RelativeLayout>
|
||||||
|
|
||||||
<RelativeLayout
|
<RelativeLayout
|
||||||
|
|
@ -295,27 +302,20 @@
|
||||||
android:layout_width="@dimen/dimen_40"
|
android:layout_width="@dimen/dimen_40"
|
||||||
android:layout_height="@dimen/dimen_40"
|
android:layout_height="@dimen/dimen_40"
|
||||||
android:layout_alignParentEnd="true"
|
android:layout_alignParentEnd="true"
|
||||||
android:layout_alignParentRight="true"
|
android:layout_marginEnd="32dp">
|
||||||
android:layout_marginEnd="32dp"
|
|
||||||
android:layout_marginRight="32dp">
|
|
||||||
|
|
||||||
<com.dinuscxj.progressbar.CircleProgressBar
|
<com.google.android.material.progressindicator.CircularProgressIndicator
|
||||||
|
android:id="@+id/images_used_by_wiki_progress_bar"
|
||||||
android:layout_width="@dimen/dimen_40"
|
android:layout_width="@dimen/dimen_40"
|
||||||
android:layout_height="@dimen/dimen_40"
|
android:layout_height="@dimen/dimen_40"
|
||||||
android:layout_alignParentRight="true"
|
android:indeterminate="false"
|
||||||
android:layout_alignParentEnd="true"
|
|
||||||
android:layout_marginRight="@dimen/large_gap"
|
|
||||||
android:layout_marginEnd="@dimen/large_gap"
|
android:layout_marginEnd="@dimen/large_gap"
|
||||||
android:progress="50"
|
app:showAnimationBehavior="outward"
|
||||||
app:progress_text_size="@dimen/progressbar_text"
|
app:indicatorColor="@color/primaryColor"
|
||||||
android:id="@+id/images_used_by_wiki_progress_bar"
|
app:indicatorSize="32dp"
|
||||||
app:progress_end_color="#8C8B98"
|
app:trackThickness="@dimen/progressbar_stroke"
|
||||||
app:progress_start_color="#3A3381"
|
app:trackColor="#B7B6B6"
|
||||||
app:progress_stroke_width="2.5dp"
|
android:visibility="gone"/>
|
||||||
android:visibility="gone"
|
|
||||||
app:progress_text_color="@color/secondaryColor"
|
|
||||||
app:progress_text_format_pattern=""
|
|
||||||
app:style="solid_line" />
|
|
||||||
|
|
||||||
<androidx.appcompat.widget.AppCompatTextView
|
<androidx.appcompat.widget.AppCompatTextView
|
||||||
android:id="@+id/tv_wiki_pb"
|
android:id="@+id/tv_wiki_pb"
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ import com.nhaarman.mockitokotlin2.whenever
|
||||||
import fr.free.nrw.commons.kvstore.JsonKvStore
|
import fr.free.nrw.commons.kvstore.JsonKvStore
|
||||||
import fr.free.nrw.commons.upload.UploadResult
|
import fr.free.nrw.commons.upload.UploadResult
|
||||||
import fr.free.nrw.commons.upload.WikidataPlace
|
import fr.free.nrw.commons.upload.WikidataPlace
|
||||||
|
import fr.free.nrw.commons.wikidata.model.RemoveClaim
|
||||||
import io.reactivex.Observable
|
import io.reactivex.Observable
|
||||||
import org.junit.Before
|
import org.junit.Before
|
||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
|
|
@ -18,7 +19,6 @@ import org.mockito.Mock
|
||||||
import org.mockito.Mockito
|
import org.mockito.Mockito
|
||||||
import org.mockito.Mockito.verifyNoInteractions
|
import org.mockito.Mockito.verifyNoInteractions
|
||||||
import org.mockito.MockitoAnnotations
|
import org.mockito.MockitoAnnotations
|
||||||
import fr.free.nrw.commons.wikidata.model.EditClaim
|
|
||||||
|
|
||||||
class WikidataEditServiceTest {
|
class WikidataEditServiceTest {
|
||||||
@Mock
|
@Mock
|
||||||
|
|
@ -53,9 +53,16 @@ class WikidataEditServiceTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testUpdateDepictsProperty() {
|
fun testUpdateDepictsProperty() {
|
||||||
whenever(wikibaseClient.postEditEntityByFilename("Test.jpg",
|
val fileEntityId = "12345"
|
||||||
gson.toJson(Mockito.mock(EditClaim::class.java)))).thenReturn(Observable.just(true))
|
|
||||||
wikidataEditService.updateDepictsProperty("Test.jpg", listOf())
|
whenever(wikibaseClient.getClaimIdsByProperty("M" + fileEntityId,
|
||||||
|
WikidataProperties.DEPICTS.propertyName))
|
||||||
|
.thenReturn(Observable.just(emptyList()))
|
||||||
|
whenever(wikibaseClient.postDeleteClaims("M" + fileEntityId,
|
||||||
|
gson.toJson(Mockito.mock(RemoveClaim::class.java)))
|
||||||
|
).thenReturn(Observable.just(true))
|
||||||
|
|
||||||
|
wikidataEditService.updateDepictsProperty(fileEntityId, listOf())
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue