-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Expand file tree
/
Copy pathOptionsApplyingTest.java
More file actions
149 lines (131 loc) · 5.87 KB
/
OptionsApplyingTest.java
File metadata and controls
149 lines (131 loc) · 5.87 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
package com.reactnativenavigation.viewcontrollers;
import android.app.Activity;
import android.content.Context;
import android.content.res.Configuration;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.view.View;
import android.widget.RelativeLayout;
import com.reactnativenavigation.BaseTest;
import com.reactnativenavigation.TestUtils;
import com.reactnativenavigation.mocks.TestComponentLayout;
import com.reactnativenavigation.mocks.TestReactView;
import com.reactnativenavigation.options.Options;
import com.reactnativenavigation.options.params.Bool;
import com.reactnativenavigation.options.params.Colour;
import com.reactnativenavigation.options.params.ThemeColour;
import com.reactnativenavigation.options.params.Text;
import com.reactnativenavigation.viewcontrollers.component.ComponentPresenter;
import com.reactnativenavigation.viewcontrollers.viewcontroller.Presenter;
import com.reactnativenavigation.react.CommandListenerAdapter;
import com.reactnativenavigation.viewcontrollers.child.ChildControllersRegistry;
import com.reactnativenavigation.viewcontrollers.component.ComponentViewController;
import com.reactnativenavigation.viewcontrollers.stack.StackController;
import com.reactnativenavigation.viewcontrollers.stack.topbar.TopBarController;
import com.reactnativenavigation.viewcontrollers.viewcontroller.IReactView;
import com.reactnativenavigation.views.stack.StackLayout;
import com.reactnativenavigation.views.stack.topbar.TopBar;
import org.junit.Ignore;
import org.junit.Test;
import static android.view.ViewGroup.LayoutParams.MATCH_PARENT;
import static org.assertj.core.api.Java6Assertions.assertThat;
import static org.mockito.Mockito.spy;
public class OptionsApplyingTest extends BaseTest {
private Activity activity;
private StackController stack;
private ComponentViewController uut;
private IReactView view;
private Options initialNavigationOptions;
private TopBar topBar;
@Override
public void beforeEach() {
super.beforeEach();
activity = newActivity();
initialNavigationOptions = new Options();
view = spy(new TestComponentLayout(activity, new TestReactView(activity)));
view.asView().setLayoutParams(new RelativeLayout.LayoutParams(MATCH_PARENT, MATCH_PARENT));
uut = new ComponentViewController(activity,
new ChildControllersRegistry(),
"componentId1",
"componentName",
(activity1, componentId, componentName) -> view,
initialNavigationOptions,
new Presenter(activity, new Options()),
new ComponentPresenter(Options.EMPTY)
) {
@Override
public boolean isViewShown() {
return true;
}
};
TopBarController topBarController = new TopBarController() {
@Override
protected TopBar createTopBar(Context context, StackLayout stackLayout) {
topBar = spy(super.createTopBar(context, stackLayout));
return topBar;
}
};
stack = TestUtils.newStackController(activity, topBarController)
.build();
stack.ensureViewIsCreated();
stack.getView().layout(0, 0, 1000, 1000);
stack.getTopBar().layout(0, 0, 1000, 100);
activity.setContentView(stack.getView());
disablePushAnimation(uut);
}
@SuppressWarnings("ConstantConditions")
@Test
public void applyNavigationOptionsHandlesNoParentStack() {
uut.setParentController(null);
assertThat(uut.getParentController()).isNull();
uut.ensureViewIsCreated();
uut.onViewWillAppear();
assertThat(uut.getParentController()).isNull();
}
@Test
public void initialOptionsAppliedOnAppear() {
uut.options.topBar.title.text = new Text("the title");
StackController stackController = TestUtils.newStackController(activity).build();
stackController.ensureViewIsCreated();
stackController.push(uut, new CommandListenerAdapter());
assertThat(stackController.getTopBar().getTitle()).isEmpty();
uut.onViewWillAppear();
assertThat(stackController.getTopBar().getTitle()).isEqualTo("the title");
}
@Test
public void mergeNavigationOptionsUpdatesCurrentOptions() {
assertThat(uut.options.topBar.title.text.get("")).isEmpty();
Options options = new Options();
options.topBar.title.text = new Text("new title");
uut.mergeOptions(options);
assertThat(uut.options.topBar.title.text.get()).isEqualTo("new title");
}
@Test
public void reappliesOptionsOnMerge() {
assertThat(stack.getTopBar().getTitle()).isEmpty();
stack.push(uut, new CommandListenerAdapter());
Options opts = new Options();
opts.topBar.title.text = new Text("the new title");
uut.mergeOptions(opts);
assertThat(stack.getTopBar().getTitle()).isEqualTo("the new title");
}
@Test
public void appliesTopBackBackgroundColor() {
uut.options.topBar.background.color = new ThemeColour(new Colour(Color.RED));
stack.push(uut, new CommandListenerAdapter());
idleMainLooper();
assertThat(((ColorDrawable) stack.getTopBar().getBackground()).getColor()).isEqualTo(Color.RED);
}
@Test
public void appliesTopBarVisible() {
stack.push(uut, new CommandListenerAdapter());
assertThat(uut.initialOptions).isSameAs(initialNavigationOptions);
initialNavigationOptions.topBar.title.text = new Text("the title");
assertThat(stack.getTopBar().getVisibility()).isNotEqualTo(View.GONE);
Options opts = new Options();
opts.topBar.visible = new Bool(false);
opts.topBar.animate = new Bool(false);
uut.mergeOptions(opts);
assertThat(stack.getTopBar().getVisibility()).isEqualTo(View.GONE);
}
}