Skip to content

Commit 2af65b8

Browse files
authored
test(Mover): Add test for moving statement blocks (#704)
* refactor(tests): Rename move test blocks to move start test blocks Also remove an unnecessary round trip through JSON.stringify + JSON.parse. * test(Mover): Introduce test blocks and suite for statement move tests Introduce moveStatementTestBlocks and suite 'Statement move tests', for testing movement of statement blocks. Move the existing test for constrained movement following unconstrained movement to the new suite. * test(Mover): Test constrained move of simple stack block left/right * refactor(tests): Refactor simple stack block move left/right Introduce a new helper function, testMove, that encapsulates the work needed to test moving a block through a constrained move, checking candidate connections and final position. Use this helper to reimplement the move left/right test as two separate tests. * test(Mover): Test constrained move of simple stack block up/down * docs(tests): Improve documentation of getFocusedNeighbourInfo * test(Mover): Also check index of candidateConnection.local Modify getConnectionCandidate to also return the index of candidateConnection.local in the list of connections returned from block.getConnections_(true), so we can check wich connection on the moving block is being used to connect. For the simple mover case this is not very interesting (it's normally index 0, for the previous connection, occasionally index 1 if the moving block will be the new top block in a stack) but this will be more important for tests involving moving more complexly-shaped blocks. * chore(tests): Add block with statment inputs to statement test blocks Add a new, E-shaped block with ID complex_mover to moveStatementTestBlocks, and update expected test results for statement move tests. * test(Mover): Test constrained move of stack block with statement inputs Note that this test verifies current behaviour which, due to bug #702, does not conform to the desired behaviour. There are TODOs to update tests to desired behaviour when bug is fixed. * docs(tests): Correct copied comment
1 parent 7df913d commit 2af65b8

File tree

4 files changed

+373
-21
lines changed

4 files changed

+373
-21
lines changed

test/index.html

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,12 @@
108108
<option value="navigationTestBlocks">
109109
navigation test blocks
110110
</option>
111-
<option value="moveTestBlocks">move test blocks</option>
111+
<option value="moveStartTestBlocks">
112+
move start test blocks
113+
</option>
114+
<option value="moveStatementTestBlocks">
115+
move statement test blocks
116+
</option>
112117
<option value="comments">comments</option>
113118
</select>
114119
</div>

test/loadTestBlocks.js

Lines changed: 126 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -570,7 +570,15 @@ const navigationTestBlocks = {
570570
},
571571
};
572572

573-
const moveTestBlocks = {
573+
// The draw block contains a stack of statement blocks, each of which
574+
// has a value input to which is connected a value expression block
575+
// which itself has one or two inputs which have (non-shadow) simple
576+
// value blocks connected. Each statement block will be selected in
577+
// turn and then a move initiated (and then aborted). This is then
578+
// repeated with the first level value blocks (those that are attached
579+
// to the statement blocks). The second level value blocks are
580+
// present to verify correct (lack of) heal behaviour.
581+
const moveStartTestBlocks = {
574582
'blocks': {
575583
'languageVersion': 0,
576584
'blocks': [
@@ -862,6 +870,112 @@ const moveTestBlocks = {
862870
},
863871
};
864872

873+
// A bunch of statement blocks. The blocks with IDs simple_mover and
874+
// complex_mover will be (constrained-)moved up, down, left and right
875+
// to verify that they visit all the expected candidate connections.
876+
const moveStatementTestBlocks = {
877+
'blocks': {
878+
'languageVersion': 0,
879+
'blocks': [
880+
{
881+
'type': 'p5_setup',
882+
'id': 'p5_setup',
883+
'x': 75,
884+
'y': 75,
885+
'deletable': false,
886+
'inputs': {
887+
'STATEMENTS': {
888+
'block': {
889+
'type': 'p5_canvas',
890+
'id': 'p5_canvas',
891+
'deletable': false,
892+
'movable': false,
893+
'fields': {
894+
'WIDTH': 400,
895+
'HEIGHT': 400,
896+
},
897+
'next': {
898+
'block': {
899+
'type': 'draw_emoji',
900+
'id': 'simple_mover',
901+
'fields': {
902+
'emoji': '✨'
903+
},
904+
'next': {
905+
'block': {
906+
'type': 'controls_if',
907+
'id': 'complex_mover',
908+
'extraState': {
909+
'hasElse': true,
910+
},
911+
},
912+
},
913+
},
914+
},
915+
},
916+
},
917+
},
918+
},
919+
{
920+
'type': 'text_print',
921+
'id': 'text_print',
922+
"disabledReasons": [
923+
"MANUALLY_DISABLED"
924+
],
925+
'x': 75,
926+
'y': 400,
927+
'inputs': {
928+
'TEXT': {
929+
'shadow': {
930+
'type': 'text',
931+
'id': 'shadow_text',
932+
'fields': {
933+
'TEXT': 'abc',
934+
},
935+
},
936+
},
937+
},
938+
'next': {
939+
'block': {
940+
'type': 'controls_if',
941+
'id': 'controls_if',
942+
'extraState': {
943+
'elseIfCount': 1,
944+
'hasElse': true,
945+
},
946+
'inputs': {
947+
'DO0': {
948+
'block': {
949+
'type': 'controls_repeat_ext',
950+
'id': 'controls_repeat_ext',
951+
'inputs': {
952+
'TIMES': {
953+
'shadow': {
954+
'type': 'math_number',
955+
'id': 'shadow_math_number',
956+
'fields': {
957+
'NUM': 10,
958+
},
959+
},
960+
},
961+
},
962+
},
963+
},
964+
},
965+
},
966+
},
967+
},
968+
{
969+
'type': 'p5_draw',
970+
'id': 'p5_draw',
971+
'x': 75,
972+
'y': 950,
973+
'deletable': false,
974+
},
975+
],
976+
},
977+
};
978+
865979
const comments = {
866980
'workspaceComments': [
867981
{
@@ -985,17 +1099,20 @@ const comments = {
9851099
export const load = function (workspace, scenarioString) {
9861100
const scenarioMap = {
9871101
'blank': blankCanvas,
988-
'comments': comments,
989-
'moreBlocks': moreBlocks,
990-
'moveTestBlocks': moveTestBlocks,
991-
'navigationTestBlocks': navigationTestBlocks,
992-
'simpleCircle': simpleCircle,
1102+
comments,
1103+
moreBlocks,
1104+
moveStartTestBlocks,
1105+
moveStatementTestBlocks,
1106+
navigationTestBlocks,
1107+
simpleCircle,
9931108
'sun': sunnyDay,
9941109
};
995-
996-
const data = JSON.stringify(scenarioMap[scenarioString]);
9971110
// Don't emit events during loading.
9981111
Blockly.Events.disable();
999-
Blockly.serialization.workspaces.load(JSON.parse(data), workspace, false);
1112+
Blockly.serialization.workspaces.load(
1113+
scenarioMap[scenarioString],
1114+
workspace,
1115+
false,
1116+
);
10001117
Blockly.Events.enable();
10011118
};

0 commit comments

Comments
 (0)