1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.exoplatform.mobile.tests;
18
19 import static org.fest.assertions.api.ANDROID.assertThat;
20 import static org.hamcrest.CoreMatchers.equalTo;
21 import static org.robolectric.Shadows.shadowOf;
22
23 import org.exoplatform.R;
24 import org.exoplatform.ui.CirclePageIndicator;
25 import org.exoplatform.ui.SignInActivity;
26 import org.exoplatform.ui.SignUpActivity;
27 import org.exoplatform.ui.WelcomeActivity;
28 import org.exoplatform.ui.login.LoginActivity;
29 import org.junit.Before;
30 import org.junit.Test;
31 import org.junit.runner.RunWith;
32 import org.robolectric.Robolectric;
33 import org.robolectric.shadows.ShadowActivity;
34 import org.robolectric.shadows.ShadowIntent;
35 import org.robolectric.shadows.ShadowView;
36
37 import android.content.Intent;
38 import android.content.res.Resources;
39 import android.os.Bundle;
40 import android.support.v4.view.ViewPager;
41 import android.widget.Button;
42 import android.widget.TextView;
43
44
45
46
47
48 @RunWith(ExoRobolectricTestRunner.class)
49 public class WelcomeActivityTest extends ExoActivityTestUtils<WelcomeActivity> {
50
51 Resources res;
52
53 Button btnLogin, btnSignUp;
54
55 TextView skipTxt;
56
57 ViewPager pager;
58
59 CirclePageIndicator indicator;
60
61 @Before
62 public void setup() {
63 controller = Robolectric.buildActivity(WelcomeActivity.class);
64 }
65
66 @Override
67 public void create() {
68 super.create();
69 init();
70 }
71
72 @Override
73 public void createWithBundle(Bundle b) {
74 super.createWithBundle(b);
75 init();
76 }
77
78 private void init() {
79 res = activity.getResources();
80 btnLogin = (Button) activity.findViewById(R.id.welcome_btn_login);
81 btnSignUp = (Button) activity.findViewById(R.id.welcome_btn_signup);
82 skipTxt = (TextView) activity.findViewById(R.id.welcome_txt_skipStep);
83 pager = (ViewPager) activity.findViewById(org.exoplatform.R.id.pager);
84 indicator = (CirclePageIndicator) activity.findViewById(R.id.circle_page_indicator);
85 }
86
87 @Test
88 public void verifyDefaultLayout() {
89 create();
90
91 assertThat(pager.getAdapter()).hasCount(5);
92
93
94 assertThat(btnLogin).containsText(R.string.LogIn);
95 org.junit.Assert.assertThat(res.getString(R.string.LogIn), equalTo("Log In"));
96
97
98 assertThat(btnSignUp).containsText(R.string.SignUp);
99 org.junit.Assert.assertThat(res.getString(R.string.SignUp), equalTo("Sign Up"));
100
101 assertThat(skipTxt).containsText(R.string.SkipStep);
102 org.junit.Assert.assertThat(res.getString(R.string.SkipStep), equalTo("or skip this for now"));
103
104 }
105
106 @Test
107 public void shouldRedirectToSignInScreen() {
108 create();
109
110 ShadowView.clickOn(btnLogin);
111 ShadowActivity shadowActivity = shadowOf(activity);
112 Intent startedIntent = shadowActivity.getNextStartedActivity();
113 ShadowIntent shadowIntent = shadowOf(startedIntent);
114 org.junit.Assert.assertThat(shadowIntent.getComponent().getClassName(), equalTo(SignInActivity.class.getName()));
115 }
116
117 @Test
118 public void shouldRedirectToSignUpScreen() {
119 create();
120
121 ShadowView.clickOn(btnSignUp);
122 ShadowActivity shadowActivity = shadowOf(activity);
123 Intent startedIntent = shadowActivity.getNextStartedActivity();
124 ShadowIntent shadowIntent = shadowOf(startedIntent);
125 org.junit.Assert.assertThat(shadowIntent.getComponent().getClassName(), equalTo(SignUpActivity.class.getName()));
126 }
127
128 @Test
129 public void shouldRedirectToLoginScreen() {
130 create();
131
132 ShadowView.clickOn(skipTxt);
133 ShadowActivity shadowActivity = shadowOf(activity);
134 Intent startedIntent = shadowActivity.getNextStartedActivity();
135 ShadowIntent shadowIntent = shadowOf(startedIntent);
136 org.junit.Assert.assertThat(shadowIntent.getComponent().getClassName(), equalTo(LoginActivity.class.getName()));
137 }
138
139 @Test
140 public void shouldSaveInstanceState() {
141 create();
142
143 Bundle bundle = new Bundle();
144 bundle.putInt("CURRENT_SLIDER", -1);
145
146
147
148 controller.saveInstanceState(bundle);
149
150
151
152 org.junit.Assert.assertThat(bundle.getInt("CURRENT_SLIDER"), equalTo(0));
153
154 }
155
156 @Test
157 public void shoudRetrieveInstanceState() {
158 Bundle bundle = new Bundle();
159 bundle.putInt("CURRENT_SLIDER", 1);
160
161 createWithBundle(bundle);
162
163 assertThat(pager).hasCurrentItem(1);
164
165 }
166
167 }