TestSetGeometryCommand.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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( "SetGeometryCommand" );
  6. QUnit.test( "Test SetGeometryCommand (Undo and Redo)", function( assert ) {
  7. var editor = new Editor();
  8. // initialize objects and geometries
  9. var box = aBox( 'Guinea Pig' ); // default ( 100, 100, 100, 1, 1, 1 )
  10. var boxGeometry1 = { geometry: { parameters: { width: 200, height: 201, depth: 202, widthSegments: 2, heightSegments: 3, depthSegments: 4 } } };
  11. var boxGeometry2 = { geometry: { parameters: { width: 50, height: 51, depth: 52, widthSegments: 7, heightSegments: 8, depthSegments: 9 } } };
  12. var geometryParams = [ boxGeometry1, boxGeometry2 ];
  13. // add the object
  14. var cmd = new AddObjectCommand( box );
  15. cmd.updatable = false;
  16. editor.execute( cmd );
  17. for ( var i = 0; i < geometryParams.length; i ++ ) {
  18. var cmd = new SetGeometryCommand( box, getGeometry( "BoxGeometry", geometryParams[ i ] ) );
  19. cmd.updatable = false;
  20. editor.execute( cmd );
  21. var actualParams = box.geometry.parameters;
  22. var expectedParams = geometryParams[ i ].geometry.parameters;
  23. assert.ok( actualParams.width == expectedParams.width, "OK, box width matches the corresponding value from boxGeometry" + ( i + 1 ) );
  24. assert.ok( actualParams.height == expectedParams.height, "OK, box height matches the corresponding value from boxGeometry" + ( i + 1 ) );
  25. assert.ok( actualParams.depth == expectedParams.depth, "OK, box depth matches the corresponding value from boxGeometry" + ( i + 1 ) );
  26. assert.ok( actualParams.widthSegments == expectedParams.widthSegments, "OK, box widthSegments matches the corresponding value from boxGeometry" + ( i + 1 ) );
  27. assert.ok( actualParams.heightSegments == expectedParams.heightSegments, "OK, box heightSegments matches the corresponding value from boxGeometry" + ( i + 1 ) );
  28. assert.ok( actualParams.depthSegments == expectedParams.depthSegments, "OK, box depthSegments matches the corresponding value from boxGeometry" + ( i + 1 ) );
  29. }
  30. editor.undo();
  31. var actualParams = box.geometry.parameters;
  32. var expectedParams = geometryParams[ 0 ].geometry.parameters;
  33. assert.ok( actualParams.width == expectedParams.width, "OK, box width matches the corresponding value from boxGeometry1 (after undo)" );
  34. assert.ok( actualParams.height == expectedParams.height, "OK, box height matches the corresponding value from boxGeometry1 (after undo)" );
  35. assert.ok( actualParams.depth == expectedParams.depth, "OK, box depth matches the corresponding value from boxGeometry1 (after undo)" );
  36. assert.ok( actualParams.widthSegments == expectedParams.widthSegments, "OK, box widthSegments matches the corresponding value from boxGeometry1 (after undo)" );
  37. assert.ok( actualParams.heightSegments == expectedParams.heightSegments, "OK, box heightSegments matches the corresponding value from boxGeometry1 (after undo)" );
  38. assert.ok( actualParams.depthSegments == expectedParams.depthSegments, "OK, box depthSegments matches the corresponding value from boxGeometry1 (after undo)" );
  39. editor.redo();
  40. var actualParams = box.geometry.parameters;
  41. var expectedParams = geometryParams[ 1 ].geometry.parameters;
  42. assert.ok( actualParams.width == expectedParams.width, "OK, box width matches the corresponding value from boxGeometry2 (after redo)" );
  43. assert.ok( actualParams.height == expectedParams.height, "OK, box height matches the corresponding value from boxGeometry2 (after redo)" );
  44. assert.ok( actualParams.depth == expectedParams.depth, "OK, box depth matches the corresponding value from boxGeometry2 (after redo)" );
  45. assert.ok( actualParams.widthSegments == expectedParams.widthSegments, "OK, box widthSegments matches the corresponding value from boxGeometry2 (after redo)" );
  46. assert.ok( actualParams.heightSegments == expectedParams.heightSegments, "OK, box heightSegments matches the corresponding value from boxGeometry2 (after redo)" );
  47. assert.ok( actualParams.depthSegments == expectedParams.depthSegments, "OK, box depthSegments matches the corresponding value from boxGeometry2 (after redo)" );
  48. } );