MultiCmdsCommand.tests.js 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. QUnit.module( "MultiCmdsCommand" );
  2. QUnit.test( "Test MultiCmdsCommand (Undo and Redo)", function( assert ) {
  3. var editor = new Editor();
  4. var box = aBox( 'Multi Command Box' );
  5. var boxGeometry1 = { geometry: { parameters: { width: 200, height: 201, depth: 202, widthSegments: 2, heightSegments: 3, depthSegments: 4 } } };
  6. var boxGeometry2 = { geometry: { parameters: { width: 50, height: 51, depth: 52, widthSegments: 7, heightSegments: 8, depthSegments: 9 } } };
  7. var boxGeometries = [ getGeometry( "BoxGeometry", boxGeometry1 ), getGeometry( "BoxGeometry", boxGeometry2 ) ];
  8. var cmd = new AddObjectCommand( box );
  9. cmd.updatable = false;
  10. editor.execute( cmd );
  11. // setup first multi commands
  12. var firstMultiCmds = [
  13. new SetGeometryCommand( box, boxGeometries[ 0 ] ),
  14. new SetPositionCommand( box, new THREE.Vector3( 1, 2, 3 ) ),
  15. new SetRotationCommand( box, new THREE.Euler( 0.1, 0.2, 0.2 ) ),
  16. new SetScaleCommand( box, new THREE.Vector3( 1.1, 1.2, 1.3 ) )
  17. ];
  18. firstMultiCmds.map( function( cmd ) {
  19. cmd.updatable = false;
  20. } );
  21. var firstMultiCmd = new MultiCmdsCommand( firstMultiCmds );
  22. firstMultiCmd.updatable = false;
  23. editor.execute( firstMultiCmd );
  24. // setup second multi commands
  25. var secondMultiCmds = [
  26. new SetGeometryCommand( box, boxGeometries[ 1 ] ),
  27. new SetPositionCommand( box, new THREE.Vector3( 4, 5, 6 ) ),
  28. new SetRotationCommand( box, new THREE.Euler( 0.4, 0.5, 0.6 ) ),
  29. new SetScaleCommand( box, new THREE.Vector3( 1.4, 1.5, 1.6 ) )
  30. ];
  31. secondMultiCmds.map( function( cmd ) {
  32. cmd.updatable = false;
  33. } );
  34. var secondMultiCmd = new MultiCmdsCommand( secondMultiCmds );
  35. secondMultiCmd.updatable = false;
  36. editor.execute( secondMultiCmd );
  37. // test one modified value for each command
  38. assert.ok( box.geometry.parameters.widthSegments == 7, "OK, widthSegments has been modified accordingly after two multi executes (expected: 7, actual: " + box.geometry.parameters.widthSegments + ")" );
  39. assert.ok( box.position.y == 5, "OK, y position has been modified accordingly after two multi executes (expected: 5, actual: " + box.position.y + ")" );
  40. assert.ok( box.rotation.x == 0.4, "OK, x rotation has been modified accordingly after two multi executes (expected: 0.4, actual: " + box.rotation.x + ") " );
  41. assert.ok( box.scale.z == 1.6, "OK, z scale has been modified accordingly after two multi executes (expected: 1.6, actual: " + box.scale.z + ")" );
  42. editor.undo();
  43. assert.ok( box.geometry.parameters.widthSegments == 2, "OK, widthSegments has been modified accordingly after undo (expected: 2, actual: " + box.geometry.parameters.widthSegments + ")" );
  44. assert.ok( box.position.y == 2, "OK, y position has been modified accordingly after undo (expected: 2, actual: " + box.position.y + ")" );
  45. assert.ok( box.rotation.x == 0.1, "OK, x rotation has been modified accordingly after undo (expected: 0.1, actual: " + box.rotation.x + ")" );
  46. assert.ok( box.scale.z == 1.3, "OK, z scale has been modified accordingly after undo (expected: 1.3, actual: " + box.scale.z + ")" );
  47. editor.redo();
  48. assert.ok( box.geometry.parameters.widthSegments == 7, "OK, widthSegments has been modified accordingly after two multi executes (expected: 7, actual: " + box.geometry.parameters.widthSegments + ")" );
  49. assert.ok( box.position.y == 5, "OK, y position has been modified accordingly after two multi executes (expected: 5, actual: " + box.position.y + ")" );
  50. assert.ok( box.rotation.x == 0.4, "OK, x rotation has been modified accordingly after two multi executes (expected: 0.4, actual: " + box.rotation.x + ") " );
  51. assert.ok( box.scale.z == 1.6, "OK, z scale has been modified accordingly after two multi executes (expected: 1.6, actual: " + box.scale.z + ")" );
  52. } );