TestCmdSetMaterial.js 1.4 KB

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