Browse Source

Merge pull request #13008 from gero3/UpdateUnitTestAnimationAction

Add unit tests for play, stop and reset in animationAction
Mr.doob 7 years ago
parent
commit
5a3c3fae9f
1 changed files with 146 additions and 16 deletions
  1. 146 16
      test/unit/src/animation/AnimationAction.tests.js

+ 146 - 16
test/unit/src/animation/AnimationAction.tests.js

@@ -6,6 +6,22 @@
 import { AnimationAction } from '../../../../src/animation/AnimationAction';
 import { AnimationMixer } from '../../../../src/animation/AnimationMixer';
 import { AnimationClip } from '../../../../src/animation/AnimationClip';
+import { NumberKeyframeTrack } from '../../../../src/animation/tracks/NumberKeyframeTrack';
+import { Object3D } from '../../../../src/core/Object3D';
+import { LoopOnce, LoopRepeat, LoopPingPong } from '../../../../src/constants';
+
+
+function createAnimation(){
+
+
+	var mixer = new AnimationMixer(new Object3D());
+	var track = new NumberKeyframeTrack( ".rotation[x]", [ 0, 1000 ], [ 0, 360 ] );
+	var clip = new AnimationClip( "clip1", 1000, [track] );
+
+	var animationAction = new AnimationAction( mixer, clip );
+	return { mixer :mixer,track:track,clip:clip,animationAction:animationAction};
+
+}
 
 export default QUnit.module( 'Animation', () => {
 
@@ -23,46 +39,160 @@ export default QUnit.module( 'Animation', () => {
 		} );
 
 		// PUBLIC STUFF
-		QUnit.todo( "play", ( assert ) => {
+		QUnit.test( "play", ( assert ) => {
 
-			assert.ok( false, "everything's gonna be alright" );
+			var {mixer,animationAction} = createAnimation();
+			var animationAction2 = animationAction.play();
+			assert.equal( animationAction, animationAction2, "AnimationAction.play can be chained." );
 
-		} );
+			var UserException = function () {
 
-		QUnit.todo( "stop", ( assert ) => {
+				this.message = "AnimationMixer must activate AnimationAction on play.";
 
-			assert.ok( false, "everything's gonna be alright" );
+			};
+			mixer._activateAction = function ( action ) {
 
-		} );
+				if ( action === animationAction ) {
 
-		QUnit.todo( "reset", ( assert ) => {
+					throw new UserException();
 
-			assert.ok( false, "everything's gonna be alright" );
+				}
+
+			};
+			assert.throws( () => {
+
+				animationAction.play();
+
+			}, new UserException() );
 
 		} );
 
-		QUnit.todo( "isRunning", ( assert ) => {
+		QUnit.test( "stop", ( assert ) => {
 
-			assert.ok( false, "everything's gonna be alright" );
+			var {mixer,animationAction} = createAnimation();
+			var animationAction2 = animationAction.stop();
+			assert.equal( animationAction, animationAction2, "AnimationAction.stop can be chained." );
+
+			var UserException = function () {
+
+				this.message = "AnimationMixer must deactivate AnimationAction on stop.";
+
+			};
+			mixer._deactivateAction = function ( action ) {
+
+				if ( action === animationAction ) {
+
+					throw new UserException();
+
+				}
+
+			};
+			assert.throws( () => {
+
+				animationAction.stop();
+
+			}, new UserException() );
 
 		} );
 
-		QUnit.todo( "isScheduled", ( assert ) => {
+		QUnit.test( "reset", ( assert ) => {
 
-			assert.ok( false, "everything's gonna be alright" );
+			var {mixer,animationAction} = createAnimation();
+			var animationAction2 = animationAction.stop();
+			assert.equal( animationAction, animationAction2, "AnimationAction.reset can be chained." );
+			assert.equal( animationAction2.paused, false, "AnimationAction.reset() sets paused false" );
+			assert.equal( animationAction2.enabled, true, "AnimationAction.reset() sets enabled true" );
+			assert.equal( animationAction2.time, 0, "AnimationAction.reset() resets time." );
+			assert.equal( animationAction2._loopCount, - 1, "AnimationAction.reset() resets loopcount." );
+			assert.equal( animationAction2._startTime, null, "AnimationAction.reset() removes starttime." );
 
 		} );
 
-		QUnit.todo( "startAt", ( assert ) => {
+		QUnit.test( "isRunning", ( assert ) => {
+
+			var {mixer,animationAction} = createAnimation();
+			assert.notOk( animationAction.isRunning(), "When an animation is just made, it is not running." );
+			animationAction.play();
+			assert.ok( animationAction.isRunning(), "When an animation is started, it is running." );
+			animationAction.stop();
+			assert.notOk( animationAction.isRunning(), "When an animation is stopped, it is not running." );
+			animationAction.play();
+			animationAction.paused = true;
+			assert.notOk( animationAction.isRunning(), "When an animation is paused, it is not running." );
+			animationAction.paused = false;
+			animationAction.enabled = false;
+			assert.notOk( animationAction.isRunning(), "When an animation is not enabled, it is not running." );
+			animationAction.enabled = true;
+			assert.ok( animationAction.isRunning(), "When an animation is enabled, it is running." );
 
-			assert.ok( false, "everything's gonna be alright" );
+		} );
+
+		QUnit.test( "isScheduled", ( assert ) => {
 
+			var {mixer,animationAction} = createAnimation();
+			assert.notOk( animationAction.isScheduled(), "When an animation is just made, it is not scheduled." );
+			animationAction.play();
+			assert.ok( animationAction.isScheduled(), "When an animation is started, it is scheduled." );
+			mixer.update(1);
+			assert.ok( animationAction.isScheduled(), "When an animation is updated, it is scheduled." );
+			animationAction.stop();
+			assert.notOk( animationAction.isScheduled(), "When an animation is stopped, it isn't scheduled anymore." );
+
+		   
 		} );
 
-		QUnit.todo( "setLoop", ( assert ) => {
+		QUnit.test( "startAt", ( assert ) => {
+
+			var {mixer,animationAction} = createAnimation();
+			animationAction.startAt(2);
+			animationAction.play();
+			assert.notOk( animationAction.isRunning(), "When an animation is started at a specific time, it is not running." );
+			assert.ok( animationAction.isScheduled(), "When an animation is started at a specific time, it is scheduled." );
+			mixer.update(1);
+			assert.notOk( animationAction.isRunning(), "When an animation is started at a specific time and the interval is not passed, it is not running." );
+			assert.ok( animationAction.isScheduled(), "When an animation is started at a specific time and the interval is not passed, it is scheduled." );
+			mixer.update(1);
+			assert.ok( animationAction.isRunning(), "When an animation is started at a specific time and the interval is passed, it is running." );
+			assert.ok( animationAction.isScheduled(), "When an animation is started at a specific time and the interval is passed, it is scheduled." );
+			animationAction.stop();
+			assert.notOk( animationAction.isRunning(), "When an animation is stopped, it is not running." );
+			assert.notOk( animationAction.isScheduled(), "When an animation is stopped, it is not scheduled." );
+			
 
-			assert.ok( false, "everything's gonna be alright" );
+		} );
 
+		QUnit.test( "setLoop LoopOnce", ( assert ) => {
+
+			var {mixer,animationAction} = createAnimation();
+			animationAction.setLoop(LoopOnce);
+			animationAction.play();
+			assert.ok( animationAction.isRunning(), "When an animation is started, it is running." );
+			mixer.update(500);
+			assert.ok( animationAction.isRunning(), "When an animation is in the first loop, it is running." );
+			mixer.update(500);
+			assert.notOk( animationAction.isRunning(), "When an animation is ended, it is not running." );
+			mixer.update(500);
+			assert.notOk( animationAction.isRunning(), "When an animation is ended, it is not running." );
+	
+		} );
+	
+		QUnit.test( "setLoop LoopRepeat", ( assert ) => {
+	
+			var {mixer,animationAction} = createAnimation();
+			animationAction.setLoop(LoopRepeat,3);
+			animationAction.play();
+			assert.ok( animationAction.isRunning(), "When an animation is started, it is running." );
+			mixer.update(500);
+			assert.ok( animationAction.isRunning(), "When an animation is in the first loop, it is running." );
+			mixer.update(1000);
+			assert.ok( animationAction.isRunning(), "When an animation is in second loop when in looprepeat 3 times, it is running." );
+			mixer.update(1000);
+			assert.ok( animationAction.isRunning(), "When an animation is in third loop when in looprepeat 3 times, it is running." );
+			mixer.update(1000);
+			assert.notOk( animationAction.isRunning(), "When an animation ended his third loop when in looprepeat 3 times, it is not running anymore." );
+			mixer.update(1000);
+			assert.notOk( animationAction.isRunning(), "When an animation ended his third loop when in looprepeat 3 times, it stays not running anymore." );
+			
 		} );
 
 		QUnit.todo( "setEffectiveWeight", ( assert ) => {