TestCmdSetScriptSource.js 1.1 KB

12345678910111213141516171819202122232425262728293031
  1. module( "CmdSetScriptSource" );
  2. test( "Test CmdSetScriptSource (Undo and Redo)", function() {
  3. var editor = new Editor();
  4. var box = aBox( "The scripted box" );
  5. var xMove = { name: "", source: "function update( event ) { this.position.x = this.position.x + 1; }" };
  6. var yMove = { name: "", source: "function update( event ) { this.position.y = this.position.y + 1; }" };
  7. var scripts = [ xMove, yMove ];
  8. editor.execute( new CmdAddObject( box ) );
  9. var cmd = new CmdAddScript( box, scripts[0] );
  10. cmd.updatable = false;
  11. editor.execute( cmd );
  12. cmd = new CmdSetScriptSource( box, xMove, yMove['source'], xMove['source'], 0 );
  13. cmd.updatable = false;
  14. editor.execute( cmd );
  15. ok( editor.scripts[ box.uuid ][0][ 'source' ] == yMove[ 'source' ], "OK, script source has been set successfully");
  16. console.log( editor.scripts );
  17. editor.undo();
  18. ok( editor.scripts[ box.uuid ][0][ 'source' ] == xMove[ 'source' ], "OK, script source has been set to previous state");
  19. editor.redo();
  20. ok( editor.scripts[ box.uuid ][0][ 'source' ] == yMove[ 'source' ], "OK, script source has been reverted successfully");
  21. });