TestSetScriptValueCommand.js 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /**
  2. * @author lxxxvi / https://github.com/lxxxvi
  3. * Developed as part of a project at University of Applied Sciences and Arts Northwestern Switzerland (www.fhnw.ch)
  4. */
  5. module( "SetScriptValueCommand" );
  6. test( "Test SetScriptValueCommand for source (Undo and Redo)", function() {
  7. // setup
  8. var editor = new Editor();
  9. var box = aBox( "The scripted box" );
  10. var cmd = new AddObjectCommand( box );
  11. cmd.updatable = false;
  12. editor.execute( cmd );
  13. var translateScript = { name: "Translate", source: "function( update ) {}" };
  14. cmd = new AddScriptCommand( box, translateScript );
  15. cmd.updatable = false;
  16. editor.execute( cmd );
  17. var testSourceData = [
  18. { name: "Translate", source: "function update( event ) { this.position.x = this.position.x + 1; }" },
  19. { name: "Translate", source: "function update( event ) { this.position.y = this.position.y + 1; }" },
  20. { name: "Translate", source: "function update( event ) { this.position.z = this.position.z + 1; }" }
  21. ];
  22. // test source
  23. testSourceData.map( function( script ) {
  24. var cmd = new SetScriptValueCommand( box, translateScript, 'source', script.source, 0 );
  25. cmd.updatable = false;
  26. editor.execute( cmd );
  27. } );
  28. var length = testSourceData.length;
  29. ok( editor.scripts[ box.uuid ][ 0 ][ 'source' ] == testSourceData[ length - 1 ].source,
  30. "OK, 'source' was set correctly to the last value (expected: '" + testSourceData[ length - 1 ].source + "', actual: '" + editor.scripts[ box.uuid ][ 0 ][ 'source' ] + "')" );
  31. editor.undo();
  32. ok( editor.scripts[ box.uuid ][ 0 ][ 'source' ] == testSourceData[ length - 2 ].source,
  33. "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' ] + "')" );
  34. editor.redo();
  35. ok( editor.scripts[ box.uuid ][ 0 ][ 'source' ] == testSourceData[ length - 1 ].source,
  36. "OK, 'source' was set correctly to the last value again after redo (expected: '" + testSourceData[ length - 1 ].source + "', actual: '" + editor.scripts[ box.uuid ][ 0 ][ 'source' ] + "')" );
  37. var names = [ "X Script", "Y Script", "Z Script" ];
  38. names.map( function( name ) {
  39. cmd = new SetScriptValueCommand( box, translateScript, 'name', name );
  40. cmd.updatable = false;
  41. editor.execute( cmd );
  42. } );
  43. var scriptName = editor.scripts[ box.uuid ][ 0 ][ "name" ];
  44. ok( scriptName == names[ names.length - 1 ], "OK, the script name corresponds to the last script name that was assigned" );
  45. editor.undo();
  46. scriptName = editor.scripts[ box.uuid ][ 0 ][ "name" ];
  47. ok( scriptName == names[ names.length - 2 ], "OK, the script name corresponds to the second last script name that was assigned" );
  48. editor.redo();
  49. scriptName = editor.scripts[ box.uuid ][ 0 ][ "name" ];
  50. ok( scriptName == names[ names.length - 1 ], "OK, the script name corresponds to the last script name that was assigned, again" );
  51. } );