SetMaterialValueCommand.tests.js 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /**
  2. * @author lxxxvi / https://github.com/lxxxvi
  3. * Developed as part of a project at University of Applied Sciences and Arts Northwestern Switzerland (www.fhnw.ch)
  4. */
  5. QUnit.module( "SetMaterialValueCommand" );
  6. QUnit.test( "Test for SetMaterialValueCommand (Undo and Redo)", function( assert ) {
  7. // setup scene
  8. var editor = new Editor();
  9. var box = aBox();
  10. var cmd = new AddObjectCommand( box );
  11. cmd.updatable = false;
  12. editor.execute( cmd );
  13. // every attribute gets three test values
  14. var testData = {
  15. uuid: [ THREE.Math.generateUUID(), THREE.Math.generateUUID(), THREE.Math.generateUUID() ],
  16. name: [ 'Alpha', 'Bravo', 'Charlie' ],
  17. shininess: [ 11.1, 22.2, 33.3 ],
  18. bumpScale: [ 1.1, 2.2, 3.3 ],
  19. reflectivity: [ - 1.3, 2.1, 5.0 ],
  20. aoMapIntensity: [ 0.1, 0.4, 0.7 ],
  21. side: [ 'Front', 'Back', 'Double' ],
  22. shading: [ 'No', 'Flat', 'Smooth' ],
  23. blending: [ 'No', 'Normal', 'Additive' ],
  24. opacity: [ 0.2, 0.5, 0.8 ],
  25. alphaTest: [ 0.1, 0.6, 0.9 ],
  26. wireframeLinewidth: [ 1.2, 3.4, 5.6 ]
  27. };
  28. var testDataKeys = Object.keys( testData );
  29. testDataKeys.map( function( attributeName ) {
  30. testData[ attributeName ].map( function( value ) {
  31. var cmd = new SetMaterialValueCommand( box, attributeName, value );
  32. cmd.updatable = false;
  33. editor.execute( cmd );
  34. } );
  35. var length = testData[ attributeName ].length;
  36. assert.ok( box.material[ attributeName ] == testData[ attributeName ][ length - 1 ],
  37. "OK, " + attributeName + " was set correctly to the last value (expected: '" + testData[ attributeName ][ length - 1 ] + "', actual: '" + box.material[ attributeName ] + "')" );
  38. editor.undo();
  39. assert.ok( box.material[ attributeName ] == testData[ attributeName ][ length - 2 ],
  40. "OK, " + attributeName + " was set correctly to the second to the last value after undo (expected: '" + testData[ attributeName ][ length - 2 ] + "', actual: '" + box.material[ attributeName ] + "')" );
  41. editor.redo();
  42. assert.ok( box.material[ attributeName ] == testData[ attributeName ][ length - 1 ],
  43. "OK, " + attributeName + " was set correctly to the last value again after redo (expected: '" + testData[ attributeName ][ length - 1 ] + "', actual: '" + box.material[ attributeName ] + "')" );
  44. } );
  45. } );