Skip to content

Commit fea1eae

Browse files
author
Mario Schuettel
committed
simplified tests and some code cleanup
1 parent b56f3a7 commit fea1eae

6 files changed

Lines changed: 109 additions & 95 deletions

File tree

test/unit/editor/TestCmdSetPosition.js

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,37 +3,41 @@ module( "CmdSetPosition" );
33
test( "Test CmdSetPosition (Undo and Redo)", function() {
44

55
var editor = new Editor();
6+
var box = aBox();
7+
var cmd = new CmdAddObject( box );
8+
editor.execute( cmd );
69

7-
var mesh = aBox();
8-
var initPosX = 50 ;
9-
var initPosY = -80 ;
10-
var initPosZ = 30 ;
11-
mesh.position.x = initPosX ;
12-
mesh.position.y = initPosY ;
13-
mesh.position.z = initPosZ ;
10+
var positions = [
1411

15-
editor.execute( new CmdAddObject( mesh ) );
16-
editor.select( mesh );
12+
{ x: 50, y: -80, z: 30 },
13+
{ x: -10, y: 100, z: 0 },
14+
{ x: 44, y: -20, z: 90 }
1715

18-
// translate the object
19-
var newPosX = 100 ;
20-
var newPosY = 200 ;
21-
var newPosZ = 500 ;
22-
var newPosition = new THREE.Vector3( newPosX, newPosY, newPosZ );
23-
editor.execute( new CmdSetPosition( mesh, newPosition ) );
16+
];
17+
18+
positions.map( function( position ) {
19+
20+
var newPosition = new THREE.Vector3( position.x, position.y, position.z );
21+
var cmd = new CmdSetPosition( box, newPosition );
22+
cmd.updatable = false;
23+
editor.execute( cmd );
24+
25+
});
26+
27+
ok( box.position.x == positions[ positions.length - 1 ].x, "OK, changing X position was successful" );
28+
ok( box.position.y == positions[ positions.length - 1 ].y, "OK, changing Y position was successful" );
29+
ok( box.position.z == positions[ positions.length - 1 ].z, "OK, changing Z position was successful" );
2430

25-
ok( mesh.position.x != initPosX, "OK, changing X position was successful" );
26-
ok( mesh.position.y != initPosY, "OK, changing Y position was successful" );
27-
ok( mesh.position.z != initPosZ, "OK, changing Z position was successful" );
2831

2932
editor.undo();
30-
ok( mesh.position.x == initPosX, "OK, changing X position value is undone" );
31-
ok( mesh.position.y == initPosY, "OK, changing Y position value is undone" );
32-
ok( mesh.position.z == initPosZ, "OK, changing Z position value is undone" );
33+
ok( box.position.x == positions[ positions.length - 2 ].x, "OK, changing X position was successful (after undo)" );
34+
ok( box.position.y == positions[ positions.length - 2 ].y, "OK, changing Y position was successful (after undo)" );
35+
ok( box.position.z == positions[ positions.length - 2 ].z, "OK, changing Z position was successful (after undo)" );
3336

3437
editor.redo();
35-
ok( mesh.position.x == newPosX, "OK, changing X position value is redone" );
36-
ok( mesh.position.y == newPosY, "OK, changing Y position value is redone" );
37-
ok( mesh.position.z == newPosZ, "OK, changing Z position value is redone" );
38+
ok( box.position.x == positions[ positions.length - 1 ].x, "OK, changing X position was successful (after redo)" );
39+
ok( box.position.y == positions[ positions.length - 1 ].y, "OK, changing Y position was successful (after redo)" );
40+
ok( box.position.z == positions[ positions.length - 1 ].z, "OK, changing Z position was successful (after redo)" );
41+
3842

3943
});

test/unit/editor/TestCmdSetRotation.js

Lines changed: 31 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,38 +2,45 @@ module( "CmdSetRotation" );
22

