TestCmdSetScriptValue.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. module( "CmdSetScriptValue" );
  2. test( "Test CmdSetScriptValue for source (Undo and Redo)", function() {
  3. // setup
  4. var editor = new Editor();
  5. var box = aBox( "The scripted box" );
  6. var cmd = new CmdAddObject( box );
  7. cmd.updatable = false;
  8. editor.execute( cmd );
  9. var translateScript = { name: "Translate", source: "function( update ) {}" };
  10. cmd = new CmdAddScript( box, translateScript );
  11. cmd.updatable = false;
  12. editor.execute( cmd );
  13. var testSourceData = [
  14. { name: "Translate", source: "function update( event ) { this.position.x = this.position.x + 1; }" },
  15. { name: "Translate", source: "function update( event ) { this.position.y = this.position.y + 1; }" },
  16. { name: "Translate", source: "function update( event ) { this.position.z = this.position.z + 1; }" }
  17. ];
  18. // test source
  19. testSourceData.map( function( script ) {
  20. var cmd = new CmdSetScriptValue( box, translateScript, 'source', script.source , 0 );
  21. cmd.updatable = false;
  22. editor.execute( cmd );
  23. });
  24. var length = testSourceData.length;
  25. ok( editor.scripts[ box.uuid ][0][ 'source' ] == testSourceData[ length - 1].source,
  26. "OK, 'source' was set correctly to the last value (expected: '" + testSourceData[ length - 1 ].source + "', actual: '" + editor.scripts[ box.uuid ][0][ 'source' ] + "')");
  27. editor.undo();
  28. ok( editor.scripts[ box.uuid ][0][ 'source' ] == testSourceData[ length - 2 ].source,
  29. "OK, 'source' was set correctly to the second to the last value after undo (expected: '" + testSourceData[ length - 2 ].source + "', actual: '" + editor.scripts[ box.uuid ][0][ 'source' ] + "')");
  30. editor.redo();
  31. ok( editor.scripts[ box.uuid ][0][ 'source' ] == testSourceData[ length - 1 ].source,
  32. "OK, 'source' was set correctly to the last value again after redo (expected: '" + testSourceData[ length - 1 ].source + "', actual: '" + editor.scripts[ box.uuid ][0][ 'source' ] + "')");
  33. // test name
  34. var names = [ "X Script", "Y Script", "Z Script" ];
  35. names.map( function( name ) {
  36. cmd = new CmdSetScriptValue( box, translateScript, 'name', name );
  37. cmd.updatable = false;
  38. editor.execute( cmd );
  39. });
  40. var scriptName = editor.scripts[ box.uuid ][0][ "name" ];
  41. ok( scriptName == names[ names.length - 1 ], "OK, the script name corresponds to the last script name that was assigned" );
  42. editor.undo();
  43. scriptName = editor.scripts[ box.uuid ][0][ "name" ];
  44. ok( scriptName == names[ names.length - 2 ], "OK, the script name corresponds to the second last script name that was assigned" );
  45. editor.redo();
  46. scriptName = editor.scripts[ box.uuid ][0][ "name" ];
  47. ok( scriptName == names[ names.length - 1 ], "OK, the script name corresponds to the last script name that was assigned, again" );
  48. });