SetValueCommand.tests.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. QUnit.module( "SetValueCommand" );
  2. QUnit.test( "Test SetValueCommand (Undo and Redo)", function( assert ) {
  3. var editor = new Editor();
  4. var valueBefore = 1.10;
  5. var valueAfter = 2.20;
  6. var box = aBox( 'A Box' );
  7. var light = aPointlight( 'A PointLight' );
  8. var cam = aPerspectiveCamera( 'A PerspectiveCamera' );
  9. [ box, light, cam ].map( function( object ) {
  10. editor.execute( new AddObjectCommand( object ) );
  11. assert.ok( 0 == 0, "Testing object of type '" + object.type + "'" );
  12. [ 'name', 'fov', 'near', 'far', 'intensity', 'distance', 'angle', 'exponent', 'decay', 'visible', 'userData' ].map( function( item ) {
  13. if ( object[ item ] !== undefined ) {
  14. var cmd = new SetValueCommand( object, item, valueBefore );
  15. cmd.updatable = false;
  16. editor.execute( cmd );
  17. assert.ok( object[ item ] == valueBefore, " OK, the attribute '" + item + "' is correct after first execute (expected: '" + valueBefore + "', actual: '" + object[ item ] + "')" );
  18. var cmd = new SetValueCommand( object, item, valueAfter );
  19. cmd.updatable = false;
  20. editor.execute( cmd );
  21. assert.ok( object[ item ] == valueAfter, " OK, the attribute '" + item + "' is correct after second execute (expected: '" + valueAfter + "', actual: '" + object[ item ] + "')" );
  22. editor.undo();
  23. assert.ok( object[ item ] == valueBefore, " OK, the attribute '" + item + "' is correct after undo (expected: '" + valueBefore + "', actual: '" + object[ item ] + "')" );
  24. editor.redo();
  25. assert.ok( object[ item ] == valueAfter, " OK, the attribute '" + item + "' is correct after redo (expected: '" + valueAfter + "', actual: '" + object[ item ] + "')" );
  26. }
  27. } );
  28. } );
  29. } );