TestSetPositionCommand.js 1.7 KB
Newer Older
M
Mario Schuettel 已提交
1 2 3 4 5
/**
 * @author lxxxvi / https://github.com/lxxxvi
 * Developed as part of a project at University of Applied Sciences and Arts Northwestern Switzerland (www.fhnw.ch)
 */

6
module( "SetPositionCommand" );
7

8
test( "Test SetPositionCommand (Undo and Redo)", function() {
9 10

	var editor = new Editor();
11
	var box = aBox();
12
	var cmd = new AddObjectCommand( box );
13
	editor.execute( cmd );
14

15
	var positions = [
16

17 18 19
		{ x:   50, y: - 80, z: 30 },
		{ x: - 10, y:  100, z:  0 },
		{ x:   44, y: - 20, z: 90 }
20

21 22 23 24 25
	];

	positions.map( function( position ) {

		var newPosition = new THREE.Vector3( position.x, position.y, position.z );
26
		var cmd = new SetPositionCommand( box, newPosition );
27 28 29
		cmd.updatable = false;
		editor.execute( cmd );

30
	} );
31 32 33 34

	ok( box.position.x == positions[ positions.length - 1 ].x, "OK, changing X position was successful" );
	ok( box.position.y == positions[ positions.length - 1 ].y, "OK, changing Y position was successful" );
	ok( box.position.z == positions[ positions.length - 1 ].z, "OK, changing Z position was successful" );
35 36 37


	editor.undo();
38 39 40
	ok( box.position.x == positions[ positions.length - 2 ].x, "OK, changing X position was successful (after undo)" );
	ok( box.position.y == positions[ positions.length - 2 ].y, "OK, changing Y position was successful (after undo)" );
	ok( box.position.z == positions[ positions.length - 2 ].z, "OK, changing Z position was successful (after undo)" );
41 42

	editor.redo();
43 44 45 46
	ok( box.position.x == positions[ positions.length - 1 ].x, "OK, changing X position was successful (after redo)" );
	ok( box.position.y == positions[ positions.length - 1 ].y, "OK, changing Y position was successful (after redo)" );
	ok( box.position.z == positions[ positions.length - 1 ].z, "OK, changing Z position was successful (after redo)" );

47

48
} );