SetMaterialValueCommand.tests.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. vertexColors: [ 'No', 'Face', 'Vertex' ],
  19. bumpScale: [ 1.1, 2.2, 3.3 ],
  20. reflectivity: [ - 1.3, 2.1, 5.0 ],
  21. aoMapIntensity: [ 0.1, 0.4, 0.7 ],
  22. side: [ 'Front', 'Back', 'Double' ],
  23. shading: [ 'No', 'Flat', 'Smooth' ],
  24. blending: [ 'No', 'Normal', 'Additive' ],
  25. opacity: [ 0.2, 0.5, 0.8 ],
  26. alphaTest: [ 0.1, 0.6, 0.9 ],
  27. wireframeLinewidth: [ 1.2, 3.4, 5.6 ]
  28. };
  29. var testDataKeys = Object.keys( testData );
  30. testDataKeys.map( function( attributeName ) {
  31. testData[ attributeName ].map( function( value ) {
  32. var cmd = new SetMaterialValueCommand( box, attributeName, value );
  33. cmd.updatable = false;
  34. editor.execute( cmd );
  35. } );
  36. var length = testData[ attributeName ].length;
  37. assert.ok( box.material[ attributeName ] == testData[ attributeName ][ length - 1 ],
  38. "OK, " + attributeName + " was set correctly to the last value (expected: '" + testData[ attributeName ][ length - 1 ] + "', actual: '" + box.material[ attributeName ] + "')" );
  39. editor.undo();
  40. assert.ok( box.material[ attributeName ] == testData[ attributeName ][ length - 2 ],
  41. "OK, " + attributeName + " was set correctly to the second to the last value after undo (expected: '" + testData[ attributeName ][ length - 2 ] + "', actual: '" + box.material[ attributeName ] + "')" );
  42. editor.redo();
  43. assert.ok( box.material[ attributeName ] == testData[ attributeName ][ length - 1 ],
  44. "OK, " + attributeName + " was set correctly to the last value again after redo (expected: '" + testData[ attributeName ][ length - 1 ] + "', actual: '" + box.material[ attributeName ] + "')" );
  45. } );
  46. } );