Skip to content

Commit d02d623

Browse files
committed
test: Add tests for stack jumping shortcuts
1 parent 37f3650 commit d02d623

File tree

1 file changed

+137
-1
lines changed

1 file changed

+137
-1
lines changed

packages/blockly/tests/mocha/shortcut_items_test.js

Lines changed: 137 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import {createKeyDownEvent} from './test_helpers/user_input.js';
1919
suite('Keyboard Shortcut Items', function () {
2020
setup(function () {
2121
sharedTestSetup.call(this);
22-
const toolbox = document.getElementById('toolbox-categories');
22+
const toolbox = document.getElementById('toolbox-test');
2323
this.workspace = Blockly.inject('blocklyDiv', {toolbox});
2424
this.injectionDiv = this.workspace.getInjectionDiv();
2525
Blockly.ContextMenuRegistry.registry.reset();
@@ -799,4 +799,140 @@ suite('Keyboard Shortcut Items', function () {
799799
);
800800
});
801801
});
802+
803+
suite('Stack navigation (N / B)', function () {
804+
const keyNextStack = () => createKeyDownEvent(Blockly.utils.KeyCodes.N);
805+
const keyPrevStack = () => createKeyDownEvent(Blockly.utils.KeyCodes.B);
806+
807+
setup(function () {
808+
this.block1 = this.workspace.newBlock('controls_if');
809+
this.block2 = this.workspace.newBlock('stack_block');
810+
this.block3 = this.workspace.newBlock('stack_block');
811+
this.block2.moveBy(0, 100);
812+
this.block3.moveBy(0, 400);
813+
814+
this.comment1 = this.workspace.newComment();
815+
this.comment2 = this.workspace.newComment();
816+
this.comment1.moveBy(0, 200);
817+
this.comment2.moveBy(0, 300);
818+
});
819+
820+
test('Block forward to block', function () {
821+
Blockly.getFocusManager().focusNode(this.block1);
822+
this.injectionDiv.dispatchEvent(keyNextStack());
823+
assert.strictEqual(
824+
Blockly.getFocusManager().getFocusedNode(),
825+
this.block2,
826+
);
827+
});
828+
829+
test('Block back to block', function () {
830+
Blockly.getFocusManager().focusNode(this.block2);
831+
this.injectionDiv.dispatchEvent(keyPrevStack());
832+
assert.strictEqual(
833+
Blockly.getFocusManager().getFocusedNode(),
834+
this.block1,
835+
);
836+
});
837+
838+
test('Block forward to workspace comment', function () {
839+
Blockly.getFocusManager().focusNode(this.block2);
840+
this.injectionDiv.dispatchEvent(keyNextStack());
841+
assert.strictEqual(
842+
Blockly.getFocusManager().getFocusedNode(),
843+
this.comment1,
844+
);
845+
});
846+
847+
test('Block back to workspace comment', function () {
848+
Blockly.getFocusManager().focusNode(this.block3);
849+
this.injectionDiv.dispatchEvent(keyPrevStack());
850+
assert.strictEqual(
851+
Blockly.getFocusManager().getFocusedNode(),
852+
this.comment2,
853+
);
854+
});
855+
856+
test('Workspace comment forward to workspace comment', function () {
857+
Blockly.getFocusManager().focusNode(this.comment1);
858+
this.injectionDiv.dispatchEvent(keyNextStack());
859+
assert.strictEqual(
860+
Blockly.getFocusManager().getFocusedNode(),
861+
this.comment2,
862+
);
863+
});
864+
865+
test('Workspace comment back to workspace comment', function () {
866+
Blockly.getFocusManager().focusNode(this.comment2);
867+
this.injectionDiv.dispatchEvent(keyPrevStack());
868+
assert.strictEqual(
869+
Blockly.getFocusManager().getFocusedNode(),
870+
this.comment1,
871+
);
872+
});
873+
874+
test('Workspace comment forward to block', function () {
875+
Blockly.getFocusManager().focusNode(this.comment2);
876+
this.injectionDiv.dispatchEvent(keyNextStack());
877+
assert.strictEqual(
878+
Blockly.getFocusManager().getFocusedNode(),
879+
this.block3,
880+
);
881+
});
882+
883+
test('Workspace comment back to block', function () {
884+
Blockly.getFocusManager().focusNode(this.comment1);
885+
this.injectionDiv.dispatchEvent(keyPrevStack());
886+
assert.strictEqual(
887+
Blockly.getFocusManager().getFocusedNode(),
888+
this.block2,
889+
);
890+
});
891+
892+
test('Block forward to block in mutator workspace', async function () {
893+
const icon = this.block1.getIcon(Blockly.icons.MutatorIcon.TYPE);
894+
await icon.setBubbleVisible(true);
895+
this.clock.runAll();
896+
const mutatorWorkspace = icon.getWorkspace();
897+
const stack1 = mutatorWorkspace.newBlock('controls_if_elseif');
898+
const stack2 = mutatorWorkspace.newBlock('controls_if_elseif');
899+
stack1.initSvg();
900+
stack2.initSvg();
901+
stack1.render();
902+
stack2.render();
903+
stack1.moveBy(0, 100);
904+
stack2.moveBy(0, 200);
905+
Blockly.getFocusManager().focusNode(stack1);
906+
this.injectionDiv.dispatchEvent(keyNextStack());
907+
assert.strictEqual(Blockly.getFocusManager().getFocusedNode(), stack2);
908+
});
909+
910+
test('Block back to block in mutator workspace', async function () {
911+
const icon = this.block1.getIcon(Blockly.icons.MutatorIcon.TYPE);
912+
await icon.setBubbleVisible(true);
913+
this.clock.runAll();
914+
const mutatorWorkspace = icon.getWorkspace();
915+
const stack1 = mutatorWorkspace.newBlock('controls_if_elseif');
916+
const stack2 = mutatorWorkspace.newBlock('controls_if_elseif');
917+
stack1.initSvg();
918+
stack2.initSvg();
919+
stack1.render();
920+
stack2.render();
921+
stack1.moveBy(0, 100);
922+
stack2.moveBy(0, 200);
923+
Blockly.getFocusManager().focusNode(stack2);
924+
this.injectionDiv.dispatchEvent(keyPrevStack());
925+
assert.strictEqual(Blockly.getFocusManager().getFocusedNode(), stack1);
926+
});
927+
928+
test('Next stack from nested element', async function () {
929+
const icon = this.block1.getIcon(Blockly.icons.MutatorIcon.TYPE);
930+
Blockly.getFocusManager().focusNode(icon);
931+
this.injectionDiv.dispatchEvent(keyNextStack());
932+
assert.strictEqual(
933+
Blockly.getFocusManager().getFocusedNode(),
934+
this.block2,
935+
);
936+
});
937+
});
802938
});

0 commit comments

Comments
 (0)