Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
janicduplessis committed Jul 19, 2016
1 parent dfc6706 commit d2fd849
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 5 deletions.
4 changes: 2 additions & 2 deletions Libraries/Animated/src/AnimatedImplementation.js
Original file line number Diff line number Diff line change
Expand Up @@ -725,7 +725,7 @@ class AnimatedValue extends AnimatedWithChildren {

_startListeningToNativeValueUpdates() {
if (this.__nativeAnimatedValueListener ||
!NativeAnimatedHelper.supportNativeListener()) {
!NativeAnimatedHelper.supportsNativeListener()) {
return;
}

Expand All @@ -740,7 +740,7 @@ class AnimatedValue extends AnimatedWithChildren {

_stopListeningForNativeValueUpdates() {
if (!this.__nativeAnimatedValueListener ||
!NativeAnimatedHelper.supportNativeListener()) {
!NativeAnimatedHelper.supportsNativeListener()) {
return;
}

Expand Down
4 changes: 2 additions & 2 deletions Libraries/Animated/src/NativeAnimatedHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ function assertNativeAnimatedModule(): void {
}

// TODO: remove this when iOS supports native listeners.
function supportNativeListener(): bool {
function supportsNativeListener(): bool {
return !!NativeAnimatedModule.startListeningToAnimatedNodeValue;
}

Expand All @@ -161,5 +161,5 @@ module.exports = {
generateNewNodeTag,
generateNewAnimationId,
assertNativeAnimatedModule,
supportNativeListener,
supportsNativeListener,
};
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@
/**
* Interface used to listen to {@link ValueAnimatedNode} updates.
*/
/* package */ interface AnimatedNodeValueListener {
public interface AnimatedNodeValueListener {
void onValueUpdate(double value);
}
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,64 @@ public void testFramesAnimation() {
verifyNoMoreInteractions(mUIImplementationMock);
}

@Test
public void testNodeValueListenerIfNotListening() {
int nodeId = 1;

createSimpleAnimatedViewWithOpacity(1000, 0d);
JavaOnlyArray frames = JavaOnlyArray.of(0d, 0.2d, 0.4d, 0.6d, 0.8d, 1d);

Callback animationCallback = mock(Callback.class);
AnimatedNodeValueListener valueListener = mock(AnimatedNodeValueListener.class);

mNativeAnimatedNodesManager.startListeningToAnimatedNodeValue(nodeId, valueListener);
mNativeAnimatedNodesManager.startAnimatingNode(
1,
nodeId,
JavaOnlyMap.of("type", "frames", "frames", frames, "toValue", 1d),
animationCallback);

mNativeAnimatedNodesManager.runUpdates(nextFrameTime());
verify(valueListener).onValueUpdate(eq(0d));

mNativeAnimatedNodesManager.stopListeningToAnimatedNodeValue(nodeId);

reset(valueListener);
mNativeAnimatedNodesManager.runUpdates(nextFrameTime());
verifyNoMoreInteractions(valueListener);
}

@Test
public void testNodeValueListenerIfListening() {
int nodeId = 1;

createSimpleAnimatedViewWithOpacity(1000, 0d);
JavaOnlyArray frames = JavaOnlyArray.of(0d, 0.2d, 0.4d, 0.6d, 0.8d, 1d);

Callback animationCallback = mock(Callback.class);
AnimatedNodeValueListener valueListener = mock(AnimatedNodeValueListener.class);

mNativeAnimatedNodesManager.startListeningToAnimatedNodeValue(nodeId, valueListener);
mNativeAnimatedNodesManager.startAnimatingNode(
1,
nodeId,
JavaOnlyMap.of("type", "frames", "frames", frames, "toValue", 1d),
animationCallback);

mNativeAnimatedNodesManager.runUpdates(nextFrameTime());
verify(valueListener).onValueUpdate(eq(0d));

for (int i = 0; i < frames.size(); i++) {
reset(valueListener);
mNativeAnimatedNodesManager.runUpdates(nextFrameTime());
verify(valueListener).onValueUpdate(eq(frames.getDouble(i)));
}

reset(valueListener);
mNativeAnimatedNodesManager.runUpdates(nextFrameTime());
verifyNoMoreInteractions(valueListener);
}

@Test
public void testAnimationCallbackFinish() {
createSimpleAnimatedViewWithOpacity(1000, 0d);
Expand Down

0 comments on commit d2fd849

Please sign in to comment.