SetRotationCommand.tests.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. QUnit.module( "SetRotationCommand" );
  2. QUnit.test( "Test SetRotationCommand (Undo and Redo)", function( assert ) {
  3. // setup
  4. var editor = new Editor();
  5. var box = aBox();
  6. editor.execute( new AddObjectCommand( box ) );
  7. var rotations = [
  8. { x: 1.1, y: 0.4, z: - 2.0 },
  9. { x: 2.2, y: - 1.3, z: 1.3 },
  10. { x: 0.3, y: - 0.1, z: - 1.9 }
  11. ];
  12. rotations.map( function( rotation ) {
  13. var newRotation = new THREE.Euler( rotation.x, rotation.y, rotation.z );
  14. var cmd = new SetRotationCommand( box, newRotation );
  15. cmd.updatable = false;
  16. editor.execute ( cmd );
  17. } );
  18. assert.ok( box.rotation.x == rotations[ rotations.length - 1 ].x, "OK, changing X rotation was successful" );
  19. assert.ok( box.rotation.y == rotations[ rotations.length - 1 ].y, "OK, changing Y rotation was successful" );
  20. assert.ok( box.rotation.z == rotations[ rotations.length - 1 ].z, "OK, changing Z rotation was successful" );
  21. editor.undo();
  22. assert.ok( box.rotation.x == rotations[ rotations.length - 2 ].x, "OK, changing X rotation was successful (after undo)" );
  23. assert.ok( box.rotation.y == rotations[ rotations.length - 2 ].y, "OK, changing Y rotation was successful (after undo)" );
  24. assert.ok( box.rotation.z == rotations[ rotations.length - 2 ].z, "OK, changing Z rotation was successful (after undo)" );
  25. editor.redo();
  26. assert.ok( box.rotation.x == rotations[ rotations.length - 1 ].x, "OK, changing X rotation was successful (after redo)" );
  27. assert.ok( box.rotation.y == rotations[ rotations.length - 1 ].y, "OK, changing Y rotation was successful (after redo)" );
  28. assert.ok( box.rotation.z == rotations[ rotations.length - 1 ].z, "OK, changing Z rotation was successful (after redo)" );
  29. } );