TestCmdRemoveScript.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. module("CmdRemoveScript");
  2. test( "Test CmdRemoveScript (Undo and Redo)", function() {
  3. var editor = new Editor();
  4. // prepare
  5. var box = aBox( "The scripted box" );
  6. var sphere = aSphere( "The scripted sphere" );
  7. var objects = [ box, sphere ];
  8. var xMove = { name: "", source: "function update( event ) { this.position.x = this.position.x + 1; }" };
  9. var yMove = { name: "", source: "function update( event ) { this.position.y = this.position.y + 1; }" };
  10. var scripts = [ xMove, yMove ];
  11. // add objects to editor
  12. objects.map( function( item ) {
  13. editor.execute( new CmdAddObject( item ) );
  14. });
  15. ok( editor.scene.children.length == 2, "OK, the box and the sphere have been added" );
  16. // add scripts to the objects
  17. for ( var i = 0; i < scripts.length; i++ ) {
  18. var cmd = new CmdAddScript( objects[i], scripts[i] );
  19. cmd.updatable = false;
  20. editor.execute( cmd );
  21. }
  22. for ( var i = 0; i < scripts.length; i++ ) {
  23. var cmd = new CmdRemoveScript( objects[i], scripts[i] );
  24. cmd.updatable = false;
  25. editor.execute( cmd );
  26. }
  27. ok( getScriptCount( editor ) == 0, "OK, all scripts have been removed" );
  28. scripts.map( function() {
  29. editor.undo();
  30. });
  31. ok( getScriptCount( editor ) == scripts.length, "OK, all scripts have been added again by undo(s)" );
  32. var scriptsKeys = Object.keys( editor.scripts );
  33. for (var i = 0; i < scriptsKeys.length; i++ ) {
  34. ok( editor.scripts[ scriptsKeys[i] ][0] == scripts[i], "OK, script #" + i + " is still assigned correctly" );
  35. }
  36. editor.redo();
  37. ok( getScriptCount( editor ) == scripts.length - 1, "OK, one script has been removed again by redo" );
  38. });