TestNestedDoUndoRedo.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. module( "NestedDoUndoRedo" );
  2. test( "Test nested Do's, Undo's and Redo's ", function() {
  3. // TODO: replace CmdNameObject by CmdSetValue
  4. var editor = new Editor();
  5. var mesh = aBox( 'One box unlike all others' );
  6. var initPosX = 2 ;
  7. var initPosY = 3 ;
  8. var initPosZ = 4 ;
  9. var initRotationX = 12 ;
  10. var initRotationY = 13 ;
  11. var initRotationZ = 14 ;
  12. var initScaleX = 22 ;
  13. var initScaleY = 23 ;
  14. var initScaleZ = 24 ;
  15. mesh.position.x = initPosX ;
  16. mesh.position.y = initPosY ;
  17. mesh.position.z = initPosZ ;
  18. mesh.rotation.x = initRotationX ;
  19. mesh.rotation.y = initRotationY ;
  20. mesh.rotation.z = initRotationZ ;
  21. mesh.scale.x = initScaleX ;
  22. mesh.scale.y = initScaleY ;
  23. mesh.scale.z = initScaleZ ;
  24. // let's begin
  25. editor.execute( new CmdAddObject( mesh ) );
  26. var newPos = new THREE.Vector3( initPosX + 100, initPosY, initPosZ );
  27. editor.execute( new CmdSetPosition( mesh, newPos ) );
  28. var newRotation = new THREE.Euler( initRotationX, initRotationY + 1000, initRotationZ );
  29. editor.execute( new CmdSetRotation( mesh, newRotation ) );
  30. var newScale = new THREE.Vector3( initScaleX, initScaleY, initScaleZ + 10000 );
  31. editor.execute( new CmdSetScale( mesh, newScale ) );
  32. /* full check */
  33. ok( mesh.position.x == 102, "OK, X position is correct " );
  34. ok( mesh.position.y == 3, "OK, Y position is correct " );
  35. ok( mesh.position.z == 4, "OK, Z position is correct " );
  36. ok( mesh.rotation.x == 12, "OK, X rotation is correct " );
  37. ok( mesh.rotation.y == 1013, "OK, Y rotation is correct " );
  38. ok( mesh.rotation.z == 14, "OK, Z rotation is correct " );
  39. ok( mesh.scale.x == 22, "OK, X scale is correct " );
  40. ok( mesh.scale.y == 23, "OK, Y scale is correct " );
  41. ok( mesh.scale.z == 10024, "OK, Z scale is correct " );
  42. editor.undo(); // rescaling undone
  43. editor.undo(); // rotation undone
  44. editor.undo(); // translation undone
  45. /* full check */
  46. ok( mesh.position.x == 2, "OK, X position is correct " );
  47. ok( mesh.position.y == 3, "OK, Y position is correct " );
  48. ok( mesh.position.z == 4, "OK, Z position is correct " );
  49. ok( mesh.rotation.x == 12, "OK, X rotation is correct " );
  50. ok( mesh.rotation.y == 13, "OK, Y rotation is correct " );
  51. ok( mesh.rotation.z == 14, "OK, Z rotation is correct " );
  52. ok( mesh.scale.x == 22, "OK, X scale is correct " );
  53. ok( mesh.scale.y == 23, "OK, Y scale is correct " );
  54. ok( mesh.scale.z == 24, "OK, Z scale is correct " );
  55. editor.redo(); // translation redone
  56. editor.redo(); // rotation redone
  57. editor.execute( new CmdRemoveObject( mesh ) );
  58. ok( editor.scene.children.length == 0, "OK, object removal was successful" );
  59. editor.undo(); // removal undone
  60. ok( mesh.rotation.y == 1013, "OK, Y rotation is correct " );
  61. editor.undo(); // rotation undone (expected!)
  62. /* full check */
  63. ok( mesh.position.x == 102, "OK, X position is correct " );
  64. ok( mesh.position.y == 3, "OK, Y position is correct " );
  65. ok( mesh.position.z == 4, "OK, Z position is correct " );
  66. ok( mesh.rotation.x == 12, "OK, X rotation is correct " );
  67. ok( mesh.rotation.y == 13, "OK, Y rotation is correct " );
  68. ok( mesh.rotation.z == 14, "OK, Z rotation is correct " );
  69. ok( mesh.scale.x == 22, "OK, X scale is correct " );
  70. ok( mesh.scale.y == 23, "OK, Y scale is correct " );
  71. ok( mesh.scale.z == 24, "OK, Z scale is correct " );
  72. });