|
@@ -2,30 +2,74 @@ module( "CmdSetScriptValue" );
|
|
|
|
|
|
test( "Test CmdSetScriptValue for source (Undo and Redo)", function() {
|
|
|
|
|
|
- var editor = new Editor();
|
|
|
|
|
|
+ // setup
|
|
|
+ var editor = new Editor();
|
|
|
var box = aBox( "The scripted box" );
|
|
|
- var xMove = { name: "", source: "function update( event ) { this.position.x = this.position.x + 1; }" };
|
|
|
- var yMove = { name: "", source: "function update( event ) { this.position.y = this.position.y + 1; }" };
|
|
|
- var scripts = [ xMove, yMove ];
|
|
|
+ var cmd = new CmdAddObject( box );
|
|
|
+ cmd.updatable = false;
|
|
|
+ editor.execute( cmd );
|
|
|
+
|
|
|
+ var translateScript = { name: "Translate", source: "function( update ) {}" };
|
|
|
+ cmd = new CmdAddScript( box, translateScript );
|
|
|
+ cmd.updatable = false;
|
|
|
+ editor.execute( cmd );
|
|
|
+
|
|
|
+
|
|
|
+ var testSourceData = [
|
|
|
+
|
|
|
+ { name: "Translate", source: "function update( event ) { this.position.x = this.position.x + 1; }" },
|
|
|
+ { name: "Translate", source: "function update( event ) { this.position.y = this.position.y + 1; }" },
|
|
|
+ { name: "Translate", source: "function update( event ) { this.position.z = this.position.z + 1; }" }
|
|
|
+
|
|
|
+ ];
|
|
|
+
|
|
|
+
|
|
|
+ // test source
|
|
|
+
|
|
|
+ testSourceData.map( function( script ) {
|
|
|
+
|
|
|
+ var cmd = new CmdSetScriptValue( box, translateScript, 'source', script.source , 0 );
|
|
|
+ cmd.updatable = false;
|
|
|
+ editor.execute( cmd );
|
|
|
+
|
|
|
+ });
|
|
|
+
|
|
|
+ var length = testSourceData.length;
|
|
|
+ ok( editor.scripts[ box.uuid ][0][ 'source' ] == testSourceData[ length - 1].source,
|
|
|
+ "OK, 'source' was set correctly to the last value (expected: '" + testSourceData[ length - 1 ].source + "', actual: '" + editor.scripts[ box.uuid ][0][ 'source' ] + "')");
|
|
|
+
|
|
|
+ editor.undo();
|
|
|
+ ok( editor.scripts[ box.uuid ][0][ 'source' ] == testSourceData[ length - 2 ].source,
|
|
|
+ "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' ] + "')");
|
|
|
+
|
|
|
+ editor.redo();
|
|
|
+ ok( editor.scripts[ box.uuid ][0][ 'source' ] == testSourceData[ length - 1 ].source,
|
|
|
+ "OK, 'source' was set correctly to the last value again after redo (expected: '" + testSourceData[ length - 1 ].source + "', actual: '" + editor.scripts[ box.uuid ][0][ 'source' ] + "')");
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ // test name
|
|
|
+
|
|
|
+ var names = [ "X Script", "Y Script", "Z Script" ];
|
|
|
|
|
|
- editor.execute( new CmdAddObject( box ) );
|
|
|
+ names.map( function( name ) {
|
|
|
|
|
|
- var cmd = new CmdAddScript( box, scripts[0] );
|
|
|
- cmd.updatable = false;
|
|
|
- editor.execute( cmd );
|
|
|
+ cmd = new CmdSetScriptValue( box, translateScript, 'name', name );
|
|
|
+ cmd.updatable = false;
|
|
|
+ editor.execute( cmd );
|
|
|
|
|
|
- cmd = new CmdSetScriptValue( box, xMove, 'source', yMove['source'], 0 );
|
|
|
- cmd.updatable = false;
|
|
|
- editor.execute( cmd );
|
|
|
- ok( editor.scripts[ box.uuid ][0][ 'source' ] == yMove[ 'source' ], "OK, script source has been set successfully");
|
|
|
+ });
|
|
|
|
|
|
- console.log( editor.scripts );
|
|
|
+ var scriptName = editor.scripts[ box.uuid ][0][ "name" ];
|
|
|
+ ok( scriptName == names[ names.length - 1 ], "OK, the script name corresponds to the last script name that was assigned" );
|
|
|
|
|
|
editor.undo();
|
|
|
- ok( editor.scripts[ box.uuid ][0][ 'source' ] == xMove[ 'source' ], "OK, script source has been set to previous state");
|
|
|
+ scriptName = editor.scripts[ box.uuid ][0][ "name" ];
|
|
|
+ ok( scriptName == names[ names.length - 2 ], "OK, the script name corresponds to the second last script name that was assigned" );
|
|
|
|
|
|
editor.redo();
|
|
|
- ok( editor.scripts[ box.uuid ][0][ 'source' ] == yMove[ 'source' ], "OK, script source has been reverted successfully");
|
|
|
+ scriptName = editor.scripts[ box.uuid ][0][ "name" ];
|
|
|
+ ok( scriptName == names[ names.length - 1 ], "OK, the script name corresponds to the last script name that was assigned, again" );
|
|
|
|
|
|
});
|