Skip to content
This repository was archived by the owner on Jul 25, 2024. It is now read-only.

Commit 29b2938

Browse files
kunall17niftynei
authored andcommitted
Modified LoginDevAuthTest to support the new login flow
1 parent 6612688 commit 29b2938

File tree

1 file changed

+45
-54
lines changed

1 file changed

+45
-54
lines changed
Lines changed: 45 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,89 +1,107 @@
11
package com.zulip.android.activities;
22

33

4-
import android.support.test.espresso.NoMatchingViewException;
5-
import android.support.test.espresso.ViewAssertion;
64
import android.support.test.espresso.ViewInteraction;
75
import android.support.test.espresso.matcher.BoundedMatcher;
86
import android.support.test.rule.ActivityTestRule;
97
import android.support.test.runner.AndroidJUnit4;
10-
import android.support.v7.widget.RecyclerView;
118
import android.test.suitebuilder.annotation.LargeTest;
129
import android.view.View;
1310
import android.widget.Button;
1411

1512
import com.zulip.android.R;
1613
import com.zulip.android.ZulipApp;
14+
import com.zulip.android.util.ZLog;
1715

1816
import org.hamcrest.Description;
1917
import org.hamcrest.Matcher;
2018
import org.hamcrest.Matchers;
21-
import org.junit.Before;
19+
import org.junit.FixMethodOrder;
2220
import org.junit.Rule;
2321
import org.junit.Test;
2422
import org.junit.runner.RunWith;
23+
import org.junit.runners.MethodSorters;
2524

2625
import static android.support.test.espresso.Espresso.onView;
2726
import static android.support.test.espresso.action.ViewActions.click;
28-
import static android.support.test.espresso.action.ViewActions.closeSoftKeyboard;
2927
import static android.support.test.espresso.action.ViewActions.replaceText;
3028
import static android.support.test.espresso.matcher.ViewMatchers.assertThat;
3129
import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed;
32-
import static android.support.test.espresso.matcher.ViewMatchers.withHint;
3330
import static android.support.test.espresso.matcher.ViewMatchers.withId;
34-
import static android.support.test.espresso.matcher.ViewMatchers.withParent;
3531
import static android.support.test.espresso.matcher.ViewMatchers.withText;
32+
import static com.zulip.android.helper.ViewAssertions.hasItemsCount;
3633
import static org.hamcrest.Matchers.is;
3734
import static org.hamcrest.core.AllOf.allOf;
3835

3936
@LargeTest
4037
@RunWith(AndroidJUnit4.class)
38+
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
4139
public class LoginDevAuthTest {
4240

4341
@Rule
4442
public ActivityTestRule<ZulipActivity> mActivityTestRule = new ActivityTestRule<>(ZulipActivity.class);
4543

4644
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+
4847

4948
// Convenience helper
5049
@Test
5150
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+
}
5260
getDevEmails();
5361
loginThroughDevMail();
5462
}
5563

56-
@Before
57-
public void setup() {
58-
closeSoftKeyboard();
59-
}
60-
61-
private void getDevEmails() {
6264

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+
}
7071

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));
7475

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());
7679

7780
//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());
8083

8184
//Check if there are Emails
8285
onView(withId(R.id.devAuthRecyclerView)).check(hasItemsCount());
8386
}
8487

8588
private static boolean matchedBefore = false;
8689

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+
87105
//This filter returns only one View!
88106
private Matcher<View> emailFilter() {
89107

@@ -106,31 +124,4 @@ protected boolean matchesSafely(Button item) {
106124
}
107125

108126

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-
}
136127
}

0 commit comments

Comments
 (0)