TestSetRotationCommand.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /**
  2. * @author lxxxvi / https://github.com/lxxxvi
  3. * Developed as part of a project at University of Applied Sciences and Arts Northwestern Switzerland (www.fhnw.ch)
  4. */
  5. QUnit.module( "SetRotationCommand" );
  6. QUnit.test( "Test SetRotationCommand (Undo and Redo)", function( assert ) {
  7. // setup
  8. var editor = new Editor();
  9. var box = aBox();
  10. editor.execute( new AddObjectCommand( box ) );
  11. var rotations = [
  12. { x: 1.1, y: 0.4, z: - 2.0 },
  13. { x: 2.2, y: - 1.3, z: 1.3 },
  14. { x: 0.3, y: - 0.1, z: - 1.9 }
  15. ];
  16. rotations.map( function( rotation ) {
  17. var newRotation = new THREE.Euler( rotation.x, rotation.y, rotation.z );
  18. var cmd = new SetRotationCommand( box, newRotation );
  19. cmd.updatable = false;
  20. editor.execute ( cmd );
  21. } );
  22. assert.ok( box.rotation.x == rotations[ rotations.length - 1 ].x, "OK, changing X rotation was successful" );
  23. assert.ok( box.rotation.y == rotations[ rotations.length - 1 ].y, "OK, changing Y rotation was successful" );
  24. assert.ok( box.rotation.z == rotations[ rotations.length - 1 ].z, "OK, changing Z rotation was successful" );
  25. editor.undo();
  26. assert.ok( box.rotation.x == rotations[ rotations.length - 2 ].x, "OK, changing X rotation was successful (after undo)" );
  27. assert.ok( box.rotation.y == rotations[ rotations.length - 2 ].y, "OK, changing Y rotation was successful (after undo)" );
  28. assert.ok( box.rotation.z == rotations[ rotations.length - 2 ].z, "OK, changing Z rotation was successful (after undo)" );
  29. editor.redo();
  30. assert.ok( box.rotation.x == rotations[ rotations.length - 1 ].x, "OK, changing X rotation was successful (after redo)" );
  31. assert.ok( box.rotation.y == rotations[ rotations.length - 1 ].y, "OK, changing Y rotation was successful (after redo)" );
  32. assert.ok( box.rotation.z == rotations[ rotations.length - 1 ].z, "OK, changing Z rotation was successful (after redo)" );
  33. } );