Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions plugins/modal/test/modal_test.mocha.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')('<!DOCTYPE html><div id="blocklyDiv"></div>');
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',
Expand All @@ -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();
Expand All @@ -59,8 +59,8 @@ suite('Modal', () => {
});
});

suite('handleKeyDown()', () => {
setup(() => {
suite('handleKeyDown()', function() {
setup(function() {
this.modal.init();
this.modal.show();
});
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -58,7 +58,7 @@ suite('TypedVariableModal', () => {
return toolbox;
}

setup(() => {
setup(function() {
this.jsdomCleanup =
require('jsdom-global')('<!DOCTYPE html><div id="blocklyDiv"></div>');
const types = [['Penguin', 'PENGUIN'], ['Giraffe', 'GIRAFFE']];
Expand All @@ -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,
Expand All @@ -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',
Expand All @@ -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',
Expand All @@ -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',
Expand All @@ -146,67 +146,67 @@ 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');
assert(allBtns.length, 2);
});
});

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');
Expand Down
Loading