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 import static org.junit.Assert.assertTrue;
24
25 import java.util.ArrayList;
26
27 import org.exoplatform.R;
28 import org.exoplatform.controller.home.HomeController;
29 import org.exoplatform.singleton.AccountSetting;
30 import org.exoplatform.singleton.SocialServiceHelper;
31 import org.exoplatform.ui.social.ActivityStreamFragment;
32 import org.exoplatform.ui.social.AllUpdatesFragment;
33 import org.exoplatform.ui.social.SocialTabsActivity;
34 import org.exoplatform.ui.social.TabPageIndicator;
35 import org.robolectric.Robolectric;
36 import org.robolectric.Shadows;
37 import org.robolectric.shadows.ShadowActivity;
38 import org.robolectric.shadows.ShadowLooper;
39 import org.robolectric.shadows.ShadowView;
40 import org.robolectric.shadows.httpclient.FakeHttp;
41
42 import android.app.ActionBar;
43 import android.os.Bundle;
44 import android.support.v4.app.FragmentManager;
45 import android.support.v4.view.ViewPager;
46 import android.view.View;
47 import android.widget.LinearLayout;
48 import android.widget.TextView;
49
50
51
52
53
54
55 public class SocialTabsActivityTest extends ExoActivityTestUtils<SocialTabsActivity> {
56
57 private static final String FRAGMENT_TAG = "fragment";
58
59 TabPageIndicator tabs;
60
61 ViewPager pages;
62
63 ActionBar actionBar;
64
65 ActivityStreamFragment fragment;
66
67 @Override
68
69 public void setup() {
70 controller = Robolectric.buildActivity(SocialTabsActivity.class);
71
72
73 FakeHttp.addHttpResponseRule(getMatcherForRequest(REQ_SOCIAL_VERSION_LATEST),
74 getResponseOKForRequest(REQ_SOCIAL_VERSION_LATEST));
75
76
77 FakeHttp.addHttpResponseRule(getMatcherForRequest(REQ_SOCIAL_IDENTITY), getResponseOKForRequest(REQ_SOCIAL_IDENTITY));
78
79
80 FakeHttp.addHttpResponseRule(getMatcherForRequest(REQ_SOCIAL_IDENTITY_2), getResponseOKForRequest(REQ_SOCIAL_IDENTITY_2));
81
82
83 FakeHttp.addHttpResponseRule(getMatcherForRequest(REQ_SOCIAL_NEWS), getResponseOKForRequest(REQ_SOCIAL_NEWS));
84
85
86 FakeHttp.addHttpResponseRule(getMatcherForRequest(REQ_SOCIAL_ALL_UPDATES), getResponseOKForRequest(REQ_SOCIAL_ALL_UPDATES));
87
88
89 FakeHttp.addHttpResponseRule(getMatcherForRequest(REQ_SOCIAL_MY_CONNECTIONS),
90 getResponseOKForRequest(REQ_SOCIAL_MY_CONNECTIONS));
91 }
92
93 private void init() {
94
95 tabs = (TabPageIndicator) activity.findViewById(R.id.indicator);
96 pages = (ViewPager) activity.findViewById(R.id.pager);
97 actionBar = activity.getActionBar();
98
99 }
100
101 private void startFragment() {
102 FragmentManager manager = activity.getSupportFragmentManager();
103 manager.beginTransaction().add(fragment, FRAGMENT_TAG).commit();
104 }
105
106 private Bundle createBundleWithDefaultSettings() {
107 Bundle b = new Bundle();
108 AccountSetting s = AccountSetting.getInstance();
109 s.setCurrentAccount(getServerWithDefaultValues());
110 s.cookiesList = new ArrayList<String>();
111 b.putParcelable("account_setting", s);
112 return b;
113 }
114
115
116 public void verifyDefaultLayout() {
117 create();
118 init();
119
120
121 assertTrue("Action bar should contain 2 menu items", actionBar.getNavigationItemCount() == 2);
122
123
124
125
126
127
128
129
130 assertThat(pages.getAdapter()).hasCount(4);
131 assertThat("Default tab should be All Updates", pages.getCurrentItem(), equalTo(SocialTabsActivity.ALL_UPDATES));
132
133 LinearLayout tabsLayout = (LinearLayout) tabs.getChildAt(0);
134
135 String[] tabsTitle = activity.getResources().getStringArray(R.array.SocialTabs);
136 assertThat((TextView) tabsLayout.getChildAt(SocialTabsActivity.ALL_UPDATES)).containsText(tabsTitle[SocialTabsActivity.ALL_UPDATES]);
137 assertThat((TextView) tabsLayout.getChildAt(SocialTabsActivity.MY_CONNECTIONS)).containsText(tabsTitle[SocialTabsActivity.MY_CONNECTIONS]);
138 assertThat((TextView) tabsLayout.getChildAt(SocialTabsActivity.MY_SPACES)).containsText(tabsTitle[SocialTabsActivity.MY_SPACES]);
139 assertThat((TextView) tabsLayout.getChildAt(SocialTabsActivity.MY_STATUS)).containsText(tabsTitle[SocialTabsActivity.MY_STATUS]);
140
141 }
142
143
144 public void shouldMoveToOtherPage() {
145 create();
146 init();
147
148 tabs.setCurrentItem(SocialTabsActivity.ALL_UPDATES);
149 assertThat("Should be on All Updates tab", pages.getCurrentItem(), equalTo(SocialTabsActivity.ALL_UPDATES));
150
151
152
153
154 tabs.setCurrentItem(SocialTabsActivity.MY_CONNECTIONS);
155 assertThat("Should be on My Connections tab", pages.getCurrentItem(), equalTo(SocialTabsActivity.MY_CONNECTIONS));
156
157
158
159
160 LinearLayout tabsLayout = (LinearLayout) tabs.getChildAt(0);
161
162 ShadowView.clickOn((View) tabsLayout.getChildAt(SocialTabsActivity.MY_SPACES));
163 assertThat("Should be on My Spaces tab", pages.getCurrentItem(), equalTo(SocialTabsActivity.MY_SPACES));
164
165
166
167
168 }
169
170
171 public void shouldFinishActivity() {
172 create();
173 init();
174
175
176
177
178 View homeBtn = actionBar.getTabAt(0).getCustomView();
179 ShadowView.clickOn(homeBtn);
180
181 ShadowActivity sActivity = Shadows.shadowOf(activity);
182
183 assertTrue("Activity should be finishing", sActivity.isFinishing());
184 }
185
186
187
188
189
190
191 public void shouldLoadAllUpdatesFragment() {
192 createWithBundle(createBundleWithDefaultSettings());
193 init();
194
195 HomeController c = new HomeController(activity);
196
197 c.launchNewsService();
198
199 fragment = AllUpdatesFragment.getInstance();
200
201
202
203 ShadowLooper.runUiThreadTasksIncludingDelayedTasks();
204
205 assertThat("Fragment ID should be ALL_UPDATES",
206 ((AllUpdatesFragment) fragment).getThisTabId(),
207 equalTo(SocialTabsActivity.ALL_UPDATES));
208 assertNotNull("SocialServiceHelper should not be null", SocialServiceHelper.getInstance());
209
210 assertNotNull("Social Info List should not be null", SocialServiceHelper.getInstance().socialInfoList);
211 assertThat("Social Info List should contain 2 items", SocialServiceHelper.getInstance().socialInfoList.size(), equalTo(2));
212
213 FakeHttp.clearPendingHttpResponses();
214 }
215
216 }