TestMultiCmdsCommand.js 3.8 KB

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