SetMaterialCommand.tests.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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( "SetMaterialCommand" );
  6. QUnit.test( "Test for SetMaterialCommand (Undo and Redo)", function( assert ) {
  7. // setup
  8. var editor = new Editor();
  9. var box = aBox( 'Material girl in a material world' );
  10. var cmd = new AddObjectCommand( box );
  11. cmd.updatable = false;
  12. editor.execute( cmd );
  13. materialClasses = [
  14. 'LineBasicMaterial',
  15. 'LineDashedMaterial',
  16. 'MeshBasicMaterial',
  17. 'MeshDepthMaterial',
  18. 'MeshLambertMaterial',
  19. 'MeshNormalMaterial',
  20. 'MeshPhongMaterial',
  21. 'ShaderMaterial',
  22. 'SpriteMaterial'
  23. ];
  24. materialClasses.map( function( materialClass ) {
  25. material = new THREE[ materialClass ]();
  26. editor.execute( new SetMaterialCommand( box, material ) );
  27. } );
  28. var i = materialClasses.length - 1;
  29. // initial test
  30. assert.ok( box.material.type == materialClasses[ i ],
  31. "OK, initial material type was set correctly (expected: '" + materialClasses[ i ] + "', actual: '" + box.material.type + "')" );
  32. // test undos
  33. while ( i > 0 ) {
  34. editor.undo();
  35. -- i;
  36. assert.ok( box.material.type == materialClasses[ i ],
  37. "OK, material type was set correctly after undo (expected: '" + materialClasses[ i ] + "', actual: '" + box.material.type + "')" );
  38. }
  39. // test redos
  40. while ( i < materialClasses.length - 1 ) {
  41. editor.redo();
  42. ++ i;
  43. assert.ok( box.material.type == materialClasses[ i ],
  44. "OK, material type was set correctly after redo (expected: '" + materialClasses[ i ] + "', actual: '" + box.material.type + "')" );
  45. }
  46. } );