Browse Source

Add tests for ConfirmationDialog RTL

Signed-off-by: alperozturk <alper_ozturk@proton.me>
alperozturk 1 năm trước cách đây
mục cha
commit
228c2159c7

+ 18 - 0
app/src/androidTest/java/com/owncloud/android/AbstractIT.java

@@ -7,6 +7,8 @@ import android.accounts.OperationCanceledException;
 import android.app.Activity;
 import android.content.ActivityNotFoundException;
 import android.content.Context;
+import android.content.res.Configuration;
+import android.content.res.Resources;
 import android.os.Build;
 import android.os.Bundle;
 import android.text.TextUtils;
@@ -58,6 +60,7 @@ import java.io.FileWriter;
 import java.io.IOException;
 import java.io.InputStream;
 import java.util.Collection;
+import java.util.Locale;
 import java.util.Objects;
 
 import androidx.annotation.NonNull;
@@ -403,6 +406,21 @@ public abstract class AbstractIT {
         assertTrue(result.getLogMessage(), result.isSuccess());
     }
 
+    protected void enableRTL() {
+        Locale locale = new Locale("ar");
+        Resources resources = InstrumentationRegistry.getInstrumentation().getTargetContext().getResources();
+        Configuration config = resources.getConfiguration();
+        config.setLocale(locale);
+        resources.updateConfiguration(config, null);
+    }
+
+    protected void resetLocale() {
+        Resources resources = InstrumentationRegistry.getInstrumentation().getTargetContext().getResources();
+        Configuration defaultConfig = resources.getConfiguration();
+        defaultConfig.setLocale(Locale.getDefault());
+        resources.updateConfiguration(defaultConfig, null);
+    }
+
     protected void screenshot(View view) {
         screenshot(view, "");
     }

+ 15 - 0
app/src/androidTest/java/com/owncloud/android/ui/dialog/DialogFragmentIT.java

@@ -25,6 +25,8 @@ package com.owncloud.android.ui.dialog;
 import android.accounts.Account;
 import android.accounts.AccountManager;
 import android.content.Intent;
+import android.content.res.Configuration;
+import android.content.res.Resources;
 import android.net.http.SslCertificate;
 import android.net.http.SslError;
 import android.os.Looper;
@@ -86,12 +88,14 @@ import java.net.URI;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
+import java.util.Locale;
 import java.util.Objects;
 
 import androidx.activity.result.contract.ActivityResultContract;
 import androidx.annotation.NonNull;
 import androidx.fragment.app.DialogFragment;
 import androidx.test.espresso.intent.rule.IntentsTestRule;
+import androidx.test.platform.app.InstrumentationRegistry;
 import kotlin.Unit;
 
 import static androidx.test.platform.app.InstrumentationRegistry.getInstrumentation;
@@ -155,6 +159,17 @@ public class DialogFragmentIT extends AbstractIT {
         showDialog(dialog);
     }
 
+    @Test
+    @ScreenshotTest
+    public void testConfirmationDialogWithThreeActionRTL() {
+        enableRTL();
+
+        ConfirmationDialogFragment dialog = ConfirmationDialogFragment.newInstance(R.string.upload_list_empty_text_auto_upload, new String[] { }, -1, R.string.common_ok, R.string.common_cancel, R.string.common_confirm);
+        showDialog(dialog);
+
+        resetLocale();
+    }
+
     @Test
     @ScreenshotTest
     public void testRemoveFileDialog() {

+ 3 - 1
app/src/main/java/com/owncloud/android/ui/dialog/ConfirmationDialogFragment.java

@@ -70,6 +70,7 @@ public class ConfirmationDialogFragment extends DialogFragment implements Inject
 
         ConfirmationDialogFragment frag = new ConfirmationDialogFragment();
         Bundle args = new Bundle();
+
         args.putInt(ARG_MESSAGE_RESOURCE_ID, messageResId);
         args.putStringArray(ARG_MESSAGE_ARGUMENTS, messageArguments);
         args.putInt(ARG_TITLE_ID, titleResId);
@@ -126,8 +127,9 @@ public class ConfirmationDialogFragment extends DialogFragment implements Inject
         }
 
         Object[] messageArguments = arguments.getStringArray(ARG_MESSAGE_ARGUMENTS);
-        int messageId = arguments.getInt(ARG_MESSAGE_RESOURCE_ID, -1);
+
         int titleId = arguments.getInt(ARG_TITLE_ID, -1);
+        int messageId = arguments.getInt(ARG_MESSAGE_RESOURCE_ID, -1);
 
         int positiveButtonTextId = arguments.getInt(ARG_POSITIVE_BTN_RES, -1);
         int negativeButtonTextId = arguments.getInt(ARG_NEGATIVE_BTN_RES, -1);