3
3
import android .content .SharedPreferences ;
4
4
import android .preference .PreferenceManager ;
5
5
import android .support .test .espresso .Espresso ;
6
- import android .support .test .espresso .action .ViewActions ;
7
- import android .support .test .espresso .assertion .ViewAssertions ;
8
6
import android .support .test .espresso .matcher .PreferenceMatchers ;
9
- import android .support .test .espresso .matcher .ViewMatchers ;
10
7
import android .support .test .filters .LargeTest ;
11
8
import android .support .test .rule .ActivityTestRule ;
12
9
import android .support .test .runner .AndroidJUnit4 ;
17
14
18
15
import java .util .Map ;
19
16
17
+ import fr .free .nrw .commons .settings .Prefs ;
20
18
import fr .free .nrw .commons .settings .SettingsActivity ;
21
19
20
+ import static android .support .test .espresso .action .ViewActions .click ;
21
+ import static android .support .test .espresso .action .ViewActions .replaceText ;
22
+ import static android .support .test .espresso .assertion .ViewAssertions .matches ;
23
+ import static android .support .test .espresso .matcher .ViewMatchers .withId ;
24
+ import static android .support .test .espresso .matcher .ViewMatchers .withText ;
25
+ import static org .hamcrest .Matchers .allOf ;
26
+ import static org .junit .Assert .assertEquals ;
27
+
22
28
@ LargeTest
23
29
@ RunWith (AndroidJUnit4 .class )
24
30
public class SettingsActivityTest {
@@ -27,8 +33,7 @@ public class SettingsActivityTest {
27
33
28
34
@ Rule
29
35
public ActivityTestRule <SettingsActivity > activityRule =
30
- new ActivityTestRule <SettingsActivity >(SettingsActivity .class ,
31
- false /* Initial touch mode */ , true /* launch activity */ ) {
36
+ new ActivityTestRule <SettingsActivity >(SettingsActivity .class , false , true ) {
32
37
33
38
@ Override
34
39
protected void afterActivityLaunched () {
@@ -59,41 +64,31 @@ protected void afterActivityFinished() {
59
64
};
60
65
61
66
@ Test
62
- public void oneLicenseIsChecked () {
63
- // click "License" (the first item)
64
- Espresso .onData (PreferenceMatchers .withKey ("defaultLicense" ))
65
- .inAdapterView (ViewMatchers .withId (android .R .id .list ))
66
- .atPosition (0 )
67
- .perform (ViewActions .click ());
67
+ public void setRecentUploadLimitTo100 () {
68
+ // Open "Use external storage" preference
69
+ Espresso .onData (PreferenceMatchers .withKey ("uploads" ))
70
+ .inAdapterView (withId (android .R .id .list ))
71
+ .perform (click ());
68
72
69
- // test the selected item
70
- Espresso .onView (ViewMatchers .isChecked ())
71
- .check (ViewAssertions .matches (ViewMatchers .isDisplayed ()));
72
- }
73
+ // Try setting it to 100
74
+ Espresso .onView (withId (android .R .id .edit ))
73
75
74
- @ Test
75
- public void afterClickingCcby4ItWillStay () {
76
- // click "License" (the first item)
77
- Espresso .onData (PreferenceMatchers .withKey ("defaultLicense" ))
78
- .inAdapterView (ViewMatchers .withId (android .R .id .list ))
79
- .atPosition (0 )
80
- .perform (ViewActions .click ());
76
+ .perform (replaceText ("100" ));
81
77
82
- // click "Attribution 4.0"
83
- Espresso .onView (
84
- ViewMatchers .withText (R .string .license_name_cc_by_four )
85
- ).perform (ViewActions .click ());
78
+ // Click "OK"
79
+ Espresso .onView (allOf (withId (android .R .id .button1 ), withText ("OK" )))
80
+ .perform (click ());
86
81
87
- // click "License" (the first item)
88
- Espresso . onData ( PreferenceMatchers . withKey ( "defaultLicense" ))
89
- . inAdapterView ( ViewMatchers . withId ( android . R . id . list ))
90
- . atPosition ( 0 )
91
- . perform ( ViewActions . click () );
82
+ // Check setting set to 100 in SharedPreferences
83
+ assertEquals (
84
+ 100 ,
85
+ prefs . getInt ( Prefs . UPLOADS_SHOWING , 0 )
86
+ );
92
87
93
- // test the value remains "Attribution 4.0"
94
- Espresso .onView ( ViewMatchers . isChecked ( ))
95
- .check ( ViewAssertions . matches (
96
- ViewMatchers . withText ( R . string . license_name_cc_by_four )
97
- ));
88
+ // Check displaying 100 in summary text
89
+ Espresso .onData ( PreferenceMatchers . withKey ( "uploads" ))
90
+ .inAdapterView ( withId ( android . R . id . list ))
91
+ . onChildView ( withId ( android . R . id . summary ) )
92
+ . check ( matches ( withText ( "100" ) ));
98
93
}
99
94
}
0 commit comments