SetMaterialCommand.tests.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. QUnit.module( "SetMaterialCommand" );
  2. QUnit.test( "Test for SetMaterialCommand (Undo and Redo)", function( assert ) {
  3. // setup
  4. var editor = new Editor();
  5. var box = aBox( 'Material girl in a material world' );
  6. var cmd = new AddObjectCommand( 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 SetMaterialCommand( box, material ) );
  23. } );
  24. var i = materialClasses.length - 1;
  25. // initial test
  26. assert.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. assert.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. assert.ok( box.material.type == materialClasses[ i ],
  40. "OK, material type was set correctly after redo (expected: '" + materialClasses[ i ] + "', actual: '" + box.material.type + "')" );
  41. }
  42. } );