-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Expand file tree
/
Copy pathFloatingActionButtonTest.java
More file actions
155 lines (136 loc) · 5.34 KB
/
FloatingActionButtonTest.java
File metadata and controls
155 lines (136 loc) · 5.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
package com.reactnativenavigation.viewcontrollers.stack;
import android.app.Activity;
import android.view.View;
import android.view.ViewGroup;
import com.reactnativenavigation.BaseTest;
import com.reactnativenavigation.TestUtils;
import com.reactnativenavigation.mocks.SimpleViewController;
import com.reactnativenavigation.options.FabOptions;
import com.reactnativenavigation.options.Options;
import com.reactnativenavigation.options.params.Text;
import com.reactnativenavigation.react.CommandListenerAdapter;
import com.reactnativenavigation.viewcontrollers.child.ChildControllersRegistry;
import com.reactnativenavigation.views.stack.fab.Fab;
import com.reactnativenavigation.views.stack.fab.FabMenu;
import com.reactnativenavigation.views.stack.StackLayout;
import org.junit.Ignore;
import org.junit.Test;
import androidx.annotation.NonNull;
import static org.assertj.core.api.Java6Assertions.assertThat;
public class FloatingActionButtonTest extends BaseTest {
private final static int CHILD_FAB_COUNT = 3;
private StackController stackController;
private SimpleViewController childFab;
private SimpleViewController childNoFab;
private Activity activity;
private ChildControllersRegistry childRegistry;
@Override
public void beforeEach() {
super.beforeEach();
activity = newActivity();
childRegistry = new ChildControllersRegistry();
stackController = TestUtils.newStackController(activity)
.setFabPresenter(createFabPresenter())
.build();
stackController.ensureViewIsCreated();
Options options = getOptionsWithFab();
childFab = new SimpleViewController(activity, childRegistry, "child1", options);
childNoFab = new SimpleViewController(activity, childRegistry, "child2", new Options());
}
@NonNull
private Options getOptionsWithFab() {
Options options = new Options();
FabOptions fabOptions = new FabOptions();
fabOptions.id = new Text("FAB");
options.fabOptions = fabOptions;
return options;
}
@NonNull
private Options getOptionsWithFabActions() {
Options options = new Options();
FabOptions fabOptions = new FabOptions();
fabOptions.id = new Text("FAB");
for (int i = 0; i < CHILD_FAB_COUNT; i++) {
FabOptions childOptions = new FabOptions();
childOptions.id = new Text("fab" + i);
fabOptions.actionsArray.add(childOptions);
}
options.fabOptions = fabOptions;
return options;
}
private boolean hasFab() {
StackLayout stackLayout = stackController.getStackLayout();
for (int i = 0; i < stackLayout.getChildCount(); i++) {
if (stackLayout.getChildAt(i) instanceof Fab) {
return true;
}
if (stackLayout.getChildAt(i) instanceof FabMenu) {
return true;
}
}
return false;
}
@Test
public void showOnPush() {
stackController.push(childFab, new CommandListenerAdapter());
childFab.onViewWillAppear();
assertThat(hasFab()).isTrue();
}
@Test
public void hideOnPush() {
stackController.push(childFab, new CommandListenerAdapter());
childFab.onViewWillAppear();
assertThat(hasFab()).isTrue();
stackController.push(childNoFab, new CommandListenerAdapter());
childNoFab.onViewWillAppear();
assertThat(hasFab()).isFalse();
}
@Test
public void hideOnPop() {
disablePushAnimation(childNoFab, childFab);
stackController.push(childNoFab, new CommandListenerAdapter());
stackController.push(childFab, new CommandListenerAdapter());
childFab.onViewWillAppear();
assertThat(hasFab()).isTrue();
stackController.pop(Options.EMPTY, new CommandListenerAdapter());
childNoFab.onViewWillAppear();
assertThat(hasFab()).isFalse();
}
@Test
public void showOnPop() {
disablePushAnimation(childFab, childNoFab);
stackController.push(childFab, new CommandListenerAdapter());
stackController.push(childNoFab, new CommandListenerAdapter());
childNoFab.onViewWillAppear();
assertThat(hasFab()).isFalse();
stackController.pop(Options.EMPTY, new CommandListenerAdapter());
childFab.onViewWillAppear();
assertThat(hasFab()).isTrue();
}
@Test
public void hasChildren() {
childFab = new SimpleViewController(activity, childRegistry, "child1", getOptionsWithFabActions());
stackController.push(childFab, new CommandListenerAdapter());
childFab.onViewWillAppear();
assertThat(hasFab()).isTrue();
assertThat(containsActions()).isTrue();
}
private boolean containsActions() {
StackLayout stackLayout = stackController.getStackLayout();
for (int i = 0; i < stackLayout.getChildCount(); i++) {
View child = stackLayout.getChildAt(i);
if (child instanceof FabMenu) {
return ((ViewGroup) child).getChildCount() == CHILD_FAB_COUNT + 2;
}
}
return false;
}
private FabPresenter createFabPresenter() {
return new FabPresenter() {
@Override
public void animateHide(Runnable onAnimationEnd) {
onAnimationEnd.run();
}
};
}
}