Ver código fonte

added test for CmdSetMaterialValue
minor change in TestCmdSetScriptName.js (changed test description)

Mario Schuettel 10 anos atrás
pai
commit
1591d5853f

+ 56 - 0
test/unit/editor/TestCmdSetMaterialValue.js

@@ -0,0 +1,56 @@
+module("CmdSetMaterialValue");
+
+test( "Test for CmdSetMaterialValue (Undo and Redo)", function() {
+
+	// setup scene
+	var editor = new Editor();
+	var box = aBox();
+	var cmd = new CmdAddObject( box );
+	cmd.updatable = false;
+	editor.execute( cmd );
+
+	// every attribute gets three test values
+	var testData = {
+		uuid: [ THREE.Math.generateUUID(), THREE.Math.generateUUID(), THREE.Math.generateUUID() ],
+		name: [ 'Alpha', 'Bravo', 'Charlie' ],
+		shininess: [ 11.1, 22.2, 33.3 ],
+		vertexColors: [ 'No', 'Face', 'Vertex' ],
+		bumpScale: [ 1.1, 2.2, 3.3 ],
+		reflectivity: [ -1.3, 2.1, 5.0 ],
+		aoMapIntensity: [ 0.1, 0.4, 0.7 ],
+		side: [ 'Front', 'Back', 'Double' ],
+		shading: [ 'No', 'Flat', 'Smooth' ],
+		blending: [ 'No', 'Normal', 'Additive' ],
+		opacity: [ 0.2, 0.5, 0.8 ],
+		alphaTest: [ 0.1, 0.6, 0.9 ],
+		wirefrimeLinewidth: [ 1.2, 3.4, 5.6 ]
+	};
+
+	var testDataKeys = Object.keys( testData );
+
+	testDataKeys.map( function( attributeName ) {
+
+		testData[ attributeName ].map( function( value ) {
+
+			var cmd = new CmdSetMaterialValue( box, attributeName, value );
+			cmd.updatable = false;
+			editor.execute( cmd );
+
+		});
+
+		var length = testData[ attributeName].length;
+		ok( box.material[ attributeName ] == testData[ attributeName ][ length - 1 ],
+			"OK, " + attributeName + " was set correctly to the last value (expected: '" + testData[ attributeName ][ length - 1 ] + "', actual: '" + box.material[ attributeName ] + "')");
+
+		editor.undo();
+		ok( box.material[ attributeName ] == testData[ attributeName ][ length - 2 ],
+			"OK, " + attributeName + " was set correctly to the second to the last value after undo (expected: '" + testData[ attributeName ][ length - 2 ] + "', actual: '" + box.material[ attributeName ] + "')");
+
+		editor.redo();
+		ok( box.material[ attributeName ] == testData[ attributeName ][ length - 1 ],
+			"OK, " + attributeName + " was set correctly to the last value again after redo (expected: '" + testData[ attributeName ][ length - 1 ] + "', actual: '" + box.material[ attributeName ] + "')");
+
+	});
+
+
+});

+ 1 - 1
test/unit/editor/TestCmdSetScriptName.js

@@ -1,6 +1,6 @@
 module("CmdSetScriptName");
 
-test( "Test CmdSetScriptValue for names", function() {
+test( "Test CmdSetScriptValue for names (Undo and Redo)", function() {
 
 	var editor = new Editor();
 

+ 2 - 0
test/unit/unittests_editor.html

@@ -81,6 +81,7 @@
 <script src="../../editor/js/CmdSetGeometry.js"></script>
 <script src="../../editor/js/CmdSetGeometryValue.js"></script>
 <script src="../../editor/js/CmdSetMaterialColor.js"></script>
+<script src="../../editor/js/CmdSetMaterialValue.js"></script>
 <script src="../../editor/js/CmdSetPosition.js"></script>
 <script src="../../editor/js/CmdSetRotation.js"></script>
 <script src="../../editor/js/CmdSetScale.js"></script>
@@ -105,6 +106,7 @@
 <script src="editor/TestCmdSetGeometry.js"></script>
 <script src="editor/TestCmdSetGeometryValue.js"></script>
 <script src="editor/TestCmdSetMaterialColor.js"></script>
+<script src="editor/TestCmdSetMaterialValue.js"></script>
 <script src="editor/TestCmdSetPosition.js"></script>
 <script src="editor/TestCmdSetRotation.js"></script>
 <script src="editor/TestCmdSetScale.js"></script>