33
test( "Test CmdSetRotation (Undo and Redo)", function() {
44

5+
// setup
56
var editor = new Editor();
7+
var box = aBox();
8+
editor.execute( new CmdAddObject( box ) );
69

7-
var mesh = aBox();
8-
var initRotationX = 1.1 ;
9-
var initRotationY = 0.4 ;
10-
var initRotationZ = -2.0 ;
11-
mesh.rotation.x = initRotationX ;
12-
mesh.rotation.y = initRotationY ;
13-
mesh.rotation.z = initRotationZ ;
1410

15-
editor.execute( new CmdAddObject( mesh ) );
16-
editor.select( mesh );
11+
var rotations = [
1712

18-
// rotate the object
19-
var newRotationX = -3.2 ;
20-
var newRotationY = 0.8 ;
21-
var newRotationZ = 1.5 ;
22-
var newRotation = new THREE.Euler( newRotationX, newRotationY, newRotationZ );
23-
editor.execute ( new CmdSetRotation( mesh, newRotation ) );
13+
{ x: 1.1, y: 0.4, z: -2.0 },
14+
{ x: 2.2, y: -1.3, z: 1.3 },
15+
{ x: 0.3, y: -0.1, z: -1.9 }
2416

25-
ok( mesh.rotation.x != initRotationX, "OK, changing X rotation was successful" );
26-
ok( mesh.rotation.y != initRotationY, "OK, changing Y rotation was successful" );
27-
ok( mesh.rotation.z != initRotationZ, "OK, changing Z rotation was successful" );
17+
];
18+
19+
20+
rotations.map( function( rotation ) {
21+
22+
var newRotation = new THREE.Euler( rotation.x, rotation.y, rotation.z );
23+
var cmd = new CmdSetRotation( box, newRotation );
24+
cmd.updatable = false;
25+
editor.execute ( cmd );
26+
27+
});
28+
29+
30+
ok( box.rotation.x == rotations[ rotations.length - 1 ].x, "OK, changing X rotation was successful" );
31+
ok( box.rotation.y == rotations[ rotations.length - 1 ].y, "OK, changing Y rotation was successful" );
32+
ok( box.rotation.z == rotations[ rotations.length - 1 ].z, "OK, changing Z rotation was successful" );
2833

2934
editor.undo();
30-
ok( mesh.rotation.x == initRotationX, "OK, changing X rotation value is undone" );
31-
ok( mesh.rotation.y == initRotationY, "OK, changing Y rotation value is undone" );
32-
ok( mesh.rotation.z == initRotationZ, "OK, changing Z rotation value is undone" );
35+
ok( box.rotation.x == rotations[ rotations.length - 2 ].x, "OK, changing X rotation was successful (after undo)" );
36+
ok( box.rotation.y == rotations[ rotations.length - 2 ].y, "OK, changing Y rotation was successful (after undo)" );
37+
ok( box.rotation.z == rotations[ rotations.length - 2 ].z, "OK, changing Z rotation was successful (after undo)" );
3338

3439
editor.redo();
35-
ok( mesh.rotation.x == newRotationX, "OK, changing X rotation value is redone" );
36-
ok( mesh.rotation.y == newRotationY, "OK, changing Y rotation value is redone" );
37-
ok( mesh.rotation.z == newRotationZ, "OK, changing Z rotation value is redone" );
40+
ok( box.rotation.x == rotations[ rotations.length - 1 ].x, "OK, changing X rotation was successful (after redo)" );
41+
ok( box.rotation.y == rotations[ rotations.length - 1 ].y, "OK, changing Y rotation was successful (after redo)" );
42+
ok( box.rotation.z == rotations[ rotations.length - 1 ].z, "OK, changing Z rotation was successful (after redo)" );
43+
44+
3845

3946
});

test/unit/editor/TestCmdSetScale.js

Lines changed: 32 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,38 +2,46 @@ module( "CmdSetScale" );
22

