diff --git a/plugins/modal/test/modal_test.mocha.js b/plugins/modal/test/modal_test.mocha.js index d16819293d..2cc91b22cb 100644 --- a/plugins/modal/test/modal_test.mocha.js +++ b/plugins/modal/test/modal_test.mocha.js @@ -15,29 +15,29 @@ const sinon = require('sinon'); const Modal = require('../src/index.js').Modal; -suite('Modal', () => { - setup(() => { +suite('Modal', function() { + setup(function() { this.jsdomCleanup = require('jsdom-global')('
'); this.workspace = Blockly.inject('blocklyDiv', {}); this.modal = new Modal('Title', this.workspace); }); - teardown(() => { + teardown(function() { this.jsdomCleanup(); sinon.restore(); }); - suite('init()', () => { - test('Calls render', () => { + suite('init()', function() { + test('Calls render', function() { this.modal.render = sinon.fake(); this.modal.init(); sinon.assert.calledOnce(this.modal.render); }); }); - suite('show()', () => { - test('Elements focused', () => { + suite('show()', function() { + test('Elements focused', function() { this.modal.init(); this.modal.show(); assert.equal('blocklyModalBtn blocklyModalBtnClose', @@ -47,8 +47,8 @@ suite('Modal', () => { }); }); - suite('dispose()', () => { - test('Events and button callback removed', () => { + suite('dispose()', function() { + test('Events and button callback removed', function() { this.modal.init(); const numEvents = this.modal.boundEvents_.length; Blockly.unbindEvent_ = sinon.fake(); @@ -59,8 +59,8 @@ suite('Modal', () => { }); }); - suite('handleKeyDown()', () => { - setup(() => { + suite('handleKeyDown()', function() { + setup(function() { this.modal.init(); this.modal.show(); }); @@ -80,19 +80,19 @@ suite('Modal', () => { event.preventDefault = sinon.fake(); return event; } - test('Tab pressed with only one element', () => { + test('Tab pressed with only one element', function() { const event = makeEvent(Blockly.utils.KeyCodes.TAB, false); this.modal.handleForwardTab_ = sinon.fake(); this.modal.handleKeyDown_(event); sinon.assert.notCalled(this.modal.handleForwardTab_); }); - test('Shift tab pressed with only one element', () => { + test('Shift tab pressed with only one element', function() { const event = makeEvent(Blockly.utils.KeyCodes.TAB, true); this.modal.handleBackwardTab_ = sinon.fake(); this.modal.handleKeyDown_(event); sinon.assert.notCalled(this.modal.handleBackwardTab_); }); - test('Escape pressed', () => { + test('Escape pressed', function() { const event = makeEvent(Blockly.utils.KeyCodes.ESC, false); this.modal.hide = sinon.fake(); this.modal.handleKeyDown_(event); diff --git a/plugins/typed-variable-modal/test/typed_variable_modal_test.mocha.js b/plugins/typed-variable-modal/test/typed_variable_modal_test.mocha.js index 12f25dfe82..5b1b4ec956 100644 --- a/plugins/typed-variable-modal/test/typed_variable_modal_test.mocha.js +++ b/plugins/typed-variable-modal/test/typed_variable_modal_test.mocha.js @@ -15,7 +15,7 @@ const sinon = require('sinon'); const {TypedVariableModal} = require('../src/index.js'); -suite('TypedVariableModal', () => { +suite('TypedVariableModal', function() { /** * Set up the workspace to test with typed variable modal. * @param {string} toolbox The toolbox. @@ -58,7 +58,7 @@ suite('TypedVariableModal', () => { return toolbox; } - setup(() => { + setup(function() { this.jsdomCleanup = require('jsdom-global')('
'); const types = [['Penguin', 'PENGUIN'], ['Giraffe', 'GIRAFFE']]; @@ -67,21 +67,21 @@ suite('TypedVariableModal', () => { 'CREATE_TYPED_VARIABLE', types); }); - teardown(() => { + teardown(function() { this.jsdomCleanup(); sinon.restore(); }); - suite('init()', () => { - test('Registers button', () => { + suite('init()', function() { + test('Registers button', function() { this.workspace.registerButtonCallback = sinon.fake(); this.typedVarModal.init(); sinon.assert.calledOnce(this.workspace.registerButtonCallback); }); }); - suite('show()', () => { - test('Elements focused', () => { + suite('show()', function() { + test('Elements focused', function() { this.typedVarModal.init(); this.typedVarModal.show(); assert.equal(this.typedVarModal.firstFocusableEl_.className, @@ -91,8 +91,8 @@ suite('TypedVariableModal', () => { }); }); - suite('setLocale()', () => { - test('Messages added', () => { + suite('setLocale()', function() { + test('Messages added', function() { this.typedVarModal.init(); const messages = { 'TYPED_VAR_MODAL_CONFIRM_BUTTON': 'confirm_test', @@ -105,26 +105,26 @@ suite('TypedVariableModal', () => { }); }); - suite('onConfirm_()', () => { - setup(() => { + suite('onConfirm_()', function() { + setup(function() { Blockly.alert = sinon.fake(); this.typedVarModal.init(); this.typedVarModal.getSelectedType_ = sinon.fake.returns('Giraffe'); this.typedVarModal.getDisplayName_ = sinon.fake.returns('Giraffe'); }); - test('No text', () => { + test('No text', function() { this.typedVarModal.getValidInput_ = sinon.fake.returns(null); this.typedVarModal.onConfirm_(); assert(Blockly.alert .calledWith('Name is not valid. Please choose a different name.')); }); - test('Valid name', () => { + test('Valid name', function() { this.typedVarModal.getValidInput_ = sinon.fake.returns('varName'); this.workspace.createVariable = sinon.fake(); this.typedVarModal.onConfirm_(); assert(this.workspace.createVariable.calledOnce); }); - test('Variable with different type already exists', () => { + test('Variable with different type already exists', function() { Blockly.Variables.nameUsedWithAnyType = sinon.fake.returns({ 'type': 'Penguin', 'name': 'varName', @@ -134,7 +134,7 @@ suite('TypedVariableModal', () => { assert(Blockly.alert.calledWith('A variable named \'varName\' already ' + 'exists for another type: \'Giraffe\'.')); }); - test('Variable with same type already exits', () => { + test('Variable with same type already exits', function() { Blockly.Variables.nameUsedWithAnyType = sinon.fake.returns({ 'type': 'Giraffe', 'name': 'varName', @@ -146,44 +146,44 @@ suite('TypedVariableModal', () => { }); }); - suite('getDisplayName_()', () => { - test('Get display name', () => { + suite('getDisplayName_()', function() { + test('Get display name', function() { assert.equal(this.typedVarModal.getDisplayName_('GIRAFFE'), 'Giraffe'); }); - test('No display name', () => { + test('No display name', function() { assert.equal(this.typedVarModal.getDisplayName_('SOMETHING'), ''); }); }); - suite('getValidInput_()', () => { - setup(() => { + suite('getValidInput_()', function() { + setup(function() { this.typedVarModal.init(); }); - test('Using rename variable name', () => { + test('Using rename variable name', function() { this.typedVarModal.variableNameInput_.value = 'Rename variable...'; assert.equal(this.typedVarModal.getValidInput_(), null); }); - test('Using new variable name', () => { + test('Using new variable name', function() { this.typedVarModal.variableNameInput_.value = 'Create variable...'; assert.equal(this.typedVarModal.getValidInput_(), null); }); - test('Valid variable name', () => { + test('Valid variable name', function() { this.typedVarModal.variableNameInput_.value = 'varName'; assert.equal(this.typedVarModal.getValidInput_(), 'varName'); }); }); - suite('render', () => { - setup(() => { + suite('render', function() { + setup(function() { this.typedVarModal.render(); }); - test('renderContent_()', () => { + test('renderContent_()', function() { const htmlDiv = this.typedVarModal.htmlDiv_; const modalContent = htmlDiv.querySelector('.blocklyModalContent'); assert(modalContent.querySelector('.typedModalVariableNameInput')); assert(modalContent.querySelector('.typedModalTypes')); }); - test('renderFooter_()', () => { + test('renderFooter_()', function() { const htmlDiv = this.typedVarModal.htmlDiv_; const modalFooter = htmlDiv.querySelector('.blocklyModalFooter'); const allBtns = modalFooter.querySelectorAll('.blocklyModalBtn'); @@ -191,22 +191,22 @@ suite('TypedVariableModal', () => { }); }); - suite('create', () => { - test('createConfirmBtn_()', () => { + suite('create', function() { + test('createConfirmBtn_()', function() { const btn = this.typedVarModal.createConfirmBtn_(); assert.equal(btn.className, 'blocklyModalBtn blocklyModalBtnPrimary'); }); - test('createCancelBtn_()', () => { + test('createCancelBtn_()', function() { const btn = this.typedVarModal.createCancelBtn_(); assert.equal(btn.className, 'blocklyModalBtn'); }); - test('createVariableTypeContainer_()', () => { + test('createVariableTypeContainer_()', function() { const types = this.typedVarModal.types_; const typeList = this.typedVarModal.createVariableTypeContainer_(types); assert.equal(typeList.querySelectorAll('.typedModalTypes') .length, types.length); }); - test('createVarNameContainer_()', () => { + test('createVarNameContainer_()', function() { const container = this.typedVarModal.createVarNameContainer_(); const varNameInput = container .querySelector('.typedModalVariableNameInput'); diff --git a/plugins/workspace-search/test/workspace_search_test.mocha.js b/plugins/workspace-search/test/workspace_search_test.mocha.js index 17e92ebcd6..5373e3bf09 100644 --- a/plugins/workspace-search/test/workspace_search_test.mocha.js +++ b/plugins/workspace-search/test/workspace_search_test.mocha.js @@ -15,7 +15,7 @@ const sinon = require('sinon'); const {WorkspaceSearch} = require('../src/index'); -suite('WorkspaceSearch', () => { +suite('WorkspaceSearch', function() { /** * Check if a block is currently highlighted. * @param {Blockly.BlockSvg} block The block to test. @@ -58,19 +58,19 @@ suite('WorkspaceSearch', () => { } } - setup(() => { + setup(function() { this.jsdomCleanup = require('jsdom-global')('
'); this.workspace = Blockly.inject('blocklyDiv'); this.workspaceSearch = new WorkspaceSearch(this.workspace); }); - teardown(() => { + teardown(function() { this.jsdomCleanup(); }); - suite('init()', () => { - test('CSS is injected at init()', () => { + suite('init()', function() { + test('CSS is injected at init()', function() { let searchStyle = document.getElementById('blockly-ws-search-style'); assert.equal(!!searchStyle, false); @@ -80,7 +80,7 @@ suite('WorkspaceSearch', () => { }); - test('DOM is intialized at init()', () => { + test('DOM is intialized at init()', function() { let dom = document.querySelector('div.blockly-ws-search'); assert.equal(!!dom, false); this.workspaceSearch.init(); @@ -89,8 +89,8 @@ suite('WorkspaceSearch', () => { }); }); - suite('dispose()', () => { - test('DOM is disposed', () => { + suite('dispose()', function() { + test('DOM is disposed', function() { this.workspaceSearch.init(); let dom = document.querySelector('div.blockly-ws-search'); assert.equal(!!dom, true); @@ -100,7 +100,7 @@ suite('WorkspaceSearch', () => { }); }); - suite('searchAndHighlight()', () => { + suite('searchAndHighlight()', function() { /** * Assert blocks are equal to the search group of blocks. * @param {Array.} allBlocks All blocks. @@ -123,7 +123,7 @@ suite('WorkspaceSearch', () => { } } } - setup(() => { + setup(function() { Blockly.defineBlocksWithJsonArray([ { 'type': 'test_block', @@ -187,14 +187,14 @@ suite('WorkspaceSearch', () => { 'getAllBlocks').returns(Object.values(this.blocks)); }); - teardown(() => { + teardown(function() { delete Blockly.Blocks['test_block']; delete Blockly.Blocks['test_statement_block']; delete Blockly.Blocks['test_text']; sinon.restore(); }); - test('Match all blocks', () => { + test('Match all blocks', function() { this.workspaceSearch.searchAndHighlight('test', false); const expectedBlocks = [ this.testBlock, @@ -212,13 +212,13 @@ suite('WorkspaceSearch', () => { 'Expected field within a collapsed block to not be highlighted.'); }); - test('Match no blocks', () => { + test('Match no blocks', function() { this.workspaceSearch.searchAndHighlight('none', false); assertEqualsSearchGroup(this.blocks, this.workspaceSearch.blocks_, []); assertNoExtraCurrentStyling(this.blocks); }); - test('Match all non-fields', () => { + test('Match all non-fields', function() { this.workspaceSearch.searchAndHighlight('block', false); const expectedBlocks = [ this.testBlock, @@ -231,7 +231,7 @@ suite('WorkspaceSearch', () => { assertNoExtraCurrentStyling(this.blocks, expectedBlocks[0]); }); - test('Match all field and collapsed blocks', () => { + test('Match all field and collapsed blocks', function() { this.workspaceSearch.searchAndHighlight('string', false); const expectedBlocks = [ this.testStatementBlockWithInputCollapsed, @@ -243,7 +243,7 @@ suite('WorkspaceSearch', () => { assertNoExtraCurrentStyling(this.blocks, expectedBlocks[0]); }); - test('Preserve current, in results', () => { + test('Preserve current, in results', function() { this.workspaceSearch.searchAndHighlight('test'); this.workspaceSearch.setCurrentBlock_(1); // this.testStatementBlock should be current. @@ -261,7 +261,7 @@ suite('WorkspaceSearch', () => { assertNoExtraCurrentStyling(this.blocks, expectedBlocks[1]); }); - test('Preserve current, not in results', () => { + test('Preserve current, not in results', function() { this.workspaceSearch.searchAndHighlight('test'); this.workspaceSearch.setCurrentBlock_(1); // this.testStatementBlock should be current. @@ -277,20 +277,50 @@ suite('WorkspaceSearch', () => { }); }); - suite('next()', () => { - setup(() => { + suite('next()', function() { + setup(function() { + Blockly.defineBlocksWithJsonArray([ + { + 'type': 'test_block', + 'message0': 'test block', + }, + { + 'type': 'test_statement_block', + 'message0': '%test %1', + 'args0': [{ + 'type': 'input_value', + 'name': 'INPUT0', + 'check': 'String', + }], + 'message1': '%block %1', + 'args1': [{ + 'type': 'input_statement', + 'name': 'INPUT1', + }], + 'previousStatement': null, + 'nextStatement': null, + }, + ]); + this.testBlock = this.workspace.newBlock('test_block'); + this.testStatementBlock = this.workspace.newBlock('test_statement_block'); this.blocks = [this.testBlock, this.testStatementBlock]; this.workspaceSearch.blocks_ = this.blocks; }); - test('next() with unset current', () => { + teardown(function() { + delete Blockly.Blocks['test_block']; + delete Blockly.Blocks['test_statement_block']; + sinon.restore(); + }); + + test('next() with unset current', function() { this.workspaceSearch.next(); const currentIndex = this.workspaceSearch.currentBlockIndex_; assert.equal(currentIndex, 0); assertNoExtraCurrentStyling(this.blocks, this.blocks[0]); }); - test('next() wrap around', () => { + test('next() wrap around', function() { this.workspaceSearch.currentBlockIndex_ = 0; this.workspaceSearch.next(); let currentIndex = this.workspaceSearch.currentBlockIndex_; @@ -303,18 +333,48 @@ suite('WorkspaceSearch', () => { }); }); - suite('previous()', () => { - setup(() => { - this.workspaceSearch.blocks_ = - [this.testBlock, this.testStatementBlock]; + suite('previous()', function() { + setup(function() { + Blockly.defineBlocksWithJsonArray([ + { + 'type': 'test_block', + 'message0': 'test block', + }, + { + 'type': 'test_statement_block', + 'message0': '%test %1', + 'args0': [{ + 'type': 'input_value', + 'name': 'INPUT0', + 'check': 'String', + }], + 'message1': '%block %1', + 'args1': [{ + 'type': 'input_statement', + 'name': 'INPUT1', + }], + 'previousStatement': null, + 'nextStatement': null, + }, + ]); + this.testBlock = this.workspace.newBlock('test_block'); + this.testStatementBlock = this.workspace.newBlock('test_statement_block'); + this.blocks = [this.testBlock, this.testStatementBlock]; + this.workspaceSearch.blocks_ = this.blocks; + }); + + teardown(function() { + delete Blockly.Blocks['test_block']; + delete Blockly.Blocks['test_statement_block']; + sinon.restore(); }); - test('previous() with unset current', () => { + test('previous() with unset current', function() { this.workspaceSearch.previous(); // No expected current index, but should not throw. }); - test('previous() wrap around', () => { + test('previous() wrap around', function() { this.workspaceSearch.currentBlockIndex_ = 1; this.workspaceSearch.previous(); let currentIndex = this.workspaceSearch.currentBlockIndex_;