Skip to content

Commit 4dff803

Browse files
committed
merged TestCmdSetScriptName.js (leftover) into TestCmdSetScriptValue.js
removed TestCmdSetScriptName.js
1 parent fb3a281 commit 4dff803

3 files changed

Lines changed: 59 additions & 53 deletions

File tree

test/unit/editor/TestCmdSetScriptName.js

Lines changed: 0 additions & 37 deletions
This file was deleted.

test/unit/editor/TestCmdSetScriptValue.js

Lines changed: 59 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,74 @@ module( "CmdSetScriptValue" );
22

33
test( "Test CmdSetScriptValue for source (Undo and Redo)", function() {
44

5-
var editor = new Editor();
65

6+
// setup
7+
var editor = new Editor();
78
var box = aBox( "The scripted box" );
8-
var xMove = { name: "", source: "function update( event ) { this.position.x = this.position.x + 1; }" };
9-
var yMove = { name: "", source: "function update( event ) { this.position.y = this.position.y + 1; }" };
10-
var scripts = [ xMove, yMove ];
9+
var cmd = new CmdAddObject( box );
10+
cmd.updatable = false;
11+
editor.execute( cmd );
12+
13+
var translateScript = { name: "Translate", source: "function( update ) {}" };
14+
cmd = new CmdAddScript( box, translateScript );
15+
cmd.updatable = false;
16+
editor.execute( cmd );
17+
18+
19+
var testSourceData = [
20+
21+
{ name: "Translate", source: "function update( event ) { this.position.x = this.position.x + 1; }" },
22+
{ name: "Translate", source: "function update( event ) { this.position.y = this.position.y + 1; }" },
23+
{ name: "Translate", source: "function update( event ) { this.position.z = this.position.z + 1; }" }
24+
25+
];
26+
27+
28+
// test source
29+
30+
testSourceData.map( function( script ) {
31+
32+
var cmd = new CmdSetScriptValue( box, translateScript, 'source', script.source , 0 );
33+
cmd.updatable = false;
34+
editor.execute( cmd );
35+
36+
});
37+
38+
var length = testSourceData.length;
39+
ok( editor.scripts[ box.uuid ][0][ 'source' ] == testSourceData[ length - 1].source,
40+
"OK, 'source' was set correctly to the last value (expected: '" + testSourceData[ length - 1 ].source + "', actual: '" + editor.scripts[ box.uuid ][0][ 'source' ] + "')");
41+
42+
editor.undo();
43+
ok( editor.scripts[ box.uuid ][0][ 'source' ] == testSourceData[ length - 2 ].source,
44+
"OK, 'source' was set correctly to the second to the last value after undo (expected: '" + testSourceData[ length - 2 ].source + "', actual: '" + editor.scripts[ box.uuid ][0][ 'source' ] + "')");
45+
46+
editor.redo();
47+
ok( editor.scripts[ box.uuid ][0][ 'source' ] == testSourceData[ length - 1 ].source,
48+
"OK, 'source' was set correctly to the last value again after redo (expected: '" + testSourceData[ length - 1 ].source + "', actual: '" + editor.scripts[ box.uuid ][0][ 'source' ] + "')");
49+
50+
51+
52+
// test name
53+
54+
var names = [ "X Script", "Y Script", "Z Script" ];
1155

12-
editor.execute( new CmdAddObject( box ) );
56+
names.map( function( name ) {
1357

14-
var cmd = new CmdAddScript( box, scripts[0] );
15-
cmd.updatable = false;
16-
editor.execute( cmd );
58+
cmd = new CmdSetScriptValue( box, translateScript, 'name', name );
59+
cmd.updatable = false;
60+
editor.execute( cmd );
1761

18-
cmd = new CmdSetScriptValue( box, xMove, 'source', yMove['source'], 0 );
19-
cmd.updatable = false;
20-
editor.execute( cmd );
21-
ok( editor.scripts[ box.uuid ][0][ 'source' ] == yMove[ 'source' ], "OK, script source has been set successfully");
62+
});
2263

23-
console.log( editor.scripts );
64+
var scriptName = editor.scripts[ box.uuid ][0][ "name" ];
65+
ok( scriptName == names[ names.length - 1 ], "OK, the script name corresponds to the last script name that was assigned" );
2466

2567
editor.undo();
26-
ok( editor.scripts[ box.uuid ][0][ 'source' ] == xMove[ 'source' ], "OK, script source has been set to previous state");
68+
scriptName = editor.scripts[ box.uuid ][0][ "name" ];
69+
ok( scriptName == names[ names.length - 2 ], "OK, the script name corresponds to the second last script name that was assigned" );
2770

2871
editor.redo();
29-
ok( editor.scripts[ box.uuid ][0][ 'source' ] == yMove[ 'source' ], "OK, script source has been reverted successfully");
72+
scriptName = editor.scripts[ box.uuid ][0][ "name" ];
73+
ok( scriptName == names[ names.length - 1 ], "OK, the script name corresponds to the last script name that was assigned, again" );
3074

3175
});

test/unit/unittests_editor.html

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,6 @@
112112
<script src="editor/TestCmdSetRotation.js"></script>
113113
<script src="editor/TestCmdSetScale.js"></script>
114114
<script src="editor/TestCmdSetScene.js"></script>
115-
<script src="editor/TestCmdSetScriptName.js"></script>
116115
<script src="editor/TestCmdSetScriptValue.js"></script>
117116
<script src="editor/TestCmdSetUuid.js"></script>
118117
<script src="editor/TestCmdSetValue.js"></script>

0 commit comments

Comments
 (0)