SetMaterialValueCommand.tests.js 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. QUnit.module( "SetMaterialValueCommand" );
  2. QUnit.test( "Test for SetMaterialValueCommand (Undo and Redo)", function( assert ) {
  3. // setup scene
  4. var editor = new Editor();
  5. var box = aBox();
  6. var cmd = new AddObjectCommand( 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. bumpScale: [ 1.1, 2.2, 3.3 ],
  15. reflectivity: [ - 1.3, 2.1, 5.0 ],
  16. aoMapIntensity: [ 0.1, 0.4, 0.7 ],
  17. side: [ 'Front', 'Back', 'Double' ],
  18. shading: [ 'No', 'Flat', 'Smooth' ],
  19. blending: [ 'No', 'Normal', 'Additive' ],
  20. opacity: [ 0.2, 0.5, 0.8 ],
  21. alphaTest: [ 0.1, 0.6, 0.9 ],
  22. wireframeLinewidth: [ 1.2, 3.4, 5.6 ]
  23. };
  24. var testDataKeys = Object.keys( testData );
  25. testDataKeys.map( function( attributeName ) {
  26. testData[ attributeName ].map( function( value ) {
  27. var cmd = new SetMaterialValueCommand( box, attributeName, value );
  28. cmd.updatable = false;
  29. editor.execute( cmd );
  30. } );
  31. var length = testData[ attributeName ].length;
  32. assert.ok( box.material[ attributeName ] == testData[ attributeName ][ length - 1 ],
  33. "OK, " + attributeName + " was set correctly to the last value (expected: '" + testData[ attributeName ][ length - 1 ] + "', actual: '" + box.material[ attributeName ] + "')" );
  34. editor.undo();
  35. assert.ok( box.material[ attributeName ] == testData[ attributeName ][ length - 2 ],
  36. "OK, " + attributeName + " was set correctly to the second to the last value after undo (expected: '" + testData[ attributeName ][ length - 2 ] + "', actual: '" + box.material[ attributeName ] + "')" );
  37. editor.redo();
  38. assert.ok( box.material[ attributeName ] == testData[ attributeName ][ length - 1 ],
  39. "OK, " + attributeName + " was set correctly to the last value again after redo (expected: '" + testData[ attributeName ][ length - 1 ] + "', actual: '" + box.material[ attributeName ] + "')" );
  40. } );
  41. } );