-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Expand file tree
/
Copy pathBackButtonHelperTest.java
More file actions
78 lines (67 loc) · 2.97 KB
/
BackButtonHelperTest.java
File metadata and controls
78 lines (67 loc) · 2.97 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
package com.reactnativenavigation.viewcontrollers.stack;
import android.app.Activity;
import com.reactnativenavigation.BaseTest;
import com.reactnativenavigation.TestUtils;
import com.reactnativenavigation.viewcontrollers.stack.topbar.button.BackButtonHelper;
import com.reactnativenavigation.mocks.SimpleViewController;
import com.reactnativenavigation.options.Options;
import com.reactnativenavigation.options.params.Bool;
import com.reactnativenavigation.react.CommandListenerAdapter;
import com.reactnativenavigation.viewcontrollers.child.ChildController;
import com.reactnativenavigation.viewcontrollers.child.ChildControllersRegistry;
import org.junit.Ignore;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
import static org.assertj.core.api.Java6Assertions.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
public class BackButtonHelperTest extends BaseTest {
private BackButtonHelper uut;
private StackController stack;
private ChildController<?> child1;
private ChildController<?> child2;
@Override
public void beforeEach() {
super.beforeEach();
uut = new BackButtonHelper();
Activity activity = newActivity();
ChildControllersRegistry childRegistry = new ChildControllersRegistry();
stack = TestUtils.newStackController(activity)
.setChildRegistry(childRegistry)
.setBackButtonHelper(uut)
.build();
child1 = spy(new SimpleViewController(activity, childRegistry, "child1", new Options()));
child2 = spy(new SimpleViewController(activity, childRegistry, "child2", new Options()));
stack.ensureViewIsCreated();
}
@Test
public void addToChild() {
uut.addToPushedChild(child1);
verify(child1).mergeOptions(any());
}
@Test
public void addToChild_addsIfStackContainsMoreThenOneChild() {
disablePushAnimation(child1, child2);
stack.push(child1, new CommandListenerAdapter());
stack.push(child2, new CommandListenerAdapter());
ArgumentCaptor<Options> optionWithBackButton = ArgumentCaptor.forClass(Options.class);
verify(child2, times(1)).mergeOptions(optionWithBackButton.capture());
assertThat(optionWithBackButton.getValue().topBar.buttons.back.visible.get()).isTrue();
}
@Test
public void addToChild_doesNotAddIfBackButtonHidden() {
disablePushAnimation(child1, child2);
stack.push(child1, new CommandListenerAdapter());
child2.options.topBar.buttons.back.visible = new Bool(false);
stack.push(child2, new CommandListenerAdapter());
verify(child2, times(0)).mergeOptions(any());
}
@Test
public void clear() {
child1.options.topBar.buttons.back.visible = new Bool(true);
uut.clear(child1);
assertThat(child1.options.topBar.buttons.back.visible.get()).isFalse();
}
}