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.junit.Assert.assertNotNull;
22 import static org.junit.Assert.assertThat;
23
24 import java.util.ArrayList;
25
26 import org.exoplatform.R;
27 import org.exoplatform.model.ExoAccount;
28 import org.exoplatform.singleton.AccountSetting;
29 import org.exoplatform.singleton.ServerSettingHelper;
30 import org.exoplatform.ui.WelcomeActivity;
31 import org.exoplatform.ui.setting.CheckBox;
32 import org.exoplatform.ui.setting.CheckBoxWithImage;
33 import org.exoplatform.ui.setting.ServerEditionActivity;
34 import org.exoplatform.ui.setting.ServerList;
35 import org.exoplatform.ui.setting.SettingActivity;
36 import org.exoplatform.utils.ExoConstants;
37 import org.exoplatform.utils.SettingUtils;
38 import org.exoplatform.widget.ServerItemLayout;
39 import org.junit.Before;
40 import org.junit.Test;
41 import org.junit.runner.RunWith;
42 import org.robolectric.Robolectric;
43 import org.robolectric.Shadows;
44 import org.robolectric.shadows.ShadowActivity;
45 import org.robolectric.shadows.ShadowApplication;
46 import org.robolectric.shadows.ShadowIntent;
47 import org.robolectric.shadows.ShadowView;
48
49 import android.content.Intent;
50 import android.content.SharedPreferences;
51 import android.widget.Button;
52 import android.widget.TextView;
53
54
55
56
57
58 @RunWith(ExoRobolectricTestRunner.class)
59 public class SettingsActivityTest extends ExoActivityTestUtils<SettingActivity> {
60
61 final String SRV_VERSION = "4.0.0";
62
63 final String SRV_EDITION = "Enterprise";
64
65 final String APP_VERSION = "2.5.0";
66
67 CheckBox mRememberMeCbx;
68
69 CheckBox mAutoLoginCbx;
70
71 CheckBoxWithImage mEnCbx, mFrCbx, mDeCbx, mEsCbx, mPtBrCbx, mElCbx;
72
73 CheckBox mRememberFilterCbx;
74
75 ServerList serverList;
76
77
78 Button mStartCloudSignUpBtn;
79
80 ServerSettingHelper srvSettings;
81
82
83
84
85
86
87 public void createWithDefaultIntent(boolean online) {
88 initSettings();
89 Intent i = new Intent(ShadowApplication.getInstance().getApplicationContext(), SettingActivity.class);
90 int settingType = online ? SettingActivity.PERSONAL_TYPE : SettingActivity.GLOBAL_TYPE;
91 i.putExtra(ExoConstants.SETTING_TYPE, settingType);
92
93 createWithIntent(i);
94 init();
95 }
96
97 private void initSettings() {
98
99 srvSettings = ServerSettingHelper.getInstance();
100 ExoAccount srv = getServerWithDefaultValues();
101 ArrayList<ExoAccount> list = new ArrayList<ExoAccount>();
102 list.add(srv);
103 srvSettings.setServerInfoList(list);
104 SettingUtils.persistServerSetting(ShadowApplication.getInstance().getApplicationContext());
105 AccountSetting.getInstance().setCurrentAccount(srv);
106 AccountSetting.getInstance().setDomainIndex("0");
107
108
109 srvSettings.setServerVersion(SRV_VERSION);
110 srvSettings.setServerEdition(SRV_EDITION);
111 srvSettings.setApplicationVersion(APP_VERSION);
112 }
113
114 private void init() {
115
116 mRememberMeCbx = (CheckBox) activity.findViewById(R.id.setting_remember_me_ckb);
117 mAutoLoginCbx = (CheckBox) activity.findViewById(R.id.setting_autologin_ckb);
118
119
120 mEnCbx = (CheckBoxWithImage) activity.findViewById(R.id.setting_en_ckb);
121 mFrCbx = (CheckBoxWithImage) activity.findViewById(R.id.setting_fr_ckb);
122 mDeCbx = (CheckBoxWithImage) activity.findViewById(R.id.setting_de_ckb);
123 mEsCbx = (CheckBoxWithImage) activity.findViewById(R.id.setting_es_ckb);
124 mPtBrCbx = (CheckBoxWithImage) activity.findViewById(R.id.setting_pt_br_ckb);
125 mElCbx = (CheckBoxWithImage) activity.findViewById(R.id.setting_el_ckb);
126
127
128 mRememberFilterCbx = (CheckBox) activity.findViewById(R.id.setting_remember_filter_ckb);
129
130
131 mStartCloudSignUpBtn = (Button) activity.findViewById(R.id.setting_new_account_btn);
132
133
134 serverList = (ServerList) activity.findViewById(R.id.setting_list_accounts);
135 }
136
137 @Override
138 @Before
139 public void setup() {
140 controller = Robolectric.buildActivity(SettingActivity.class);
141 }
142
143 @Test
144 public void verifyDefaultLayout_Online() {
145 createWithDefaultIntent(true);
146
147
148 assertNotNull(mRememberMeCbx);
149 assertNotNull(mAutoLoginCbx);
150 assertThat("Remember Me should be disabled", mRememberMeCbx.isChecked(), equalTo(false));
151 assertThat("Auto Login should be disabled", mAutoLoginCbx.isEnabled(), equalTo(false));
152
153
154 assertThat("Auto Login should be disabled", mAutoLoginCbx.isChecked(), equalTo(false));
155
156
157 assertNotNull(mEnCbx);
158 assertThat(mEnCbx.isChecked(), equalTo(true));
159
160 assertNotNull(mFrCbx);
161 assertThat(mFrCbx.isChecked(), equalTo(false));
162 assertNotNull(mDeCbx);
163 assertThat(mDeCbx.isChecked(), equalTo(false));
164 assertNotNull(mEsCbx);
165 assertThat(mEsCbx.isChecked(), equalTo(false));
166 assertNotNull(mPtBrCbx);
167 assertThat(mPtBrCbx.isChecked(), equalTo(false));
168 assertNotNull(mElCbx);
169 assertThat(mElCbx.isChecked(), equalTo(false));
170
171
172 assertNotNull(mRememberFilterCbx);
173
174
175 assertThat(srvSettings.getServerInfoList(activity).size(), equalTo(1));
176 assertThat(serverList).hasChildCount(1);
177 ServerItemLayout serverItem = (ServerItemLayout) serverList.getChildAt(0);
178 assertThat(serverItem.serverName).containsText(TEST_SERVER_NAME);
179 assertThat(serverItem.serverUrl).containsText(TEST_SERVER_URL);
180
181
182 assertNotNull(mStartCloudSignUpBtn);
183
184
185
186 TextView srvVersion = (TextView) activity.findViewById(R.id.setting_server_version_value_txt);
187 TextView srvEdition = (TextView) activity.findViewById(R.id.setting_server_edition_value_txt);
188 TextView appVersion = (TextView) activity.findViewById(R.id.setting_app_version_value_txt);
189 assertThat(appVersion).containsText(APP_VERSION);
190 assertThat(srvVersion).containsText(SRV_VERSION);
191 assertThat(srvEdition).containsText(SRV_EDITION);
192
193 }
194
195 @Test
196 public void verifyDefaultLayout_Offline() {
197 createWithDefaultIntent(false);
198
199
200 assertThat(mRememberMeCbx).isGone();
201 assertThat(mAutoLoginCbx).isGone();
202
203
204 assertNotNull(mEnCbx);
205 assertThat(mEnCbx.isChecked(), equalTo(true));
206
207 assertNotNull(mFrCbx);
208 assertThat(mFrCbx.isChecked(), equalTo(false));
209 assertNotNull(mDeCbx);
210 assertThat(mDeCbx.isChecked(), equalTo(false));
211 assertNotNull(mEsCbx);
212 assertThat(mEsCbx.isChecked(), equalTo(false));
213 assertNotNull(mPtBrCbx);
214 assertThat(mPtBrCbx.isChecked(), equalTo(false));
215 assertNotNull(mElCbx);
216 assertThat(mElCbx.isChecked(), equalTo(false));
217
218
219 assertThat(mRememberFilterCbx).isGone();
220
221
222 assertThat(srvSettings.getServerInfoList(activity).size(), equalTo(1));
223 assertThat(serverList).hasChildCount(1);
224 ServerItemLayout serverItem = (ServerItemLayout) serverList.getChildAt(0);
225 assertThat(serverItem.serverName).containsText(TEST_SERVER_NAME);
226 assertThat(serverItem.serverUrl).containsText(TEST_SERVER_URL);
227
228
229 assertNotNull(mStartCloudSignUpBtn);
230
231
232
233 TextView srvVersion = (TextView) activity.findViewById(R.id.setting_server_version_value_txt);
234 TextView srvEdition = (TextView) activity.findViewById(R.id.setting_server_edition_value_txt);
235 TextView appVersion = (TextView) activity.findViewById(R.id.setting_app_version_value_txt);
236 assertThat(appVersion).containsText(APP_VERSION);
237 assertThat(srvVersion).containsText(SRV_VERSION);
238 assertThat(srvEdition).containsText(SRV_EDITION);
239
240 }
241
242 @Test
243 public void shouldTurnOnRememberMe() {
244
245 createWithDefaultIntent(true);
246
247 ShadowView.clickOn(mRememberMeCbx);
248
249 assertThat("RM should be checked", mRememberMeCbx.isChecked(), equalTo(true));
250 }
251
252 @Test
253 public void shouldEnableAutoLoginWhenTurningOnRememberMe() {
254
255 createWithDefaultIntent(true);
256
257 ShadowView.clickOn(mRememberMeCbx);
258
259 assertThat("AL checkbox should be enabled", mAutoLoginCbx.isEnabled(), equalTo(true));
260 assertThat("AL should be unchecked", mAutoLoginCbx.isChecked(), equalTo(false));
261
262 }
263
264 @Test
265 public void shouldTurnOnAutoLogin() {
266
267 createWithDefaultIntent(true);
268
269 ShadowView.clickOn(mRememberMeCbx);
270 ShadowView.clickOn(mAutoLoginCbx);
271
272 assertThat("AL should be checked", mAutoLoginCbx.isChecked(), equalTo(true));
273 }
274
275 @Test
276 public void shouldTurnOffAndDisableAutoLoginWhenTurningOffRememberMe() {
277
278 createWithDefaultIntent(true);
279
280 ShadowView.clickOn(mRememberMeCbx);
281 ShadowView.clickOn(mAutoLoginCbx);
282
283 assertThat(mAutoLoginCbx.isEnabled(), equalTo(true));
284 assertThat(mAutoLoginCbx.isChecked(), equalTo(true));
285
286 ShadowView.clickOn(mRememberMeCbx);
287
288 assertThat("RM should be unchecked", mRememberMeCbx.isChecked(), equalTo(false));
289 assertThat("AL should be disabled", mAutoLoginCbx.isEnabled(), equalTo(false));
290 assertThat("AL should be unchecked", mAutoLoginCbx.isChecked(), equalTo(false));
291
292 }
293
294 @Test
295 public void shouldStartExoCloudSignupAssistant() {
296
297 createWithDefaultIntent(true);
298
299 ShadowView.clickOn(mStartCloudSignUpBtn);
300
301 ShadowActivity sActivity = Shadows.shadowOf(activity);
302 Intent welcomeIntent = sActivity.getNextStartedActivity();
303 ShadowIntent sIntent = Shadows.shadowOf(welcomeIntent);
304
305 assertThat(sIntent.getComponent().getClassName(), equalTo(WelcomeActivity.class.getName()));
306
307 }
308
309 @Test
310 public void shouldChangeLanguage() {
311
312 createWithDefaultIntent(true);
313
314 SharedPreferences prefs = activity.getSharedPreferences(ExoConstants.EXO_PREFERENCE, 0);
315
316 ShadowView.clickOn(mDeCbx);
317
318 assertThat("English should be OFF", mEnCbx.isChecked(), equalTo(false));
319 assertThat("German should be ON", mDeCbx.isChecked(), equalTo(true));
320 assertThat(prefs.getString(ExoConstants.EXO_PRF_LOCALIZE, ""), equalTo(ExoConstants.GERMAN_LOCALIZATION));
321
322 ShadowView.clickOn(mFrCbx);
323
324 assertThat("German should be OFF", mDeCbx.isChecked(), equalTo(false));
325 assertThat("French should be ON", mFrCbx.isChecked(), equalTo(true));
326 assertThat(prefs.getString(ExoConstants.EXO_PRF_LOCALIZE, ""), equalTo(ExoConstants.FRENCH_LOCALIZATION));
327
328 ShadowView.clickOn(mEsCbx);
329
330 assertThat("French should be OFF", mFrCbx.isChecked(), equalTo(false));
331 assertThat("Spanish should be ON", mEsCbx.isChecked(), equalTo(true));
332 assertThat(prefs.getString(ExoConstants.EXO_PRF_LOCALIZE, ""), equalTo(ExoConstants.SPANISH_LOCALIZATION));
333
334 ShadowView.clickOn(mPtBrCbx);
335
336 assertThat("Spanish should be OFF", mEsCbx.isChecked(), equalTo(false));
337 assertThat("Portuguese should be ON", mPtBrCbx.isChecked(), equalTo(true));
338 assertThat(prefs.getString(ExoConstants.EXO_PRF_LOCALIZE, ""), equalTo(ExoConstants.BRAZIL_LOCALIZATION));
339
340 ShadowView.clickOn(mElCbx);
341
342 assertThat("Portuguese should be OFF", mPtBrCbx.isChecked(), equalTo(false));
343 assertThat("Greek should be ON", mElCbx.isChecked(), equalTo(true));
344 assertThat(prefs.getString(ExoConstants.EXO_PRF_LOCALIZE, ""), equalTo(ExoConstants.GREEK_LOCALIZATION));
345
346 ShadowView.clickOn(mEnCbx);
347
348 assertThat("Greek should be OFF", mElCbx.isChecked(), equalTo(false));
349 assertThat("English should be ON", mEnCbx.isChecked(), equalTo(true));
350 assertThat(prefs.getString(ExoConstants.EXO_PRF_LOCALIZE, ""), equalTo(ExoConstants.ENGLISH_LOCALIZATION));
351 }
352
353 @Test
354 public void shouldEnableAccountInServerList() {
355 createWithDefaultIntent(true);
356
357 assertThat(serverList).hasChildCount(1);
358
359
360 ServerItemLayout item = (ServerItemLayout) serverList.getChildAt(0);
361
362 ShadowView.clickOn(item.layout);
363
364 ShadowActivity sActivity = Shadows.shadowOf(activity);
365 Intent editAccount = sActivity.getNextStartedActivity();
366 ShadowIntent sIntent = Shadows.shadowOf(editAccount);
367
368
369 assertThat("Should start the server edition activity",
370 sIntent.getComponent().getClassName(),
371 equalTo(ServerEditionActivity.class.getName()));
372 }
373
374 }