Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing #5755 with UI automator tests #5890

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 9 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ if (isRunningOnTravisAndIsNotPRBuild) {

dependencies {

def appcompat_version = "1.7.0"
implementation "androidx.appcompat:appcompat:$appcompat_version"
// For loading and tinting drawables on older versions of the platform
implementation "androidx.appcompat:appcompat-resources:$appcompat_version"

// Utils
implementation 'in.yuvi:http.fluent:1.3'
implementation 'com.google.code.gson:gson:2.8.5'
Expand Down Expand Up @@ -380,13 +385,16 @@ android {
compose true
}
composeOptions {
kotlinCompilerExtensionVersion '1.3.2'
kotlinCompilerExtensionVersion '1.5.8'
}
namespace 'fr.free.nrw.commons'
lint {
abortOnError false
disable 'MissingTranslation', 'ExtraTranslation'
}
androidResources {
generateLocaleConfig true
}
}

String getTestUserName() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package fr.free.nrw.commons.ui;

import androidx.test.uiautomator.UiScrollable;
import androidx.test.uiautomator.UiSelector;
import androidx.test.uiautomator.UiObject;
import androidx.test.uiautomator.UiDevice;
import androidx.test.platform.app.InstrumentationRegistry;
import android.content.Intent;
import android.provider.Settings;

import org.junit.Before;
import org.junit.Test;

public class AppLanguagesSystemTest {

private UiDevice device;

@Before
public void setUp() {
// Initiate UI Automator
device = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation());

// Use Intent to start system application
Intent intent = new Intent(Settings.ACTION_SETTINGS);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
InstrumentationRegistry.getInstrumentation().getContext().startActivity(intent);

// wait Settings starting
device.waitForIdle();
}

@Test
public void testCommonsAppLanguageOptionExists() throws Exception {
// 1. Find and click "System"
UiScrollable settingsList = new UiScrollable(new UiSelector().scrollable(true));
UiObject systemOption = settingsList.getChildByText(new UiSelector().text("System"), "System");
systemOption.click();

// 2. scroll and find "Languages & input"
UiObject languagesInputOption = device.findObject(new UiSelector()
.className("android.widget.TextView")
.textContains("Gboard"));
languagesInputOption.clickAndWaitForNewWindow();




// 3. detect "App languages" and click
UiObject appLanguagesOption = device.findObject(new UiSelector().text("App languages"));
appLanguagesOption.clickAndWaitForNewWindow();

// 4. detect "Commons" APP is there
UiScrollable appLanguagesList = new UiScrollable(new UiSelector().scrollable(true));
UiObject commonsAppOption = appLanguagesList.getChildByText(new UiSelector().text("Commons"), "Commons");

assert(commonsAppOption.exists());
}
}
7 changes: 7 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,13 @@
<service
android:name="androidx.work.impl.foreground.SystemForegroundService"
android:foregroundServiceType="dataSync" />
<service
android:name="androidx.appcompat.app.AppLocalesMetadataHolderService"
android:enabled="false">
<meta-data
android:name="autoStoreLocales"
android:value="true" />
</service>

