TestAddObjectCommandAndRemoveObjectCommand.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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( "AddObjectCommandAndRemoveObjectCommand" );
  6. QUnit.test( "Test AddObjectCommand and RemoveObjectCommand (Undo and Redo)", function( assert ) {
  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 AddObjectCommand( object );
  16. cmd.updatable = false;
  17. editor.execute( cmd );
  18. assert.ok( editor.scene.children.length == 1, "OK, adding '" + object.type + "' was successful " );
  19. editor.undo();
  20. assert.ok( editor.scene.children.length == 0, "OK, adding '" + object.type + "' is undone (was removed)" );
  21. editor.redo();
  22. assert.ok( editor.scene.children[ 0 ].name == object.name, "OK, removed '" + object.type + "' was added again (redo)" );
  23. assert.ok( editor.selected == object, "OK, focus was set on recovered object after Add-Redo" );
  24. // Test Remove
  25. var cmd = new RemoveObjectCommand( object );
  26. cmd.updatable = false;
  27. editor.execute( cmd );
  28. assert.ok( editor.scene.children.length == 0, "OK, removing object was successful" );
  29. editor.undo();
  30. assert.ok( editor.scene.children[ 0 ].name == object.name, "OK, removed object was added again (undo)" );
  31. assert.ok( editor.selected == object, "OK, focus was set on recovered object after Delete-Undo" );
  32. editor.redo();
  33. assert.ok( editor.scene.children.length == 0, "OK, object was removed again (redo)" );
  34. } );
  35. } );