TestCmdSetScriptName.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. module("CmdSetScriptName");
  2. test( "Test CmdSetScriptName", 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 names = [ "name 1", "name 2" ];
  7. editor.execute( new CmdAddObject( box ) );
  8. var cmd = new CmdAddScript( box, xMove );
  9. editor.execute( cmd );
  10. ok( Object.keys( editor.scripts ).length == 1, "OK, script has been added" );
  11. names.map( function( name ) {
  12. cmd = new CmdSetScriptName( box, xMove, name );
  13. cmd.updatable = false;
  14. editor.execute( cmd );
  15. });
  16. var scriptName = editor.scripts[ box.uuid ][0][ "name" ];
  17. ok( scriptName == names[ names.length - 1 ], "OK, the script name corresponds to the last script name that was assigned" );
  18. editor.undo();
  19. scriptName = editor.scripts[ box.uuid ][0][ "name" ];
  20. ok( scriptName == names[ names.length - 2 ], "OK, the script name corresponds to the second last script name that was assigned" );
  21. editor.redo();
  22. var scriptName = editor.scripts[ box.uuid ][0][ "name" ];
  23. ok( scriptName == names[ names.length - 1 ], "OK, the script name corresponds to the last script name that was assigned, again" );
  24. });