TestCmdSetGeometry.js 3.7 KB

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