33
test( "Test CmdSetScale (Undo and Redo)", function() {
44

5+
// setup
56
var editor = new Editor();
7+
var box = aBox();
8+
editor.execute( new CmdAddObject( box ) );
69

7-
var mesh = aBox();
8-
var initScaleX = 1.4 ;
9-
var initScaleY = 2.7 ;
10-
var initScaleZ = 0.4 ;
11-
mesh.scale.x = initScaleX ;
12-
mesh.scale.y = initScaleY ;
13-
mesh.scale.z = initScaleZ ;
1410

15-
editor.execute( new CmdAddObject( mesh ) );
16-
editor.select( mesh );
11+
// scales
12+
var scales = [
1713

18-
// (re)scale the object
19-
var newScaleX = 0.1 ;
20-
var newScaleY = 5.3 ;
21-
var newScaleZ = 1.0 ;
22-
var newScale = new THREE.Vector3( newScaleX, newScaleY, newScaleZ );
23-
editor.execute ( new CmdSetScale( mesh, newScale ) );
14+
{ x: 1.4, y: 2.7, z: 0.4 },
15+
{ x: 0.1, y: 1.3, z: 2.9 },
16+
{ x: 3.2, y: 0.3, z: 2.0 }
17+
18+
];
19+
20+
scales.map( function( scale ) {
21+
22+
var newScale = new THREE.Vector3( scale.x, scale.y, scale.z );
23+
var cmd = new CmdSetScale( box, newScale );
24+
cmd.updatable = false;
25+
editor.execute( cmd );
26+
27+
28+
});
29+
30+
ok( box.scale.x == scales[ scales.length - 1 ].x, "OK, setting X scale value was successful" );
31+
ok( box.scale.y == scales[ scales.length - 1 ].y, "OK, setting Y scale value was successful" );
32+
ok( box.scale.z == scales[ scales.length - 1 ].z, "OK, setting Z scale value was successful" );
2433

25-
ok( mesh.scale.x != initScaleX, "OK, changing X scale was successful" );
26-
ok( mesh.scale.y != initScaleY, "OK, changing Y scale was successful" );
27-
ok( mesh.scale.z != initScaleZ, "OK, changing Z scale was successful" );
2834

2935
editor.undo();
30-
ok( mesh.scale.x == initScaleX, "OK, changing X scale value is undone" );
31-
ok( mesh.scale.y == initScaleY, "OK, changing Y scale value is undone" );
32-
ok( mesh.scale.z == initScaleZ, "OK, changing Z scale value is undone" );
36+
ok( box.scale.x == scales[ scales.length - 2 ].x, "OK, X scale is correct after undo" );
37+
ok( box.scale.y == scales[ scales.length - 2 ].y, "OK, Y scale is correct after undo" );
38+
ok( box.scale.z == scales[ scales.length - 2 ].z, "OK, Z scale is correct after undo" );
39+
3340

3441
editor.redo();
35-
ok( mesh.scale.x == newScaleX, "OK, changing X scale value is redone" );
36-
ok( mesh.scale.y == newScaleY, "OK, changing Y scale value is redone" );
37-
ok( mesh.scale.z == newScaleZ, "OK, changing Z scale value is redone" );
42+
ok( box.scale.x == scales[ scales.length - 1 ].x, "OK, X scale is correct after redo" );
43+
ok( box.scale.y == scales[ scales.length - 1 ].y, "OK, Y scale is correct after redo" );
44+
ok( box.scale.z == scales[ scales.length - 1 ].z, "OK, Z scale is correct after redo" );
45+
3846

3947
});

