1
1
package com .zulip .android .activities ;
2
2
3
3
4
- import android .support .test .espresso .NoMatchingViewException ;
5
- import android .support .test .espresso .ViewAssertion ;
6
4
import android .support .test .espresso .ViewInteraction ;
7
5
import android .support .test .espresso .matcher .BoundedMatcher ;
8
6
import android .support .test .rule .ActivityTestRule ;
9
7
import android .support .test .runner .AndroidJUnit4 ;
10
- import android .support .v7 .widget .RecyclerView ;
11
8
import android .test .suitebuilder .annotation .LargeTest ;
12
9
import android .view .View ;
13
10
import android .widget .Button ;
14
11
15
12
import com .zulip .android .R ;
16
13
import com .zulip .android .ZulipApp ;
14
+ import com .zulip .android .util .ZLog ;
17
15
18
16
import org .hamcrest .Description ;
19
17
import org .hamcrest .Matcher ;
20
18
import org .hamcrest .Matchers ;
21
- import org .junit .Before ;
19
+ import org .junit .FixMethodOrder ;
22
20
import org .junit .Rule ;
23
21
import org .junit .Test ;
24
22
import org .junit .runner .RunWith ;
23
+ import org .junit .runners .MethodSorters ;
25
24
26
25
import static android .support .test .espresso .Espresso .onView ;
27
26
import static android .support .test .espresso .action .ViewActions .click ;
28
- import static android .support .test .espresso .action .ViewActions .closeSoftKeyboard ;
29
27
import static android .support .test .espresso .action .ViewActions .replaceText ;
30
28
import static android .support .test .espresso .matcher .ViewMatchers .assertThat ;
31
29
import static android .support .test .espresso .matcher .ViewMatchers .isDisplayed ;
32
- import static android .support .test .espresso .matcher .ViewMatchers .withHint ;
33
30
import static android .support .test .espresso .matcher .ViewMatchers .withId ;
34
- import static android .support .test .espresso .matcher .ViewMatchers .withParent ;
35
31
import static android .support .test .espresso .matcher .ViewMatchers .withText ;
32
+ import static com .zulip .android .helper .ViewAssertions .hasItemsCount ;
36
33
import static org .hamcrest .Matchers .is ;
37
34
import static org .hamcrest .core .AllOf .allOf ;
38
35
39
36
@ LargeTest
40
37
@ RunWith (AndroidJUnit4 .class )
38
+ @ FixMethodOrder (MethodSorters .NAME_ASCENDING )
41
39
public class LoginDevAuthTest {
42
40
43
41
@ Rule
44
42
public ActivityTestRule <ZulipActivity > mActivityTestRule = new ActivityTestRule <>(ZulipActivity .class );
45
43
46
44
private static String EMAIL_TEST = "" ;
47
- private static String SERVER_URL = "http://10.0.3.2:9991/api/" ;
45
+ private static String SERVER_URL = "http://www.local.test.com" ;
46
+
48
47
49
48
// Convenience helper
50
49
@ Test
51
50
public void TestSerially () {
51
+ if (!ZulipApp .get ().getApiKey ().isEmpty ()) {
52
+ BaseTest baseTest = new BaseTest ();
53
+ baseTest .logout ();
54
+ try {
55
+ Thread .sleep (2000 );
56
+ } catch (InterruptedException e ) {
57
+ ZLog .logException (e );
58
+ }
59
+ }
52
60
getDevEmails ();
53
61
loginThroughDevMail ();
54
62
}
55
63
56
- @ Before
57
- public void setup () {
58
- closeSoftKeyboard ();
59
- }
60
-
61
- private void getDevEmails () {
62
64
63
- closeSoftKeyboard ();
64
- //Uncheck Checkbox
65
- ViewInteraction checkBox = onView (
66
- allOf (withId (R .id .checkbox_usezulip ), withText ("Use Zulip.com" ),
67
- withParent (withId (R .id .server )),
68
- isDisplayed ()));
69
- checkBox .perform (click ());
65
+ public void getDevEmails () {
66
+ try {
67
+ Thread .sleep (1000 );
68
+ } catch (InterruptedException e ) {
69
+ e .printStackTrace ();
70
+ }
70
71
71
- //Give a Server URL
72
- ViewInteraction editText = onView (allOf (withId (R .id .server_url ), withHint ( R . string . server_domain ), withParent ( withId ( R . id . server ) ), isDisplayed ()));
73
- editText .perform (replaceText (SERVER_URL ));
72
+ //Fill Server URL
73
+ ViewInteraction serverURLInteraction = onView (Matchers . allOf (withId (R .id .server_url_in ), isDisplayed ()));
74
+ serverURLInteraction .perform (replaceText (SERVER_URL ));
74
75
75
- closeSoftKeyboard ();
76
+ //Click Enter server URL
77
+ ViewInteraction enterServerUrl = onView (Matchers .allOf (withId (R .id .server_btn ), withText (R .string .enter ), isDisplayed ()));
78
+ enterServerUrl .perform (click ());
76
79
77
80
//Click DevAuth TextView Button
78
- ViewInteraction textView = onView (allOf (withId (R .id .local_server_button ), withText ("Dev Backend testing server" ), isDisplayed ()));
79
- textView .perform (click ());
81
+ ViewInteraction devServerTextViewInteraction = onView (allOf (withId (R .id .local_server_button ), withText (R . string . local_server ), isDisplayed ()));
82
+ devServerTextViewInteraction .perform (click ());
80
83
81
84
//Check if there are Emails
82
85
onView (withId (R .id .devAuthRecyclerView )).check (hasItemsCount ());
83
86
}
84
87
85
88
private static boolean matchedBefore = false ;
86
89
90
+ private void loginThroughDevMail () {
91
+ //If EMAIL not specified click on first EMAIL.
92
+ if (EMAIL_TEST .equals ("" )) {
93
+ onView (allOf (withId (android .R .id .text1 ), emailFilter ())).perform (click ());
94
+ } else {
95
+ //Find and click the E-Mail Button.
96
+ ViewInteraction button = onView (Matchers .allOf (withId (android .R .id .text1 ), withText (EMAIL_TEST ), isDisplayed ()));
97
+ button .perform (click ());
98
+ }
99
+
100
+ //Verify Correct E-Mail is Stored
101
+ assertThat (ZulipApp .get ().getEmail (), is (EMAIL_TEST ));
102
+ }
103
+
104
+
87
105
//This filter returns only one View!
88
106
private Matcher <View > emailFilter () {
89
107
@@ -106,31 +124,4 @@ protected boolean matchesSafely(Button item) {
106
124
}
107
125
108
126
109
- private void loginThroughDevMail () {
110
-
111
- //If EMAIL not specified click on first EMAIL.
112
- if (EMAIL_TEST .equals ("" )) {
113
- onView (allOf (withId (android .R .id .text1 ), emailFilter ())).perform (click ());
114
- } else {
115
- //Find and click the E-Mail Button.
116
- ViewInteraction button = onView (Matchers .allOf (withId (android .R .id .text1 ), withText (EMAIL_TEST ), isDisplayed ()));
117
- button .perform (click ());
118
- }
119
-
120
- //Verify Correct E-Mail is Stored
121
- assertThat (ZulipApp .get ().getEmail (), is (EMAIL_TEST ));
122
- }
123
-
124
- private static ViewAssertion hasItemsCount () {
125
- return new ViewAssertion () {
126
- @ Override
127
- public void check (View view , NoMatchingViewException e ) {
128
- if (!(view instanceof RecyclerView )) {
129
- throw e ;
130
- }
131
- RecyclerView rv = (RecyclerView ) view ;
132
- assertThat ("Items less than 2, which means no E-Mails!" , rv .getAdapter ().getItemCount (), Matchers .greaterThan (2 ));
133
- }
134
- };
135
- }
136
127
}
0 commit comments