SetPositionCommand.tests.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. QUnit.module( "SetPositionCommand" );
  2. QUnit.test( "Test SetPositionCommand (Undo and Redo)", function( assert ) {
  3. var editor = new Editor();
  4. var box = aBox();
  5. var cmd = new AddObjectCommand( 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 SetPositionCommand( box, newPosition );
  15. cmd.updatable = false;
  16. editor.execute( cmd );
  17. } );
  18. assert.ok( box.position.x == positions[ positions.length - 1 ].x, "OK, changing X position was successful" );
  19. assert.ok( box.position.y == positions[ positions.length - 1 ].y, "OK, changing Y position was successful" );
  20. assert.ok( box.position.z == positions[ positions.length - 1 ].z, "OK, changing Z position was successful" );
  21. editor.undo();
  22. assert.ok( box.position.x == positions[ positions.length - 2 ].x, "OK, changing X position was successful (after undo)" );
  23. assert.ok( box.position.y == positions[ positions.length - 2 ].y, "OK, changing Y position was successful (after undo)" );
  24. assert.ok( box.position.z == positions[ positions.length - 2 ].z, "OK, changing Z position was successful (after undo)" );
  25. editor.redo();
  26. assert.ok( box.position.x == positions[ positions.length - 1 ].x, "OK, changing X position was successful (after redo)" );
  27. assert.ok( box.position.y == positions[ positions.length - 1 ].y, "OK, changing Y position was successful (after redo)" );
  28. assert.ok( box.position.z == positions[ positions.length - 1 ].z, "OK, changing Z position was successful (after redo)" );
  29. } );