TestCmdAddObjectAndCmdRemoveObject.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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. module( "CmdAddObjectAndCmdRemoveObject" );
  6. test( "Test CmdAddObject and CmdRemoveObject (Undo and Redo)", function() {
  7. // setup
  8. var editor = new Editor();
  9. var box = aBox( 'The Box' );
  10. var light = aPointlight( 'The PointLight' );
  11. var camera = aPerspectiveCamera( 'The Camera' );
  12. var objects = [ box, light, camera ];
  13. objects.map( function( object ) {
  14. // Test Add
  15. var cmd = new CmdAddObject( object );
  16. cmd.updatable = false;
  17. editor.execute( cmd );
  18. ok( editor.scene.children.length == 1, "OK, adding '" + object.type + "' was successful " );
  19. editor.undo();
  20. ok( editor.scene.children.length == 0, "OK, adding '" + object.type + "' is undone (was removed)" );
  21. editor.redo();
  22. ok( editor.scene.children[ 0 ].name == object.name, "OK, removed '" + object.type + "' was added again (redo)" );
  23. // Test Remove
  24. var cmd = new CmdRemoveObject( object );
  25. cmd.updatable = false;
  26. editor.execute( cmd );
  27. ok( editor.scene.children.length == 0, "OK, removing object was successful" );
  28. editor.undo();
  29. ok( editor.scene.children[ 0 ].name == object.name, "OK, removed object was added again (undo)" );
  30. editor.redo();
  31. ok( editor.scene.children.length == 0, "OK, object was removed again (redo)" );
  32. } );
  33. } );