|
@@ -27,318 +27,318 @@ import static org.mockito.Mockito.when;
|
27
|
27
|
|
28
|
28
|
public class LayoutFactoryTest extends BaseTest {
|
29
|
29
|
|
30
|
|
- private final static String NODE_ID = "myUniqueId";
|
31
|
|
- private final static String REACT_ROOT_VIEW_KEY = "myName";
|
32
|
|
-
|
33
|
|
- private final static String OTHER_NODE_ID = "anotherUniqueId";
|
34
|
|
- private final static String OTHER_REACT_ROOT_VIEW_KEY = "anotherName";
|
35
|
|
-
|
36
|
|
- private Activity activity;
|
37
|
|
- private View mockView;
|
38
|
|
- private View otherMockView;
|
39
|
|
- private LayoutFactory.ReactRootViewCreator reactRootViewCreator;
|
40
|
|
-
|
41
|
|
- @Before
|
42
|
|
- public void setUp() {
|
43
|
|
- activity = Robolectric.buildActivity(AppCompatActivity.class).get();
|
44
|
|
- mockView = new View(activity);
|
45
|
|
- otherMockView = new View(activity);
|
46
|
|
- reactRootViewCreator = mock(LayoutFactory.ReactRootViewCreator.class);
|
47
|
|
- }
|
48
|
|
-
|
49
|
|
- @Test
|
50
|
|
- public void returnsContainerThatHoldsTheRootView() throws Exception {
|
51
|
|
- when(reactRootViewCreator.create(eq(NODE_ID), eq(REACT_ROOT_VIEW_KEY))).thenReturn(mockView);
|
52
|
|
- final LayoutNode node = createContainerNode();
|
53
|
|
-
|
54
|
|
- final ViewGroup result = (ViewGroup) createLayoutFactory().create(node);
|
55
|
|
-
|
56
|
|
- assertThat(result).isInstanceOf(Container.class);
|
57
|
|
- TestUtils.assertViewChildren(result, mockView);
|
58
|
|
- }
|
59
|
|
-
|
60
|
|
- @Test
|
61
|
|
- public void returnsContainerStack() throws Exception {
|
62
|
|
- when(reactRootViewCreator.create(eq(NODE_ID), eq(REACT_ROOT_VIEW_KEY))).thenReturn(mockView);
|
63
|
|
- final LayoutNode containerNode = createContainerNode();
|
64
|
|
- final LayoutNode stackNode = createContainerStackNode(containerNode);
|
65
|
|
-
|
66
|
|
- final ViewGroup result = (ViewGroup) createLayoutFactory().create(stackNode);
|
67
|
|
-
|
68
|
|
- assertThat(result).isInstanceOf(ContainerStackLayout.class);
|
69
|
|
- ViewGroup container = (ViewGroup) TestUtils.assertViewChildrenCount(result, 1).get(0);
|
70
|
|
- TestUtils.assertViewChildren(container, mockView);
|
71
|
|
- }
|
72
|
|
-
|
73
|
|
- @Test
|
74
|
|
- public void returnsContainerStackWithMultipleViews() throws Exception {
|
75
|
|
- final View mockView1 = mock(View.class);
|
76
|
|
- final View mockView2 = mock(View.class);
|
77
|
|
- when(reactRootViewCreator.create(eq(NODE_ID), eq(REACT_ROOT_VIEW_KEY))).thenReturn(mockView1);
|
78
|
|
- when(reactRootViewCreator.create(eq(OTHER_NODE_ID), eq(OTHER_REACT_ROOT_VIEW_KEY))).thenReturn(mockView2);
|
79
|
|
-
|
80
|
|
- final LayoutNode containerNode1 = createContainerNode(NODE_ID, REACT_ROOT_VIEW_KEY);
|
81
|
|
- final LayoutNode containerNode2 = createContainerNode(OTHER_NODE_ID, OTHER_REACT_ROOT_VIEW_KEY);
|
82
|
|
- final LayoutNode stackNode = createContainerStackNode(containerNode1, containerNode2);
|
83
|
|
-
|
84
|
|
- final ViewGroup result = (ViewGroup) createLayoutFactory().create(stackNode);
|
85
|
|
-
|
86
|
|
- assertThat(result).isInstanceOf(ContainerStackLayout.class);
|
87
|
|
- List<View> containers = TestUtils.assertViewChildrenCount(result, 2);
|
88
|
|
- ViewGroup container1 = (ViewGroup) containers.get(0);
|
89
|
|
- ViewGroup container2 = (ViewGroup) containers.get(1);
|
90
|
|
- TestUtils.assertViewChildren(container1, mockView1);
|
91
|
|
- TestUtils.assertViewChildren(container2, mockView2);
|
92
|
|
- }
|
93
|
|
-
|
94
|
|
- @Test
|
95
|
|
- public void returnsSideMenuRoot() throws Exception {
|
96
|
|
- when(reactRootViewCreator.create(eq(NODE_ID), eq(REACT_ROOT_VIEW_KEY))).thenReturn(mockView);
|
97
|
|
- final LayoutNode containerNode = createSideMenuContainerNode(Arrays.asList(createContainerNode()));
|
98
|
|
- final ViewGroup result = (ViewGroup) createLayoutFactory().create(containerNode);
|
99
|
|
- assertThat(result).isInstanceOf(SideMenuLayout.class);
|
100
|
|
- }
|
101
|
|
-
|
102
|
|
- @Test
|
103
|
|
- public void hasContentContainer() throws Exception {
|
104
|
|
- when(reactRootViewCreator.create(eq(NODE_ID), eq(REACT_ROOT_VIEW_KEY))).thenReturn(mockView);
|
105
|
|
- LayoutNode contentContainer = createContainerNode();
|
106
|
|
- final LayoutNode sideMenu = createSideMenuContainerNode(Arrays.asList(contentContainer));
|
107
|
|
- final ViewGroup result = (ViewGroup) createLayoutFactory().create(sideMenu);
|
108
|
|
- assertThat(result.getChildAt(0)).isInstanceOf(Container.class);
|
109
|
|
- }
|
110
|
|
-
|
111
|
|
- @Test
|
112
|
|
- public void hasLeftMenu() throws Exception {
|
113
|
|
- when(reactRootViewCreator.create(eq(NODE_ID), eq(REACT_ROOT_VIEW_KEY))).thenReturn(mockView);
|
114
|
|
- LayoutNode sideMenuLeft = createSideMenuLeftNode();
|
115
|
|
- final LayoutNode sideMenu = createSideMenuContainerNode(Arrays.asList(sideMenuLeft));
|
116
|
|
- final ViewGroup result = (ViewGroup) createLayoutFactory().create(sideMenu);
|
117
|
|
- assertThat(result.getChildAt(0)).isInstanceOf(Container.class);
|
118
|
|
- }
|
119
|
|
-
|
120
|
|
- @Test
|
121
|
|
- public void hasRightMenu() throws Exception {
|
122
|
|
- when(reactRootViewCreator.create(eq(NODE_ID), eq(REACT_ROOT_VIEW_KEY))).thenReturn(mockView);
|
123
|
|
- LayoutNode sideMenuRight = createSideMenuRightNode();
|
124
|
|
- final LayoutNode sideMenu = createSideMenuContainerNode(Arrays.asList(sideMenuRight));
|
125
|
|
- final ViewGroup result = (ViewGroup) createLayoutFactory().create(sideMenu);
|
126
|
|
- assertThat(result.getChildAt(0)).isInstanceOf(Container.class);
|
127
|
|
- }
|
128
|
|
-
|
129
|
|
- @Test
|
130
|
|
- public void returnsSingleTabContent() throws Exception {
|
131
|
|
- BottomTabs bottomTabsMock = mock(BottomTabs.class);
|
132
|
|
- when(bottomTabsMock.size()).thenReturn(0);
|
133
|
|
-
|
134
|
|
- when(reactRootViewCreator.create(eq(NODE_ID), eq(REACT_ROOT_VIEW_KEY))).thenReturn(mockView);
|
135
|
|
- final LayoutNode containerNode = createContainerStackNode(createContainerNode());
|
136
|
|
- final LayoutNode tabNode = createBottomTabNode(containerNode);
|
137
|
|
-
|
138
|
|
- final View result = createLayoutFactory(bottomTabsMock).create(tabNode);
|
139
|
|
-
|
140
|
|
- verify(bottomTabsMock).add("#0");
|
141
|
|
-
|
142
|
|
- assertThat(result).isInstanceOf(BottomTabsLayout.class);
|
143
|
|
- ViewGroup containerStack = (ViewGroup) TestUtils.assertViewChildrenCount((BottomTabsLayout) result, 1).get(0);
|
144
|
|
- Container container = (Container) TestUtils.assertViewChildrenCount(containerStack, 1).get(0);
|
145
|
|
- View view = TestUtils.assertViewChildrenCount(container, 1).get(0);
|
146
|
|
- assertThat(view).isEqualTo(mockView);
|
147
|
|
- }
|
148
|
|
-
|
149
|
|
- @Test
|
150
|
|
- public void returnsTwoTabContent() throws Exception {
|
151
|
|
- BottomTabs bottomTabsMock = mock(BottomTabs.class);
|
152
|
|
- when(bottomTabsMock.size()).thenReturn(0, 1);
|
153
|
|
-
|
154
|
|
- when(reactRootViewCreator.create(eq(NODE_ID), eq(REACT_ROOT_VIEW_KEY))).thenReturn(mockView);
|
155
|
|
- final LayoutNode firstTabRootNode = createContainerStackNode(createContainerNode(NODE_ID, REACT_ROOT_VIEW_KEY));
|
156
|
|
-
|
157
|
|
- when(reactRootViewCreator.create(eq(OTHER_NODE_ID), eq(OTHER_REACT_ROOT_VIEW_KEY))).thenReturn(otherMockView);
|
158
|
|
- final LayoutNode secondTabRootNode = createContainerStackNode(createContainerNode(OTHER_NODE_ID, OTHER_REACT_ROOT_VIEW_KEY));
|
159
|
|
-
|
160
|
|
- final LayoutNode tabNode = createBottomTabNode(firstTabRootNode, secondTabRootNode);
|
161
|
|
-
|
162
|
|
- final View result = createLayoutFactory(bottomTabsMock).create(tabNode);
|
163
|
|
-
|
164
|
|
- assertThat(result).isInstanceOf(BottomTabsLayout.class);
|
165
|
|
- verify(bottomTabsMock).add(eq("#0"));
|
166
|
|
- verify(bottomTabsMock).add(eq("#1"));
|
167
|
|
- }
|
168
|
|
-
|
169
|
|
- @Test
|
170
|
|
- public void pushScreenToFirstBottomTab() {
|
171
|
|
- BottomTabs bottomTabsMock = mock(BottomTabs.class);
|
172
|
|
- when(bottomTabsMock.size()).thenReturn(0, 1);
|
173
|
|
-
|
174
|
|
- when(reactRootViewCreator.create(eq(NODE_ID), eq(REACT_ROOT_VIEW_KEY))).thenReturn(mockView);
|
175
|
|
- final LayoutNode firstTabContainerStack = createContainerStackNode(createContainerNode(NODE_ID, REACT_ROOT_VIEW_KEY));
|
176
|
|
-
|
177
|
|
- final LayoutNode tabNode = createBottomTabNode(firstTabContainerStack);
|
178
|
|
- final BottomTabsLayout bottomTabsContainer = (BottomTabsLayout) createLayoutFactory(bottomTabsMock).create(tabNode);
|
179
|
|
- verify(bottomTabsMock).add(eq("#0"));
|
180
|
|
-
|
181
|
|
- View pushedReactView = new View(activity);
|
182
|
|
- when(reactRootViewCreator.create(eq("pushedReactViewId"), eq("pushedReactViewKey"))).thenReturn(pushedReactView);
|
183
|
|
- View view = createLayoutFactory().create(createContainerNode("pushedReactViewId", "pushedReactViewKey"));
|
184
|
|
- bottomTabsContainer.push(view);
|
185
|
|
-
|
186
|
|
- ViewGroup containerStack = (ViewGroup) TestUtils.assertViewChildrenCount(bottomTabsContainer, 1).get(0);
|
187
|
|
- ViewGroup container = (ViewGroup) TestUtils.assertViewChildrenCount(containerStack, 1).get(0);
|
188
|
|
- View result = TestUtils.assertViewChildrenCount(container, 1).get(0);
|
189
|
|
- assertThat(result).isEqualTo(pushedReactView);
|
190
|
|
- }
|
191
|
|
-
|
192
|
|
- @Test
|
193
|
|
- public void popScreenFromFirstBottomTab() {
|
194
|
|
- BottomTabs bottomTabsMock = mock(BottomTabs.class);
|
195
|
|
- when(bottomTabsMock.size()).thenReturn(0, 1);
|
196
|
|
-
|
197
|
|
- when(reactRootViewCreator.create(eq(NODE_ID), eq(REACT_ROOT_VIEW_KEY))).thenReturn(mockView);
|
198
|
|
- final LayoutNode firstTabContainerStack = createContainerStackNode(createContainerNode(NODE_ID, REACT_ROOT_VIEW_KEY));
|
199
|
|
-
|
200
|
|
- final LayoutNode tabNode = createBottomTabNode(firstTabContainerStack);
|
201
|
|
- final BottomTabsLayout bottomTabsContainer = (BottomTabsLayout) createLayoutFactory(bottomTabsMock).create(tabNode);
|
202
|
|
- verify(bottomTabsMock).add(eq("#0"));
|
203
|
|
-
|
204
|
|
- pushContainer(bottomTabsContainer, "pushedReactViewId", "pushedReactViewKey", new View(activity));
|
205
|
|
-
|
206
|
|
- bottomTabsContainer.pop();
|
207
|
|
-
|
208
|
|
- ViewGroup containerStack = (ViewGroup) TestUtils.assertViewChildrenCount(bottomTabsContainer, 1).get(0);
|
209
|
|
- ViewGroup container = (ViewGroup) TestUtils.assertViewChildrenCount(containerStack, 1).get(0);
|
210
|
|
- View result = TestUtils.assertViewChildrenCount(container, 1).get(0);
|
211
|
|
- assertThat(result).isEqualTo(mockView);
|
212
|
|
- }
|
213
|
|
-
|
214
|
|
- @Test
|
215
|
|
- public void pushScreenToScreenStackLayout() throws Exception {
|
216
|
|
- when(reactRootViewCreator.create(eq(NODE_ID), eq(REACT_ROOT_VIEW_KEY))).thenReturn(mockView);
|
217
|
|
- final LayoutNode container = createContainerNode();
|
218
|
|
- final LayoutNode stackNode = createContainerStackNode(container);
|
219
|
|
- final ContainerStackLayout containerStackLayout = (ContainerStackLayout) createLayoutFactory().create(stackNode);
|
220
|
|
-
|
221
|
|
- when(reactRootViewCreator.create(eq(OTHER_NODE_ID), eq(OTHER_REACT_ROOT_VIEW_KEY))).thenReturn(otherMockView);
|
222
|
|
- final LayoutNode pushedContainer = createContainerNode(OTHER_NODE_ID, OTHER_REACT_ROOT_VIEW_KEY);
|
223
|
|
- containerStackLayout.push(createLayoutFactory().create(pushedContainer));
|
224
|
|
-
|
225
|
|
- ViewGroup result = (ViewGroup) TestUtils.assertViewChildrenCount(containerStackLayout, 1).get(0);
|
226
|
|
- assertThat(result.getChildAt(0)).isEqualTo(otherMockView);
|
227
|
|
- }
|
228
|
|
-
|
229
|
|
- @Test
|
230
|
|
- public void pushTwoScreensToStackLayout() throws Exception {
|
231
|
|
- when(reactRootViewCreator.create(eq(NODE_ID), eq(REACT_ROOT_VIEW_KEY))).thenReturn(mockView);
|
232
|
|
- final LayoutNode container = createContainerNode();
|
233
|
|
- final LayoutNode stackNode = createContainerStackNode(container);
|
234
|
|
- final ContainerStackLayout containerStackLayout = (ContainerStackLayout) createLayoutFactory().create(stackNode);
|
235
|
|
-
|
236
|
|
- View first = new View(activity);
|
237
|
|
- pushContainer(containerStackLayout, OTHER_NODE_ID, OTHER_REACT_ROOT_VIEW_KEY, first);
|
238
|
|
-
|
239
|
|
- View second = new View(activity);
|
240
|
|
- pushContainer(containerStackLayout, "secondPushedScreenId", "secondPushedScreenKey", second);
|
241
|
|
-
|
242
|
|
- ViewGroup result = (ViewGroup) TestUtils.assertViewChildrenCount(containerStackLayout, 1).get(0);
|
243
|
|
- assertThat(result.getChildAt(0)).isEqualTo(second);
|
244
|
|
- }
|
245
|
|
-
|
246
|
|
- @Test
|
247
|
|
- public void popTwoScreensFromStackLayout() throws Exception {
|
248
|
|
- when(reactRootViewCreator.create(eq(NODE_ID), eq(REACT_ROOT_VIEW_KEY))).thenReturn(mockView);
|
249
|
|
- final LayoutNode container = createContainerNode();
|
250
|
|
- final LayoutNode stackNode = createContainerStackNode(container);
|
251
|
|
- final ContainerStackLayout containerStackLayout = (ContainerStackLayout) createLayoutFactory().create(stackNode);
|
252
|
|
-
|
253
|
|
- pushContainer(containerStackLayout, OTHER_NODE_ID, OTHER_REACT_ROOT_VIEW_KEY, new View(activity));
|
254
|
|
- pushContainer(containerStackLayout, "secondPushedScreenId", "secondPushedScreenKey", new View(activity));
|
255
|
|
-
|
256
|
|
- containerStackLayout.pop();
|
257
|
|
- containerStackLayout.pop();
|
258
|
|
-
|
259
|
|
- ViewGroup result = (ViewGroup) TestUtils.assertViewChildrenCount(containerStackLayout, 1).get(0);
|
260
|
|
- assertThat(result.getChildAt(0)).isEqualTo(mockView);
|
261
|
|
- }
|
262
|
|
-
|
263
|
|
- private void pushContainer(ContainerStackLayout containerStackLayout, String screenId, String reactRootViewKey, View rootView) {
|
264
|
|
- when(reactRootViewCreator.create(eq(screenId), eq(reactRootViewKey))).thenReturn(rootView);
|
265
|
|
- View pushedContainer = createLayoutFactory().create(createContainerNode(screenId, reactRootViewKey));
|
266
|
|
- containerStackLayout.push(pushedContainer);
|
267
|
|
- }
|
268
|
|
-
|
269
|
|
- private void pushContainer(BottomTabsLayout containerStackLayout, String screenId, String reactRootViewKey, View rootView) {
|
270
|
|
- when(reactRootViewCreator.create(eq(screenId), eq(reactRootViewKey))).thenReturn(rootView);
|
271
|
|
- View pushedContainer = createLayoutFactory().create(createContainerNode(screenId, reactRootViewKey));
|
272
|
|
- containerStackLayout.push(pushedContainer);
|
273
|
|
- }
|
274
|
|
-
|
275
|
|
- @Test
|
276
|
|
- public void popScreenFromScreenStackLayout() {
|
277
|
|
- when(reactRootViewCreator.create(eq(NODE_ID), eq(REACT_ROOT_VIEW_KEY))).thenReturn(mockView);
|
278
|
|
- final LayoutNode container = createContainerNode();
|
279
|
|
- final LayoutNode stackNode = createContainerStackNode(container);
|
280
|
|
- final ContainerStackLayout containerStackLayout = (ContainerStackLayout) createLayoutFactory().create(stackNode);
|
281
|
|
-
|
282
|
|
- when(reactRootViewCreator.create(eq(OTHER_NODE_ID), eq(OTHER_REACT_ROOT_VIEW_KEY))).thenReturn(otherMockView);
|
283
|
|
- final LayoutNode pushedContainer = createContainerNode(OTHER_NODE_ID, OTHER_REACT_ROOT_VIEW_KEY);
|
284
|
|
- containerStackLayout.push(createLayoutFactory().create(pushedContainer));
|
285
|
|
-
|
286
|
|
- containerStackLayout.pop();
|
287
|
|
- ViewGroup result = (ViewGroup) TestUtils.assertViewChildrenCount(containerStackLayout, 1).get(0);
|
288
|
|
- assertThat(result.getChildAt(0)).isEqualTo(mockView);
|
289
|
|
- }
|
290
|
|
-
|
291
|
|
- @Test(expected = IllegalArgumentException.class)
|
292
|
|
- public void throwsExceptionForUnknownType() throws Exception {
|
293
|
|
- when(reactRootViewCreator.create(eq(NODE_ID), eq(REACT_ROOT_VIEW_KEY))).thenReturn(mockView);
|
294
|
|
- final LayoutNode node = new LayoutNode(NODE_ID, "***unknownType***", Collections.<String, Object>emptyMap());
|
295
|
|
-
|
296
|
|
- createLayoutFactory().create(node);
|
297
|
|
- }
|
298
|
|
-
|
299
|
|
- private LayoutFactory createLayoutFactory() {
|
300
|
|
- return createLayoutFactory(null);
|
301
|
|
- }
|
302
|
|
-
|
303
|
|
- private LayoutFactory createLayoutFactory(BottomTabs bottomTabs) {
|
304
|
|
- BottomTabsCreator bottomTabsCreator = null;
|
305
|
|
- if (bottomTabs != null) {
|
306
|
|
- bottomTabsCreator = mock(BottomTabsCreator.class);
|
307
|
|
- when(bottomTabsCreator.create()).thenReturn(bottomTabs);
|
308
|
|
- }
|
309
|
|
-
|
310
|
|
- return new LayoutFactory(activity, reactRootViewCreator, bottomTabsCreator);
|
311
|
|
- }
|
312
|
|
-
|
313
|
|
- private LayoutNode createContainerNode() {
|
314
|
|
- return createContainerNode(NODE_ID, REACT_ROOT_VIEW_KEY);
|
315
|
|
- }
|
316
|
|
-
|
317
|
|
- private LayoutNode createSideMenuLeftNode() {
|
318
|
|
- List<LayoutNode> children = Arrays.asList(createContainerNode());
|
319
|
|
- return new LayoutNode("SideMenuLeft", children);
|
320
|
|
- }
|
321
|
|
-
|
322
|
|
- private LayoutNode createSideMenuRightNode() {
|
323
|
|
- List<LayoutNode> children = Arrays.asList(createContainerNode());
|
324
|
|
- return new LayoutNode("SideMenuRight", children);
|
325
|
|
- }
|
326
|
|
-
|
327
|
|
- private LayoutNode createContainerNode(final String id, final String name) {
|
328
|
|
- return new LayoutNode(id, "Container", new HashMap<String, Object>() {{
|
329
|
|
- put("name", name);
|
330
|
|
- }});
|
331
|
|
- }
|
332
|
|
-
|
333
|
|
- private LayoutNode createSideMenuContainerNode(List<LayoutNode> children) {
|
334
|
|
- return new LayoutNode("SideMenuRoot", children);
|
335
|
|
- }
|
336
|
|
-
|
337
|
|
- private LayoutNode createContainerStackNode(LayoutNode... children) {
|
338
|
|
- return new LayoutNode("ContainerStack", Arrays.asList(children));
|
339
|
|
- }
|
340
|
|
-
|
341
|
|
- private LayoutNode createBottomTabNode(LayoutNode... children) {
|
342
|
|
- return new LayoutNode("BottomTabs", Arrays.asList(children));
|
343
|
|
- }
|
|
30
|
+ private final static String NODE_ID = "myUniqueId";
|
|
31
|
+ private final static String REACT_ROOT_VIEW_KEY = "myName";
|
|
32
|
+
|
|
33
|
+ private final static String OTHER_NODE_ID = "anotherUniqueId";
|
|
34
|
+ private final static String OTHER_REACT_ROOT_VIEW_KEY = "anotherName";
|
|
35
|
+
|
|
36
|
+ private Activity activity;
|
|
37
|
+ private View mockView;
|
|
38
|
+ private View otherMockView;
|
|
39
|
+ private LayoutFactory.ReactRootViewCreator reactRootViewCreator;
|
|
40
|
+
|
|
41
|
+ @Before
|
|
42
|
+ public void setUp() {
|
|
43
|
+ activity = Robolectric.buildActivity(AppCompatActivity.class).get();
|
|
44
|
+ mockView = new View(activity);
|
|
45
|
+ otherMockView = new View(activity);
|
|
46
|
+ reactRootViewCreator = mock(LayoutFactory.ReactRootViewCreator.class);
|
|
47
|
+ }
|
|
48
|
+
|
|
49
|
+ @Test
|
|
50
|
+ public void returnsContainerThatHoldsTheRootView() throws Exception {
|
|
51
|
+ when(reactRootViewCreator.create(eq(NODE_ID), eq(REACT_ROOT_VIEW_KEY))).thenReturn(mockView);
|
|
52
|
+ final LayoutNode node = createContainerNode();
|
|
53
|
+
|
|
54
|
+ final ViewGroup result = (ViewGroup) createLayoutFactory().create(node);
|
|
55
|
+
|
|
56
|
+ assertThat(result).isInstanceOf(Container.class);
|
|
57
|
+ TestUtils.assertViewChildren(result, mockView);
|
|
58
|
+ }
|
|
59
|
+
|
|
60
|
+ @Test
|
|
61
|
+ public void returnsContainerStack() throws Exception {
|
|
62
|
+ when(reactRootViewCreator.create(eq(NODE_ID), eq(REACT_ROOT_VIEW_KEY))).thenReturn(mockView);
|
|
63
|
+ final LayoutNode containerNode = createContainerNode();
|
|
64
|
+ final LayoutNode stackNode = createContainerStackNode(containerNode);
|
|
65
|
+
|
|
66
|
+ final ViewGroup result = (ViewGroup) createLayoutFactory().create(stackNode);
|
|
67
|
+
|
|
68
|
+ assertThat(result).isInstanceOf(ContainerStackLayout.class);
|
|
69
|
+ ViewGroup container = (ViewGroup) TestUtils.assertViewChildrenCount(result, 1).get(0);
|
|
70
|
+ TestUtils.assertViewChildren(container, mockView);
|
|
71
|
+ }
|
|
72
|
+
|
|
73
|
+ @Test
|
|
74
|
+ public void returnsContainerStackWithMultipleViews() throws Exception {
|
|
75
|
+ final View mockView1 = mock(View.class);
|
|
76
|
+ final View mockView2 = mock(View.class);
|
|
77
|
+ when(reactRootViewCreator.create(eq(NODE_ID), eq(REACT_ROOT_VIEW_KEY))).thenReturn(mockView1);
|
|
78
|
+ when(reactRootViewCreator.create(eq(OTHER_NODE_ID), eq(OTHER_REACT_ROOT_VIEW_KEY))).thenReturn(mockView2);
|
|
79
|
+
|
|
80
|
+ final LayoutNode containerNode1 = createContainerNode(NODE_ID, REACT_ROOT_VIEW_KEY);
|
|
81
|
+ final LayoutNode containerNode2 = createContainerNode(OTHER_NODE_ID, OTHER_REACT_ROOT_VIEW_KEY);
|
|
82
|
+ final LayoutNode stackNode = createContainerStackNode(containerNode1, containerNode2);
|
|
83
|
+
|
|
84
|
+ final ViewGroup result = (ViewGroup) createLayoutFactory().create(stackNode);
|
|
85
|
+
|
|
86
|
+ assertThat(result).isInstanceOf(ContainerStackLayout.class);
|
|
87
|
+ List<View> containers = TestUtils.assertViewChildrenCount(result, 2);
|
|
88
|
+ ViewGroup container1 = (ViewGroup) containers.get(0);
|
|
89
|
+ ViewGroup container2 = (ViewGroup) containers.get(1);
|
|
90
|
+ TestUtils.assertViewChildren(container1, mockView1);
|
|
91
|
+ TestUtils.assertViewChildren(container2, mockView2);
|
|
92
|
+ }
|
|
93
|
+
|
|
94
|
+ @Test
|
|
95
|
+ public void returnsSideMenuRoot() throws Exception {
|
|
96
|
+ when(reactRootViewCreator.create(eq(NODE_ID), eq(REACT_ROOT_VIEW_KEY))).thenReturn(mockView);
|
|
97
|
+ final LayoutNode containerNode = createSideMenuContainerNode(Arrays.asList(createContainerNode()));
|
|
98
|
+ final ViewGroup result = (ViewGroup) createLayoutFactory().create(containerNode);
|
|
99
|
+ assertThat(result).isInstanceOf(SideMenuLayout.class);
|
|
100
|
+ }
|
|
101
|
+
|
|
102
|
+ @Test
|
|
103
|
+ public void hasContentContainer() throws Exception {
|
|
104
|
+ when(reactRootViewCreator.create(eq(NODE_ID), eq(REACT_ROOT_VIEW_KEY))).thenReturn(mockView);
|
|
105
|
+ LayoutNode contentContainer = createContainerNode();
|
|
106
|
+ final LayoutNode sideMenu = createSideMenuContainerNode(Arrays.asList(contentContainer));
|
|
107
|
+ final ViewGroup result = (ViewGroup) createLayoutFactory().create(sideMenu);
|
|
108
|
+ assertThat(result.getChildAt(0)).isInstanceOf(Container.class);
|
|
109
|
+ }
|
|
110
|
+
|
|
111
|
+ @Test
|
|
112
|
+ public void hasLeftMenu() throws Exception {
|
|
113
|
+ when(reactRootViewCreator.create(eq(NODE_ID), eq(REACT_ROOT_VIEW_KEY))).thenReturn(mockView);
|
|
114
|
+ LayoutNode sideMenuLeft = createSideMenuLeftNode();
|
|
115
|
+ final LayoutNode sideMenu = createSideMenuContainerNode(Arrays.asList(sideMenuLeft));
|
|
116
|
+ final ViewGroup result = (ViewGroup) createLayoutFactory().create(sideMenu);
|
|
117
|
+ assertThat(result.getChildAt(0)).isInstanceOf(Container.class);
|
|
118
|
+ }
|
|
119
|
+
|
|
120
|
+ @Test
|
|
121
|
+ public void hasRightMenu() throws Exception {
|
|
122
|
+ when(reactRootViewCreator.create(eq(NODE_ID), eq(REACT_ROOT_VIEW_KEY))).thenReturn(mockView);
|
|
123
|
+ LayoutNode sideMenuRight = createSideMenuRightNode();
|
|
124
|
+ final LayoutNode sideMenu = createSideMenuContainerNode(Arrays.asList(sideMenuRight));
|
|
125
|
+ final ViewGroup result = (ViewGroup) createLayoutFactory().create(sideMenu);
|
|
126
|
+ assertThat(result.getChildAt(0)).isInstanceOf(Container.class);
|
|
127
|
+ }
|
|
128
|
+
|
|
129
|
+ @Test
|
|
130
|
+ public void returnsSingleTabContent() throws Exception {
|
|
131
|
+ BottomTabs bottomTabsMock = mock(BottomTabs.class);
|
|
132
|
+ when(bottomTabsMock.size()).thenReturn(0);
|
|
133
|
+
|
|
134
|
+ when(reactRootViewCreator.create(eq(NODE_ID), eq(REACT_ROOT_VIEW_KEY))).thenReturn(mockView);
|
|
135
|
+ final LayoutNode containerNode = createContainerStackNode(createContainerNode());
|
|
136
|
+ final LayoutNode tabNode = createBottomTabNode(containerNode);
|
|
137
|
+
|
|
138
|
+ final View result = createLayoutFactory(bottomTabsMock).create(tabNode);
|
|
139
|
+
|
|
140
|
+ verify(bottomTabsMock).add("#0");
|
|
141
|
+
|
|
142
|
+ assertThat(result).isInstanceOf(BottomTabsLayout.class);
|
|
143
|
+ ViewGroup containerStack = (ViewGroup) TestUtils.assertViewChildrenCount((BottomTabsLayout) result, 1).get(0);
|
|
144
|
+ Container container = (Container) TestUtils.assertViewChildrenCount(containerStack, 1).get(0);
|
|
145
|
+ View view = TestUtils.assertViewChildrenCount(container, 1).get(0);
|
|
146
|
+ assertThat(view).isEqualTo(mockView);
|
|
147
|
+ }
|
|
148
|
+
|
|
149
|
+ @Test
|
|
150
|
+ public void returnsTwoTabContent() throws Exception {
|
|
151
|
+ BottomTabs bottomTabsMock = mock(BottomTabs.class);
|
|
152
|
+ when(bottomTabsMock.size()).thenReturn(0, 1);
|
|
153
|
+
|
|
154
|
+ when(reactRootViewCreator.create(eq(NODE_ID), eq(REACT_ROOT_VIEW_KEY))).thenReturn(mockView);
|
|
155
|
+ final LayoutNode firstTabRootNode = createContainerStackNode(createContainerNode(NODE_ID, REACT_ROOT_VIEW_KEY));
|
|
156
|
+
|
|
157
|
+ when(reactRootViewCreator.create(eq(OTHER_NODE_ID), eq(OTHER_REACT_ROOT_VIEW_KEY))).thenReturn(otherMockView);
|
|
158
|
+ final LayoutNode secondTabRootNode = createContainerStackNode(createContainerNode(OTHER_NODE_ID, OTHER_REACT_ROOT_VIEW_KEY));
|
|
159
|
+
|
|
160
|
+ final LayoutNode tabNode = createBottomTabNode(firstTabRootNode, secondTabRootNode);
|
|
161
|
+
|
|
162
|
+ final View result = createLayoutFactory(bottomTabsMock).create(tabNode);
|
|
163
|
+
|
|
164
|
+ assertThat(result).isInstanceOf(BottomTabsLayout.class);
|
|
165
|
+ verify(bottomTabsMock).add(eq("#0"));
|
|
166
|
+ verify(bottomTabsMock).add(eq("#1"));
|
|
167
|
+ }
|
|
168
|
+
|
|
169
|
+ @Test
|
|
170
|
+ public void pushScreenToFirstBottomTab() {
|
|
171
|
+ BottomTabs bottomTabsMock = mock(BottomTabs.class);
|
|
172
|
+ when(bottomTabsMock.size()).thenReturn(0, 1);
|
|
173
|
+
|
|
174
|
+ when(reactRootViewCreator.create(eq(NODE_ID), eq(REACT_ROOT_VIEW_KEY))).thenReturn(mockView);
|
|
175
|
+ final LayoutNode firstTabContainerStack = createContainerStackNode(createContainerNode(NODE_ID, REACT_ROOT_VIEW_KEY));
|
|
176
|
+
|
|
177
|
+ final LayoutNode tabNode = createBottomTabNode(firstTabContainerStack);
|
|
178
|
+ final BottomTabsLayout bottomTabsContainer = (BottomTabsLayout) createLayoutFactory(bottomTabsMock).create(tabNode);
|
|
179
|
+ verify(bottomTabsMock).add(eq("#0"));
|
|
180
|
+
|
|
181
|
+ View pushedReactView = new View(activity);
|
|
182
|
+ when(reactRootViewCreator.create(eq("pushedReactViewId"), eq("pushedReactViewKey"))).thenReturn(pushedReactView);
|
|
183
|
+ View view = createLayoutFactory().create(createContainerNode("pushedReactViewId", "pushedReactViewKey"));
|
|
184
|
+ bottomTabsContainer.push(view);
|
|
185
|
+
|
|
186
|
+ ViewGroup containerStack = (ViewGroup) TestUtils.assertViewChildrenCount(bottomTabsContainer, 1).get(0);
|
|
187
|
+ ViewGroup container = (ViewGroup) TestUtils.assertViewChildrenCount(containerStack, 1).get(0);
|
|
188
|
+ View result = TestUtils.assertViewChildrenCount(container, 1).get(0);
|
|
189
|
+ assertThat(result).isEqualTo(pushedReactView);
|
|
190
|
+ }
|
|
191
|
+
|
|
192
|
+ @Test
|
|
193
|
+ public void popScreenFromFirstBottomTab() {
|
|
194
|
+ BottomTabs bottomTabsMock = mock(BottomTabs.class);
|
|
195
|
+ when(bottomTabsMock.size()).thenReturn(0, 1);
|
|
196
|
+
|
|
197
|
+ when(reactRootViewCreator.create(eq(NODE_ID), eq(REACT_ROOT_VIEW_KEY))).thenReturn(mockView);
|
|
198
|
+ final LayoutNode firstTabContainerStack = createContainerStackNode(createContainerNode(NODE_ID, REACT_ROOT_VIEW_KEY));
|
|
199
|
+
|
|
200
|
+ final LayoutNode tabNode = createBottomTabNode(firstTabContainerStack);
|
|
201
|
+ final BottomTabsLayout bottomTabsContainer = (BottomTabsLayout) createLayoutFactory(bottomTabsMock).create(tabNode);
|
|
202
|
+ verify(bottomTabsMock).add(eq("#0"));
|
|
203
|
+
|
|
204
|
+ pushContainer(bottomTabsContainer, "pushedReactViewId", "pushedReactViewKey", new View(activity));
|
|
205
|
+
|
|
206
|
+ bottomTabsContainer.pop();
|
|
207
|
+
|
|
208
|
+ ViewGroup containerStack = (ViewGroup) TestUtils.assertViewChildrenCount(bottomTabsContainer, 1).get(0);
|
|
209
|
+ ViewGroup container = (ViewGroup) TestUtils.assertViewChildrenCount(containerStack, 1).get(0);
|
|
210
|
+ View result = TestUtils.assertViewChildrenCount(container, 1).get(0);
|
|
211
|
+ assertThat(result).isEqualTo(mockView);
|
|
212
|
+ }
|
|
213
|
+
|
|
214
|
+ @Test
|
|
215
|
+ public void pushScreenToScreenStackLayout() throws Exception {
|
|
216
|
+ when(reactRootViewCreator.create(eq(NODE_ID), eq(REACT_ROOT_VIEW_KEY))).thenReturn(mockView);
|
|
217
|
+ final LayoutNode container = createContainerNode();
|
|
218
|
+ final LayoutNode stackNode = createContainerStackNode(container);
|
|
219
|
+ final ContainerStackLayout containerStackLayout = (ContainerStackLayout) createLayoutFactory().create(stackNode);
|
|
220
|
+
|
|
221
|
+ when(reactRootViewCreator.create(eq(OTHER_NODE_ID), eq(OTHER_REACT_ROOT_VIEW_KEY))).thenReturn(otherMockView);
|
|
222
|
+ final LayoutNode pushedContainer = createContainerNode(OTHER_NODE_ID, OTHER_REACT_ROOT_VIEW_KEY);
|
|
223
|
+ containerStackLayout.push(createLayoutFactory().create(pushedContainer));
|
|
224
|
+
|
|
225
|
+ ViewGroup result = (ViewGroup) TestUtils.assertViewChildrenCount(containerStackLayout, 1).get(0);
|
|
226
|
+ assertThat(result.getChildAt(0)).isEqualTo(otherMockView);
|
|
227
|
+ }
|
|
228
|
+
|
|
229
|
+ @Test
|
|
230
|
+ public void pushTwoScreensToStackLayout() throws Exception {
|
|
231
|
+ when(reactRootViewCreator.create(eq(NODE_ID), eq(REACT_ROOT_VIEW_KEY))).thenReturn(mockView);
|
|
232
|
+ final LayoutNode container = createContainerNode();
|
|
233
|
+ final LayoutNode stackNode = createContainerStackNode(container);
|
|
234
|
+ final ContainerStackLayout containerStackLayout = (ContainerStackLayout) createLayoutFactory().create(stackNode);
|
|
235
|
+
|
|
236
|
+ View first = new View(activity);
|
|
237
|
+ pushContainer(containerStackLayout, OTHER_NODE_ID, OTHER_REACT_ROOT_VIEW_KEY, first);
|
|
238
|
+
|
|
239
|
+ View second = new View(activity);
|
|
240
|
+ pushContainer(containerStackLayout, "secondPushedScreenId", "secondPushedScreenKey", second);
|
|
241
|
+
|
|
242
|
+ ViewGroup result = (ViewGroup) TestUtils.assertViewChildrenCount(containerStackLayout, 1).get(0);
|
|
243
|
+ assertThat(result.getChildAt(0)).isEqualTo(second);
|
|
244
|
+ }
|
|
245
|
+
|
|
246
|
+ @Test
|
|
247
|
+ public void popTwoScreensFromStackLayout() throws Exception {
|
|
248
|
+ when(reactRootViewCreator.create(eq(NODE_ID), eq(REACT_ROOT_VIEW_KEY))).thenReturn(mockView);
|
|
249
|
+ final LayoutNode container = createContainerNode();
|
|
250
|
+ final LayoutNode stackNode = createContainerStackNode(container);
|
|
251
|
+ final ContainerStackLayout containerStackLayout = (ContainerStackLayout) createLayoutFactory().create(stackNode);
|
|
252
|
+
|
|
253
|
+ pushContainer(containerStackLayout, OTHER_NODE_ID, OTHER_REACT_ROOT_VIEW_KEY, new View(activity));
|
|
254
|
+ pushContainer(containerStackLayout, "secondPushedScreenId", "secondPushedScreenKey", new View(activity));
|
|
255
|
+
|
|
256
|
+ containerStackLayout.pop();
|
|
257
|
+ containerStackLayout.pop();
|
|
258
|
+
|
|
259
|
+ ViewGroup result = (ViewGroup) TestUtils.assertViewChildrenCount(containerStackLayout, 1).get(0);
|
|
260
|
+ assertThat(result.getChildAt(0)).isEqualTo(mockView);
|
|
261
|
+ }
|
|
262
|
+
|
|
263
|
+ private void pushContainer(ContainerStackLayout containerStackLayout, String screenId, String reactRootViewKey, View rootView) {
|
|
264
|
+ when(reactRootViewCreator.create(eq(screenId), eq(reactRootViewKey))).thenReturn(rootView);
|
|
265
|
+ View pushedContainer = createLayoutFactory().create(createContainerNode(screenId, reactRootViewKey));
|
|
266
|
+ containerStackLayout.push(pushedContainer);
|
|
267
|
+ }
|
|
268
|
+
|
|
269
|
+ private void pushContainer(BottomTabsLayout containerStackLayout, String screenId, String reactRootViewKey, View rootView) {
|
|
270
|
+ when(reactRootViewCreator.create(eq(screenId), eq(reactRootViewKey))).thenReturn(rootView);
|
|
271
|
+ View pushedContainer = createLayoutFactory().create(createContainerNode(screenId, reactRootViewKey));
|
|
272
|
+ containerStackLayout.push(pushedContainer);
|
|
273
|
+ }
|
|
274
|
+
|
|
275
|
+ @Test
|
|
276
|
+ public void popScreenFromScreenStackLayout() {
|
|
277
|
+ when(reactRootViewCreator.create(eq(NODE_ID), eq(REACT_ROOT_VIEW_KEY))).thenReturn(mockView);
|
|
278
|
+ final LayoutNode container = createContainerNode();
|
|
279
|
+ final LayoutNode stackNode = createContainerStackNode(container);
|
|
280
|
+ final ContainerStackLayout containerStackLayout = (ContainerStackLayout) createLayoutFactory().create(stackNode);
|
|
281
|
+
|
|
282
|
+ when(reactRootViewCreator.create(eq(OTHER_NODE_ID), eq(OTHER_REACT_ROOT_VIEW_KEY))).thenReturn(otherMockView);
|
|
283
|
+ final LayoutNode pushedContainer = createContainerNode(OTHER_NODE_ID, OTHER_REACT_ROOT_VIEW_KEY);
|
|
284
|
+ containerStackLayout.push(createLayoutFactory().create(pushedContainer));
|
|
285
|
+
|
|
286
|
+ containerStackLayout.pop();
|
|
287
|
+ ViewGroup result = (ViewGroup) TestUtils.assertViewChildrenCount(containerStackLayout, 1).get(0);
|
|
288
|
+ assertThat(result.getChildAt(0)).isEqualTo(mockView);
|
|
289
|
+ }
|
|
290
|
+
|
|
291
|
+ @Test(expected = IllegalArgumentException.class)
|
|
292
|
+ public void throwsExceptionForUnknownType() throws Exception {
|
|
293
|
+ when(reactRootViewCreator.create(eq(NODE_ID), eq(REACT_ROOT_VIEW_KEY))).thenReturn(mockView);
|
|
294
|
+ final LayoutNode node = new LayoutNode(NODE_ID, "***unknownType***", Collections.<String, Object>emptyMap());
|
|
295
|
+
|
|
296
|
+ createLayoutFactory().create(node);
|
|
297
|
+ }
|
|
298
|
+
|
|
299
|
+ private LayoutFactory createLayoutFactory() {
|
|
300
|
+ return createLayoutFactory(null);
|
|
301
|
+ }
|
|
302
|
+
|
|
303
|
+ private LayoutFactory createLayoutFactory(BottomTabs bottomTabs) {
|
|
304
|
+ BottomTabsCreator bottomTabsCreator = null;
|
|
305
|
+ if (bottomTabs != null) {
|
|
306
|
+ bottomTabsCreator = mock(BottomTabsCreator.class);
|
|
307
|
+ when(bottomTabsCreator.create()).thenReturn(bottomTabs);
|
|
308
|
+ }
|
|
309
|
+
|
|
310
|
+ return new LayoutFactory(activity, reactRootViewCreator, bottomTabsCreator);
|
|
311
|
+ }
|
|
312
|
+
|
|
313
|
+ private LayoutNode createContainerNode() {
|
|
314
|
+ return createContainerNode(NODE_ID, REACT_ROOT_VIEW_KEY);
|
|
315
|
+ }
|
|
316
|
+
|
|
317
|
+ private LayoutNode createSideMenuLeftNode() {
|
|
318
|
+ List<LayoutNode> children = Arrays.asList(createContainerNode());
|
|
319
|
+ return new LayoutNode("SideMenuLeft", children);
|
|
320
|
+ }
|
|
321
|
+
|
|
322
|
+ private LayoutNode createSideMenuRightNode() {
|
|
323
|
+ List<LayoutNode> children = Arrays.asList(createContainerNode());
|
|
324
|
+ return new LayoutNode("SideMenuRight", children);
|
|
325
|
+ }
|
|
326
|
+
|
|
327
|
+ private LayoutNode createContainerNode(final String id, final String name) {
|
|
328
|
+ return new LayoutNode(id, "Container", new HashMap<String, Object>() {{
|
|
329
|
+ put("name", name);
|
|
330
|
+ }});
|
|
331
|
+ }
|
|
332
|
+
|
|
333
|
+ private LayoutNode createSideMenuContainerNode(List<LayoutNode> children) {
|
|
334
|
+ return new LayoutNode("SideMenuRoot", children);
|
|
335
|
+ }
|
|
336
|
+
|
|
337
|
+ private LayoutNode createContainerStackNode(LayoutNode... children) {
|
|
338
|
+ return new LayoutNode("ContainerStack", Arrays.asList(children));
|
|
339
|
+ }
|
|
340
|
+
|
|
341
|
+ private LayoutNode createBottomTabNode(LayoutNode... children) {
|
|
342
|
+ return new LayoutNode("BottomTabs", Arrays.asList(children));
|
|
343
|
+ }
|
344
|
344
|
}
|