Skip to content

Commit

Permalink
Reject promise when trying to push two children with same id (#5855)
Browse files Browse the repository at this point in the history
Reject promise when trying to push two children with the same if into the same stack.

Related to #5821
Closes #5689

Co-authored-by: Yogev Ben David <yogevbd@wix.com>
  • Loading branch information
guyca and yogevbd committed Jan 20, 2020
1 parent 9a361a4 commit 27ceea8
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,10 @@ public void onChildDestroyed(ViewController child) {
}

public void push(ViewController child, CommandListener listener) {
if (findController(child.getId()) != null) {
listener.onError("A stack can't contain two children with the same id");
return;
}
final ViewController toRemove = stack.peek();
if (size() > 0) backButtonHelper.addToPushedChild(child);
child.setParentController(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ public void push() {
uut.selectTab(3);

SimpleViewController stackChild = new SimpleViewController(activity, childRegistry, "stackChild", new Options());
SimpleViewController stackChild2 = new SimpleViewController(activity, childRegistry, "stackChild", new Options());
SimpleViewController stackChild2 = new SimpleViewController(activity, childRegistry, "stackChild2", new Options());

disablePushAnimation(stackChild, stackChild2);
hideBackButton(stackChild2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,18 @@ public void push_backPressedDuringPushAnimationDestroysPushedScreenImmediately()
inOrder.verify(backListener).onSuccess(any());
}

@Test
public void push_rejectIfStackContainsChildWithId() {
disablePushAnimation(child1);
uut.push(child1, new CommandListenerAdapter());
assertThat(uut.size()).isEqualTo(1);

CommandListenerAdapter listener = spy(new CommandListenerAdapter());
uut.push(child1a, listener);
verify(listener).onError(any());
assertThat(uut.size()).isEqualTo(1);
}

@Test
public void animateSetRoot() {
disablePushAnimation(child1, child2, child3);
Expand Down

0 comments on commit 27ceea8

Please sign in to comment.