|
|
@@ -1,128 +0,0 @@
|
|
1
|
|
-package com.reactnativenavigation.viewcontrollers;
|
|
2
|
|
-
|
|
3
|
|
-import com.reactnativenavigation.BaseTest;
|
|
4
|
|
-import com.reactnativenavigation.mocks.ModalCreatorMock;
|
|
5
|
|
-import com.reactnativenavigation.mocks.SimpleViewController;
|
|
6
|
|
-import com.reactnativenavigation.parse.Options;
|
|
7
|
|
-import com.reactnativenavigation.utils.CommandListenerAdapter;
|
|
8
|
|
-import com.reactnativenavigation.viewcontrollers.modal.Modal;
|
|
9
|
|
-import com.reactnativenavigation.viewcontrollers.modal.ModalListener;
|
|
10
|
|
-
|
|
11
|
|
-import org.junit.Test;
|
|
12
|
|
-
|
|
13
|
|
-import static org.assertj.core.api.Java6Assertions.assertThat;
|
|
14
|
|
-import static org.mockito.ArgumentMatchers.any;
|
|
15
|
|
-import static org.mockito.Mockito.spy;
|
|
16
|
|
-import static org.mockito.Mockito.times;
|
|
17
|
|
-import static org.mockito.Mockito.verify;
|
|
18
|
|
-
|
|
19
|
|
-public class ModalStackTest extends BaseTest {
|
|
20
|
|
- private static final String CONTROLLER_ID = "simpleController";
|
|
21
|
|
- private ModalStack uut;
|
|
22
|
|
- private SimpleViewController viewController;
|
|
23
|
|
- private ModalListener modalListener;
|
|
24
|
|
-
|
|
25
|
|
- @Override
|
|
26
|
|
- public void beforeEach() {
|
|
27
|
|
- createDismissListener();
|
|
28
|
|
- uut = spy(new ModalStack(new ModalCreatorMock(), modalListener));
|
|
29
|
|
- viewController = new SimpleViewController(newActivity(), CONTROLLER_ID, new Options());
|
|
30
|
|
- }
|
|
31
|
|
-
|
|
32
|
|
- @SuppressWarnings("Convert2Lambda")
|
|
33
|
|
- private void createDismissListener() {
|
|
34
|
|
- ModalListener dismissListener = new ModalListener() {
|
|
35
|
|
- @Override
|
|
36
|
|
- public void onModalDismiss(Modal modal) {
|
|
37
|
|
-
|
|
38
|
|
- }
|
|
39
|
|
-
|
|
40
|
|
- @Override
|
|
41
|
|
- public void onModalDisplay(Modal modal) {
|
|
42
|
|
-
|
|
43
|
|
- }
|
|
44
|
|
- };
|
|
45
|
|
- this.modalListener = spy(dismissListener);
|
|
46
|
|
- }
|
|
47
|
|
-
|
|
48
|
|
- @Test
|
|
49
|
|
- public void modalRefIsSaved() {
|
|
50
|
|
- uut.showModal(viewController, new CommandListenerAdapter());
|
|
51
|
|
- assertThat(findModal(CONTROLLER_ID)).isNotNull();
|
|
52
|
|
- }
|
|
53
|
|
-
|
|
54
|
|
- @Test
|
|
55
|
|
- public void modalIsShown() {
|
|
56
|
|
- uut.showModal(viewController, new CommandListenerAdapter() {
|
|
57
|
|
- @Override
|
|
58
|
|
- public void onSuccess(String childId) {
|
|
59
|
|
- verify(findModal(CONTROLLER_ID), times(1)).show();
|
|
60
|
|
- verify(modalListener, times(1)).onModalDisplay(any());
|
|
61
|
|
- }
|
|
62
|
|
- });
|
|
63
|
|
- }
|
|
64
|
|
-
|
|
65
|
|
- @Test
|
|
66
|
|
- public void modalIsDismissed() {
|
|
67
|
|
- uut.showModal(viewController, new CommandListenerAdapter());
|
|
68
|
|
- final Modal modal = findModal(CONTROLLER_ID);
|
|
69
|
|
- assertThat(modal).isNotNull();
|
|
70
|
|
- uut.dismissModal(CONTROLLER_ID, new CommandListenerAdapter() {
|
|
71
|
|
- @Override
|
|
72
|
|
- public void onSuccess(String childId) {
|
|
73
|
|
- assertThat(findModal(CONTROLLER_ID)).isNull();
|
|
74
|
|
- verify(uut, times(1)).onModalDismiss(modal);
|
|
75
|
|
- }
|
|
76
|
|
- });
|
|
77
|
|
- }
|
|
78
|
|
-
|
|
79
|
|
- @Test
|
|
80
|
|
- public void dismissAllModals() {
|
|
81
|
|
- uut.showModal(new SimpleViewController(newActivity(), "1", new Options()), new CommandListenerAdapter());
|
|
82
|
|
- uut.showModal(new SimpleViewController(newActivity(), "2", new Options()), new CommandListenerAdapter());
|
|
83
|
|
- uut.dismissAll(new CommandListenerAdapter() {
|
|
84
|
|
- @Override
|
|
85
|
|
- public void onSuccess(String childId) {
|
|
86
|
|
- assertThat(uut.isEmpty()).isTrue();
|
|
87
|
|
- }
|
|
88
|
|
- });
|
|
89
|
|
- }
|
|
90
|
|
-
|
|
91
|
|
- @Test
|
|
92
|
|
- public void isEmpty() {
|
|
93
|
|
- assertThat(uut.isEmpty()).isTrue();
|
|
94
|
|
- uut.showModal(viewController, new CommandListenerAdapter());
|
|
95
|
|
- assertThat(uut.isEmpty()).isFalse();
|
|
96
|
|
- uut.dismissAll(new CommandListenerAdapter());
|
|
97
|
|
- assertThat(uut.isEmpty()).isTrue();
|
|
98
|
|
- }
|
|
99
|
|
-
|
|
100
|
|
- @Test
|
|
101
|
|
- public void onDismiss() {
|
|
102
|
|
- uut.showModal(viewController, new CommandListenerAdapter());
|
|
103
|
|
- uut.showModal(new SimpleViewController(newActivity(), "otherComponent", new Options()), new CommandListenerAdapter());
|
|
104
|
|
- uut.dismissAll(new CommandListenerAdapter() {
|
|
105
|
|
- @Override
|
|
106
|
|
- public void onSuccess(String childId) {
|
|
107
|
|
- verify(uut, times(2)).onModalDismiss(any());
|
|
108
|
|
- }
|
|
109
|
|
- });
|
|
110
|
|
- }
|
|
111
|
|
-
|
|
112
|
|
- @Test
|
|
113
|
|
- public void onDismiss_onViewAppearedInvokedOnPreviousModal() {
|
|
114
|
|
- SimpleViewController viewController = spy(new SimpleViewController(newActivity(), "otherComponent", new Options()));
|
|
115
|
|
- uut.showModal(viewController, new CommandListenerAdapter());
|
|
116
|
|
- uut.showModal(this.viewController, new CommandListenerAdapter());
|
|
117
|
|
- uut.dismissModal(CONTROLLER_ID, new CommandListenerAdapter() {
|
|
118
|
|
- @Override
|
|
119
|
|
- public void onSuccess(String childId) {
|
|
120
|
|
- verify(viewController, times(1)).onViewAppeared();
|
|
121
|
|
- }
|
|
122
|
|
- });
|
|
123
|
|
- }
|
|
124
|
|
-
|
|
125
|
|
- private Modal findModal(String id) {
|
|
126
|
|
- return uut.findModalByComponentId(id);
|
|
127
|
|
- }
|
|
128
|
|
-}
|