mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-26 20:33:53 +01:00
Removed default license settings, and implemented selecting last selected license as default licence(#2170) (#2218)
* Removed default license settings, and implemented selecting last selected license as default licence(#2170) * Replace settings license tests with recent upload limit test
This commit is contained in:
parent
f5c8e7ad93
commit
dabcd43a5b
4 changed files with 32 additions and 53 deletions
|
|
@ -3,10 +3,7 @@ package fr.free.nrw.commons;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
import android.support.test.espresso.Espresso;
|
import android.support.test.espresso.Espresso;
|
||||||
import android.support.test.espresso.action.ViewActions;
|
|
||||||
import android.support.test.espresso.assertion.ViewAssertions;
|
|
||||||
import android.support.test.espresso.matcher.PreferenceMatchers;
|
import android.support.test.espresso.matcher.PreferenceMatchers;
|
||||||
import android.support.test.espresso.matcher.ViewMatchers;
|
|
||||||
import android.support.test.filters.LargeTest;
|
import android.support.test.filters.LargeTest;
|
||||||
import android.support.test.rule.ActivityTestRule;
|
import android.support.test.rule.ActivityTestRule;
|
||||||
import android.support.test.runner.AndroidJUnit4;
|
import android.support.test.runner.AndroidJUnit4;
|
||||||
|
|
@ -17,8 +14,17 @@ import org.junit.runner.RunWith;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import fr.free.nrw.commons.settings.Prefs;
|
||||||
import fr.free.nrw.commons.settings.SettingsActivity;
|
import fr.free.nrw.commons.settings.SettingsActivity;
|
||||||
|
|
||||||
|
import static android.support.test.espresso.action.ViewActions.click;
|
||||||
|
import static android.support.test.espresso.action.ViewActions.replaceText;
|
||||||
|
import static android.support.test.espresso.assertion.ViewAssertions.matches;
|
||||||
|
import static android.support.test.espresso.matcher.ViewMatchers.withId;
|
||||||
|
import static android.support.test.espresso.matcher.ViewMatchers.withText;
|
||||||
|
import static org.hamcrest.Matchers.allOf;
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
@LargeTest
|
@LargeTest
|
||||||
@RunWith(AndroidJUnit4.class)
|
@RunWith(AndroidJUnit4.class)
|
||||||
public class SettingsActivityTest {
|
public class SettingsActivityTest {
|
||||||
|
|
@ -27,8 +33,7 @@ public class SettingsActivityTest {
|
||||||
|
|
||||||
@Rule
|
@Rule
|
||||||
public ActivityTestRule<SettingsActivity> activityRule =
|
public ActivityTestRule<SettingsActivity> activityRule =
|
||||||
new ActivityTestRule<SettingsActivity>(SettingsActivity.class,
|
new ActivityTestRule<SettingsActivity>(SettingsActivity.class, false, true) {
|
||||||
false /* Initial touch mode */, true /* launch activity */) {
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void afterActivityLaunched() {
|
protected void afterActivityLaunched() {
|
||||||
|
|
@ -59,41 +64,31 @@ public class SettingsActivityTest {
|
||||||
};
|
};
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void oneLicenseIsChecked() {
|
public void setRecentUploadLimitTo100() {
|
||||||
// click "License" (the first item)
|
// Open "Use external storage" preference
|
||||||
Espresso.onData(PreferenceMatchers.withKey("defaultLicense"))
|
Espresso.onData(PreferenceMatchers.withKey("uploads"))
|
||||||
.inAdapterView(ViewMatchers.withId(android.R.id.list))
|
.inAdapterView(withId(android.R.id.list))
|
||||||
.atPosition(0)
|
.perform(click());
|
||||||
.perform(ViewActions.click());
|
|
||||||
|
|
||||||
// test the selected item
|
// Try setting it to 100
|
||||||
Espresso.onView(ViewMatchers.isChecked())
|
Espresso.onView(withId(android.R.id.edit))
|
||||||
.check(ViewAssertions.matches(ViewMatchers.isDisplayed()));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
.perform(replaceText("100"));
|
||||||
public void afterClickingCcby4ItWillStay() {
|
|
||||||
// click "License" (the first item)
|
|
||||||
Espresso.onData(PreferenceMatchers.withKey("defaultLicense"))
|
|
||||||
.inAdapterView(ViewMatchers.withId(android.R.id.list))
|
|
||||||
.atPosition(0)
|
|
||||||
.perform(ViewActions.click());
|
|
||||||
|
|
||||||
// click "Attribution 4.0"
|
// Click "OK"
|
||||||
Espresso.onView(
|
Espresso.onView(allOf(withId(android.R.id.button1), withText("OK")))
|
||||||
ViewMatchers.withText(R.string.license_name_cc_by_four)
|
.perform(click());
|
||||||
).perform(ViewActions.click());
|
|
||||||
|
|
||||||
// click "License" (the first item)
|
// Check setting set to 100 in SharedPreferences
|
||||||
Espresso.onData(PreferenceMatchers.withKey("defaultLicense"))
|
assertEquals(
|
||||||
.inAdapterView(ViewMatchers.withId(android.R.id.list))
|
100,
|
||||||
.atPosition(0)
|
prefs.getInt(Prefs.UPLOADS_SHOWING, 0)
|
||||||
.perform(ViewActions.click());
|
);
|
||||||
|
|
||||||
// test the value remains "Attribution 4.0"
|
// Check displaying 100 in summary text
|
||||||
Espresso.onView(ViewMatchers.isChecked())
|
Espresso.onData(PreferenceMatchers.withKey("uploads"))
|
||||||
.check(ViewAssertions.matches(
|
.inAdapterView(withId(android.R.id.list))
|
||||||
ViewMatchers.withText(R.string.license_name_cc_by_four)
|
.onChildView(withId(android.R.id.summary))
|
||||||
));
|
.check(matches(withText("100")));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -47,16 +47,6 @@ public class SettingsFragment extends PreferenceFragment {
|
||||||
// Load the preferences from an XML resource
|
// Load the preferences from an XML resource
|
||||||
addPreferencesFromResource(R.xml.preferences);
|
addPreferencesFromResource(R.xml.preferences);
|
||||||
|
|
||||||
// Update spinner to show selected value as summary
|
|
||||||
ListPreference licensePreference = (ListPreference) findPreference(Prefs.DEFAULT_LICENSE);
|
|
||||||
licensePreference.setSummary(getString(Utils.licenseNameFor(licensePreference.getValue())));
|
|
||||||
|
|
||||||
// Keep summary updated when changing value
|
|
||||||
licensePreference.setOnPreferenceChangeListener((preference, newValue) -> {
|
|
||||||
preference.setSummary(getString(Utils.licenseNameFor((String) newValue)));
|
|
||||||
return true;
|
|
||||||
});
|
|
||||||
|
|
||||||
SwitchPreference themePreference = (SwitchPreference) findPreference("theme");
|
SwitchPreference themePreference = (SwitchPreference) findPreference("theme");
|
||||||
themePreference.setOnPreferenceChangeListener((preference, newValue) -> {
|
themePreference.setOnPreferenceChangeListener((preference, newValue) -> {
|
||||||
getActivity().recreate();
|
getActivity().recreate();
|
||||||
|
|
|
||||||
|
|
@ -332,6 +332,7 @@ public class UploadModel {
|
||||||
|
|
||||||
void setSelectedLicense(String licenseName) {
|
void setSelectedLicense(String licenseName) {
|
||||||
this.license = licensesByName.get(licenseName);
|
this.license = licensesByName.get(licenseName);
|
||||||
|
prefs.edit().putString(Prefs.DEFAULT_LICENSE, license).commit();
|
||||||
}
|
}
|
||||||
|
|
||||||
Observable<Contribution> buildContributions(List<String> categoryStringList) {
|
Observable<Contribution> buildContributions(List<String> categoryStringList) {
|
||||||
|
|
|
||||||
|
|
@ -16,13 +16,6 @@
|
||||||
<fr.free.nrw.commons.ui.LongTitlePreferences.LongTitlePreferenceCategory
|
<fr.free.nrw.commons.ui.LongTitlePreferences.LongTitlePreferenceCategory
|
||||||
android:title="@string/preference_category_general">
|
android:title="@string/preference_category_general">
|
||||||
|
|
||||||
<fr.free.nrw.commons.ui.LongTitlePreferences.LongTitleListPreference
|
|
||||||
android:key="defaultLicense"
|
|
||||||
android:title="@string/preference_license"
|
|
||||||
android:entries="@array/pref_defaultLicense_entries"
|
|
||||||
android:entryValues="@array/pref_defaultLicense_values"
|
|
||||||
android:defaultValue="@string/license_pref_cc_by_sa_4_0" />
|
|
||||||
|
|
||||||
<fr.free.nrw.commons.ui.LongTitlePreferences.LongTitleSwitchPreference
|
<fr.free.nrw.commons.ui.LongTitlePreferences.LongTitleSwitchPreference
|
||||||
android:key="useExternalStorage"
|
android:key="useExternalStorage"
|
||||||
android:title="@string/use_external_storage"
|
android:title="@string/use_external_storage"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue