TestCmdSetMaterialValue.js 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. module("CmdSetMaterialValue");
  2. test( "Test for CmdSetMaterialValue (Undo and Redo)", function() {
  3. // setup scene
  4. var editor = new Editor();
  5. var box = aBox();
  6. var cmd = new CmdAddObject( box );
  7. cmd.updatable = false;
  8. editor.execute( cmd );
  9. // every attribute gets three test values
  10. var testData = {
  11. uuid: [ THREE.Math.generateUUID(), THREE.Math.generateUUID(), THREE.Math.generateUUID() ],
  12. name: [ 'Alpha', 'Bravo', 'Charlie' ],
  13. shininess: [ 11.1, 22.2, 33.3 ],
  14. vertexColors: [ 'No', 'Face', 'Vertex' ],
  15. bumpScale: [ 1.1, 2.2, 3.3 ],
  16. reflectivity: [ -1.3, 2.1, 5.0 ],
  17. aoMapIntensity: [ 0.1, 0.4, 0.7 ],
  18. side: [ 'Front', 'Back', 'Double' ],
  19. shading: [ 'No', 'Flat', 'Smooth' ],
  20. blending: [ 'No', 'Normal', 'Additive' ],
  21. opacity: [ 0.2, 0.5, 0.8 ],
  22. alphaTest: [ 0.1, 0.6, 0.9 ],
  23. wirefrimeLinewidth: [ 1.2, 3.4, 5.6 ]
  24. };
  25. var testDataKeys = Object.keys( testData );
  26. testDataKeys.map( function( attributeName ) {
  27. testData[ attributeName ].map( function( value ) {
  28. var cmd = new CmdSetMaterialValue( box, attributeName, value );
  29. cmd.updatable = false;
  30. editor.execute( cmd );
  31. });
  32. var length = testData[ attributeName].length;
  33. ok( box.material[ attributeName ] == testData[ attributeName ][ length - 1 ],
  34. "OK, " + attributeName + " was set correctly to the last value (expected: '" + testData[ attributeName ][ length - 1 ] + "', actual: '" + box.material[ attributeName ] + "')");
  35. editor.undo();
  36. ok( box.material[ attributeName ] == testData[ attributeName ][ length - 2 ],
  37. "OK, " + attributeName + " was set correctly to the second to the last value after undo (expected: '" + testData[ attributeName ][ length - 2 ] + "', actual: '" + box.material[ attributeName ] + "')");
  38. editor.redo();
  39. ok( box.material[ attributeName ] == testData[ attributeName ][ length - 1 ],
  40. "OK, " + attributeName + " was set correctly to the last value again after redo (expected: '" + testData[ attributeName ][ length - 1 ] + "', actual: '" + box.material[ attributeName ] + "')");
  41. });
  42. });