test/unit/editor/TestCmdSetUuid.js

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,30 @@ module( "CmdSetUuid" );
33
test( "Test CmdSetUuid (Undo and Redo)", function(){
44

55
var editor = new Editor();
6-
var theName = "Initial name";
7-
var object = aBox( theName );
6+
var object = aBox( 'UUID test box' );
7+
editor.execute( new CmdAddObject( object ) );
88

9-
var uuidBefore = THREE.Math.generateUUID();
10-
var uuidAfter = THREE.Math.generateUUID();
119

12-
editor.execute( new CmdAddObject( object ) );
10+
var uuids = [ THREE.Math.generateUUID(), THREE.Math.generateUUID(), THREE.Math.generateUUID() ];
11+
12+
uuids.map( function( uuid ) {
1313

14-
var cmd = new CmdSetUuid( object, uuidBefore );
15-
cmd.updatable = false;
16-
editor.execute( cmd );
17-
ok( object[ 'uuid' ] == uuidBefore, "OK, UUID is correct after first execute ");
14+
var cmd = new CmdSetUuid( object, uuid );
15+
cmd.updatable = false;
16+
editor.execute( cmd );
1817

19-
var cmd = new CmdSetUuid( object, uuidAfter );
20-
cmd.updatable = false;
21-
editor.execute( cmd );
22-
ok( object[ 'uuid' ] == uuidAfter, "OK, UUID is correct after second execute ");
18+
});
19+
20+
ok( object.uuid == uuids[ uuids.length - 1 ],
21+
"OK, UUID on actual object matches last UUID in the test data array " );
2322

2423
editor.undo();
25-
ok( object[ 'uuid' ] == uuidBefore, "OK, UUID is correct after undo ");
24+
ok( object.uuid == uuids[ uuids.length - 2 ],
25+
"OK, UUID on actual object matches second to the last UUID in the test data array (after undo)" );
2626

2727
editor.redo();
28-
ok( object[ 'uuid' ] == uuidAfter, "OK, UUID is correct after redo ");
28+
ok( object.uuid == uuids[ uuids.length - 1 ],
29+
"OK, UUID on actual object matches last UUID in the test data array again (after redo) " );
30+
2931

3032
});

test/unit/editor/TestNestedDoUndoRedo.js

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@ test( "Test nested Do's, Undo's and Redo's ", function() {
3131
// let's begin
3232
editor.execute( new CmdAddObject( mesh ) );
3333

34-
// editor.execute( new CmdNameObject( editor, mesh, 'Nothing is as it was before' ) );
35-
3634
var newPos = new THREE.Vector3( initPosX + 100, initPosY, initPosZ );
3735
editor.execute( new CmdSetPosition( mesh, newPos ) );
3836

@@ -44,7 +42,6 @@ test( "Test nested Do's, Undo's and Redo's ", function() {
4442

4543

4644
/* full check */
47-
// ok( mesh.name == "Nothing is as it was before", "OK, name is correct" );
4845

4946
ok( mesh.position.x == 102, "OK, X position is correct " );
5047
ok( mesh.position.y == 3, "OK, Y position is correct " );
@@ -62,10 +59,8 @@ test( "Test nested Do's, Undo's and Redo's ", function() {
6259
editor.undo(); // rescaling undone
6360
editor.undo(); // rotation undone
6461
editor.undo(); // translation undone
65-
// editor.undo(); // renaming undone
6662

6763
/* full check */
68-
// ok( mesh.name == "One box unlike all others", "OK, name is correct" );
6964

7065
ok( mesh.position.x == 2, "OK, X position is correct " );
7166
ok( mesh.position.y == 3, "OK, Y position is correct " );
@@ -80,7 +75,6 @@ test( "Test nested Do's, Undo's and Redo's ", function() {
8075
ok( mesh.scale.z == 24, "OK, Z scale is correct " );
8176

8277

83-
// editor.redo(); // renaming redone
8478
editor.redo(); // translation redone
8579
editor.redo(); // rotation redone
8680

@@ -94,7 +88,6 @@ test( "Test nested Do's, Undo's and Redo's ", function() {
9488
editor.undo(); // rotation undone (expected!)
9589

9690
/* full check */
97-
// ok( mesh.name == "Nothing is as it was before", "OK, name is correct" );
9891

9992
ok( mesh.position.x == 102, "OK, X position is correct " );
10093
ok( mesh.position.y == 3, "OK, Y position is correct " );

test/unit/editor/TestSerialization.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ test( "Test Serialization (simple)", function() {
5555

5656
// Forward tests
5757

58-
for (var i = 0; i < setups.length ; i++ ) {
58+
for ( var i = 0; i < setups.length ; i++ ) {
5959

6060
setups[i]();
6161

0 commit comments

Comments
 (0)