TestCmdSetPosition.js 1.6 KB

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