Browse Source

merged TestCmdSetScriptName.js (leftover) into TestCmdSetScriptValue.js
removed TestCmdSetScriptName.js

Mario Schuettel 9 years ago
parent
commit
4dff803dcb

+ 0 - 37
test/unit/editor/TestCmdSetScriptName.js

@@ -1,37 +0,0 @@
-module("CmdSetScriptName");
-
-test( "Test CmdSetScriptValue for names (Undo and Redo)", function() {
-
-	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 names = [ "name 1", "name 2" ];
-
-	editor.execute( new CmdAddObject( box ) );
-
-	var cmd = new CmdAddScript( box, xMove );
-	editor.execute( cmd );
-
-	ok( Object.keys( editor.scripts ).length == 1, "OK, script has been added" );
-
-	names.map( function( name ) {
-
-		cmd = new CmdSetScriptValue( box, xMove, 'name', name );
-		cmd.updatable = false;
-		editor.execute( cmd );
-
-	});
-	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();
-	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();
-	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, again" );
-
-});

+ 59 - 15
test/unit/editor/TestCmdSetScriptValue.js

@@ -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" );
 
 });

+ 0 - 1
test/unit/unittests_editor.html

@@ -112,7 +112,6 @@
 <script src="editor/TestCmdSetRotation.js"></script>
 <script src="editor/TestCmdSetScale.js"></script>
 <script src="editor/TestCmdSetScene.js"></script>
-<script src="editor/TestCmdSetScriptName.js"></script>
 <script src="editor/TestCmdSetScriptValue.js"></script>
 <script src="editor/TestCmdSetUuid.js"></script>
 <script src="editor/TestCmdSetValue.js"></script>