TestSetPositionCommand.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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. module( "SetPositionCommand" );
  6. test( "Test SetPositionCommand (Undo and Redo)", function() {
  7. var editor = new Editor();
  8. var box = aBox();
  9. var cmd = new AddObjectCommand( box );
  10. editor.execute( cmd );
  11. var positions = [
  12. { x: 50, y: - 80, z: 30 },
  13. { x: - 10, y: 100, z: 0 },
  14. { x: 44, y: - 20, z: 90 }
  15. ];
  16. positions.map( function( position ) {
  17. var newPosition = new THREE.Vector3( position.x, position.y, position.z );
  18. var cmd = new SetPositionCommand( box, newPosition );
  19. cmd.updatable = false;
  20. editor.execute( cmd );
  21. } );
  22. ok( box.position.x == positions[ positions.length - 1 ].x, "OK, changing X position was successful" );
  23. ok( box.position.y == positions[ positions.length - 1 ].y, "OK, changing Y position was successful" );
  24. ok( box.position.z == positions[ positions.length - 1 ].z, "OK, changing Z position was successful" );
  25. editor.undo();
  26. ok( box.position.x == positions[ positions.length - 2 ].x, "OK, changing X position was successful (after undo)" );
  27. ok( box.position.y == positions[ positions.length - 2 ].y, "OK, changing Y position was successful (after undo)" );
  28. ok( box.position.z == positions[ positions.length - 2 ].z, "OK, changing Z position was successful (after undo)" );
  29. editor.redo();
  30. ok( box.position.x == positions[ positions.length - 1 ].x, "OK, changing X position was successful (after redo)" );
  31. ok( box.position.y == positions[ positions.length - 1 ].y, "OK, changing Y position was successful (after redo)" );
  32. ok( box.position.z == positions[ positions.length - 1 ].z, "OK, changing Z position was successful (after redo)" );
  33. } );