<provider
android:name=".filepicker.ExtendedFileProvider"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public void onCreate(Bundle savedInstanceState) {
setContentView(binding.getRoot());
setSupportActionBar(binding.toolbarBinding.toolbar);
tabLayout = binding.fragmentMainNavTabLayout;
loadLocale();
// loadLocale();

binding.toolbarBinding.toolbar.setNavigationOnClickListener(view -> {
onSupportNavigateUp();
Expand Down Expand Up @@ -485,13 +485,13 @@ public enum ActiveFragment {
/**
* Load default language in onCreate from SharedPreferences
*/
private void loadLocale() {
final SharedPreferences preferences = getSharedPreferences("Settings",
Activity.MODE_PRIVATE);
final String language = preferences.getString("language", "");
final SettingsFragment settingsFragment = new SettingsFragment();
settingsFragment.setLocale(this, language);
}
// private void loadLocale() {
// final SharedPreferences preferences = getSharedPreferences("Settings",
// Activity.MODE_PRIVATE);
// final String language = preferences.getString("language", "");
// final SettingsFragment settingsFragment = new SettingsFragment();
// settingsFragment.setLocale(this, language);
// }

public NavTabLayout.OnNavigationItemSelectedListener getNavListener() {
return navListener;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,19 @@ abstract class NotForUploadStatusDao {
* Insert into Not For Upload status.
*/
@Insert(onConflict = OnConflictStrategy.REPLACE)
abstract suspend fun insert(notForUploadStatus: NotForUploadStatus)
abstract fun insert(notForUploadStatus: NotForUploadStatus)

/**
* Delete Not For Upload status entry.
*/
@Delete
abstract suspend fun delete(notForUploadStatus: NotForUploadStatus)
abstract fun delete(notForUploadStatus: NotForUploadStatus)

/**
* Query Not For Upload status with image sha1.
*/
@Query("SELECT * FROM images_not_for_upload_table WHERE imageSHA1 = (:imageSHA1) ")
abstract suspend fun getFromImageSHA1(imageSHA1: String): NotForUploadStatus?
abstract fun getFromImageSHA1(imageSHA1: String): NotForUploadStatus?

/**
* Asynchronous image sha1 query.
Expand All @@ -38,7 +38,7 @@ abstract class NotForUploadStatusDao {
* Deletion Not For Upload status with image sha1.
*/
@Query("DELETE FROM images_not_for_upload_table WHERE imageSHA1 = (:imageSHA1) ")
abstract suspend fun deleteWithImageSHA1(imageSHA1: String)
abstract fun deleteWithImageSHA1(imageSHA1: String)

/**
* Asynchronous image sha1 deletion.
Expand All @@ -49,5 +49,5 @@ abstract class NotForUploadStatusDao {
* Check whether the imageSHA1 is present in database
*/
@Query("SELECT COUNT() FROM images_not_for_upload_table WHERE imageSHA1 = (:imageSHA1) ")
abstract suspend fun find(imageSHA1: String): Int
abstract fun find(imageSHA1: String): Int
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,31 +17,31 @@ abstract class UploadedStatusDao {
* Insert into uploaded status.
*/
@Insert(onConflict = OnConflictStrategy.REPLACE)
abstract suspend fun insert(uploadedStatus: UploadedStatus)
abstract fun insert(uploadedStatus: UploadedStatus)

/**
* Update uploaded status entry.
*/
@Update
abstract suspend fun update(uploadedStatus: UploadedStatus)
abstract fun update(uploadedStatus: UploadedStatus)

/**
* Delete uploaded status entry.
*/
@Delete
abstract suspend fun delete(uploadedStatus: UploadedStatus)
abstract fun delete(uploadedStatus: UploadedStatus)

/**
* Query uploaded status with image sha1.
*/
@Query("SELECT * FROM uploaded_table WHERE imageSHA1 = (:imageSHA1) ")
abstract suspend fun getFromImageSHA1(imageSHA1: String): UploadedStatus?
abstract fun getFromImageSHA1(imageSHA1: String): UploadedStatus?

/**
* Query uploaded status with modified image sha1.
*/
@Query("SELECT * FROM uploaded_table WHERE modifiedImageSHA1 = (:modifiedImageSHA1) ")
abstract suspend fun getFromModifiedImageSHA1(modifiedImageSHA1: String): UploadedStatus?
abstract fun getFromModifiedImageSHA1(modifiedImageSHA1: String): UploadedStatus?

/**
* Asynchronous insert into uploaded status table.
Expand All @@ -55,7 +55,7 @@ abstract class UploadedStatusDao {
* Check whether the imageSHA1 is present in database
*/
@Query("SELECT COUNT() FROM uploaded_table WHERE imageSHA1 = (:imageSHA1) AND imageResult = (:imageResult) ")
abstract suspend fun findByImageSHA1(
abstract fun findByImageSHA1(
imageSHA1: String,
imageResult: Boolean,
): Int
Expand All @@ -66,7 +66,7 @@ abstract class UploadedStatusDao {
@Query(
"SELECT COUNT() FROM uploaded_table WHERE modifiedImageSHA1 = (:modifiedImageSHA1) AND modifiedImageResult = (:modifiedImageResult) ",
)
abstract suspend fun findByModifiedImageSHA1(
abstract fun findByModifiedImageSHA1(
modifiedImageSHA1: String,
modifiedImageResult: Boolean,
): Int
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ class RecentLanguagesAdapter constructor(

override fun isEnabled(position: Int) =
recentLanguages[position].languageCode.let {
it.isNotEmpty() && !selectedLanguages.containsValue(it) && it != selectedLangCode
// it.isNotEmpty() && !it.contains(selectedLanguages.values.first())
true
}

override fun getCount() = recentLanguages.size
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/java/fr/free/nrw/commons/settings/Prefs.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ public class Prefs {
public static final String UPLOADS_SHOWING = "uploadsshowing";
public static final String MANAGED_EXIF_TAGS = "managed_exif_tags";
public static final String DESCRIPTION_LANGUAGE = "languageDescription";
public static final String SECONDARY_LANGUAGE = "languageSecondary";

public static final String APP_UI_LANGUAGE = "appUiLanguage";
public static final String KEY_THEME_VALUE = "appThemePref";

Expand Down
Loading