-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Expand file tree
/
Copy pathOverlayManagerTest.java
More file actions
109 lines (93 loc) · 4.33 KB
/
OverlayManagerTest.java
File metadata and controls
109 lines (93 loc) · 4.33 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
package com.reactnativenavigation.viewcontrollers.overlay;
import android.app.Activity;
import android.view.View;
import android.widget.FrameLayout;
import com.reactnativenavigation.BaseTest;
import com.reactnativenavigation.mocks.SimpleViewController;
import com.reactnativenavigation.options.Options;
import com.reactnativenavigation.react.CommandListener;
import com.reactnativenavigation.react.CommandListenerAdapter;
import com.reactnativenavigation.viewcontrollers.child.ChildControllersRegistry;
import org.junit.Ignore;
import org.junit.Test;
import static org.assertj.core.api.Java6Assertions.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
public class OverlayManagerTest extends BaseTest {
private static final String OVERLAY_ID_1 = "OVERLAY_1";
private static final String OVERLAY_ID_2 = "OVERLAY_2";
private OverlayManager uut;
private SimpleViewController overlay1;
private SimpleViewController overlay2;
private FrameLayout contentLayout;
private FrameLayout overlayContainer;
@Override
public void beforeEach() {
super.beforeEach();
Activity activity = newActivity();
contentLayout = new FrameLayout(activity);
contentLayout.layout(0, 0, 1000, 1000);
activity.setContentView(contentLayout);
overlayContainer = new FrameLayout(activity);
contentLayout.addView(overlayContainer);
ChildControllersRegistry childRegistry = new ChildControllersRegistry();
overlay1 = spy(new SimpleViewController(activity, childRegistry, OVERLAY_ID_1, new Options()));
overlay2 = spy(new SimpleViewController(activity, childRegistry, OVERLAY_ID_2, new Options()));
uut = new OverlayManager();
}
@Test
public void show_attachesOverlayContainerToContentLayout() {
uut.show(overlayContainer, overlay1, new CommandListenerAdapter());
assertThat(overlayContainer.getParent()).isEqualTo(contentLayout);
uut.show(overlayContainer, overlay2, new CommandListenerAdapter());
}
@Test
public void show() {
CommandListenerAdapter listener = spy(new CommandListenerAdapter());
uut.show(overlayContainer, overlay1, listener);
idleMainLooper();
verify(listener).onSuccess(OVERLAY_ID_1);
verify(overlay1).onViewDidAppear();
assertThat(overlay1.getView().getParent()).isEqualTo(overlayContainer);
assertMatchParent(overlay1.getView());
}
@Test
public void dismiss() {
uut.show(overlayContainer, overlay1, new CommandListenerAdapter());
assertThat(uut.size()).isOne();
CommandListener listener = spy(new CommandListenerAdapter());
uut.dismiss(overlayContainer, overlay1.getId(), listener);
assertThat(uut.size()).isZero();
verify(listener, times(1)).onSuccess(OVERLAY_ID_1);
verify(overlay1, times(1)).destroy();
}
@Test
public void dismiss_rejectIfOverlayNotFound() {
CommandListener listener = spy(new CommandListenerAdapter());
uut.dismiss(overlayContainer, overlay1.getId(), listener);
verify(listener, times(1)).onError(any());
}
@Test
public void dismiss_onViewReturnedToFront() {
uut.show(overlayContainer, overlay1, new CommandListenerAdapter());
uut.show(overlayContainer, overlay2, new CommandListenerAdapter());
idleMainLooper();
verify(overlay1, never()).onViewBroughtToFront();
uut.dismiss(overlayContainer, OVERLAY_ID_2, new CommandListenerAdapter());
idleMainLooper();
verify(overlay1).onViewBroughtToFront();
}
@Test
public void dismiss_overlayContainerIsHiddenIfAllOverlaysAreDismissed() {
uut.show(overlayContainer, overlay1, new CommandListenerAdapter());
uut.show(overlayContainer, overlay2, new CommandListenerAdapter());
uut.dismiss(overlayContainer, OVERLAY_ID_2, new CommandListenerAdapter());
assertThat(overlayContainer.getVisibility()).isEqualTo(View.VISIBLE);
assertThat(overlayContainer.getParent()).isEqualTo(contentLayout);
uut.dismiss(overlayContainer, OVERLAY_ID_1, new CommandListenerAdapter());
assertThat(overlayContainer.getVisibility()).isEqualTo(View.GONE);
}
}