NestedDoUndoRedo.tests.js 3.5 KB

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