mirror of
https://github.com/google/blockly.git
synced 2026-01-13 11:57:10 +01:00
* chore: fix 918 violations of comma-dangle rule * chore: fix 2 violations of comma-spacing * chore: fix 13 violations of padded-blocks * chore: fix 50 violations of block-spacing * chore: fix one violation of semi-spacing * chore: fix 4 violations of space-before-blocks * chore: fix 38 violations of object-curly-spacing * chore: fix 30 violations of key-spacing * chore: fix 3 violations of quote-props * chore: fix 5 violations of arrow-parens * chore: fix 8 violations of no-tabs * chore: allow uncommented helper functions in mocha tests * chore: fix several more lint errors * chore: tweak eslint configuration in core and tests * chore: rebuild for tests
235 lines
5.9 KiB
JavaScript
235 lines
5.9 KiB
JavaScript
/**
|
|
* @license
|
|
* Copyright 2020 Google LLC
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
*/
|
|
|
|
goog.module('Blockly.test.tooltip');
|
|
|
|
const {sharedTestSetup, sharedTestTeardown, workspaceTeardown} = goog.require('Blockly.test.helpers');
|
|
|
|
|
|
suite('Tooltip', function() {
|
|
setup(function() {
|
|
sharedTestSetup.call(this);
|
|
this.workspace = new Blockly.Workspace();
|
|
});
|
|
|
|
teardown(function() {
|
|
sharedTestTeardown.call(this);
|
|
});
|
|
|
|
suite('set/getTooltip', function() {
|
|
setup(function() {
|
|
Blockly.defineBlocksWithJsonArray([
|
|
{
|
|
"type": "test_block",
|
|
"message0": "%1",
|
|
"args0": [
|
|
{
|
|
"type": "field_input",
|
|
"name": "FIELD",
|
|
},
|
|
],
|
|
},
|
|
]);
|
|
});
|
|
|
|
teardown(function() {
|
|
delete Blockly.Blocks["test_block"];
|
|
});
|
|
|
|
const tooltipText = 'testTooltip';
|
|
|
|
function assertTooltip(obj) {
|
|
chai.assert.equal(obj.getTooltip(), tooltipText);
|
|
}
|
|
|
|
function setStringTooltip(obj) {
|
|
obj.setTooltip(tooltipText);
|
|
}
|
|
|
|
function setFunctionTooltip(obj) {
|
|
obj.setTooltip(() => tooltipText);
|
|
}
|
|
|
|
function setNestedFunctionTooltip(obj) {
|
|
function nestFunction(fn, count) {
|
|
if (!count) {
|
|
return fn;
|
|
}
|
|
return () => nestFunction(fn, --count);
|
|
}
|
|
obj.setTooltip(nestFunction(() => tooltipText, 5));
|
|
}
|
|
|
|
function setFunctionReturningObjectTooltip(obj) {
|
|
obj.setTooltip(() => {
|
|
return {
|
|
tooltip: tooltipText,
|
|
};
|
|
});
|
|
}
|
|
|
|
function setObjectTooltip(obj) {
|
|
obj.setTooltip({tooltip: tooltipText});
|
|
}
|
|
|
|
suite('Headless Blocks', function() {
|
|
setup(function() {
|
|
this.block = this.workspace.newBlock('test_block');
|
|
});
|
|
|
|
test('String', function() {
|
|
setStringTooltip(this.block);
|
|
assertTooltip(this.block);
|
|
});
|
|
|
|
test('Function', function() {
|
|
setFunctionTooltip(this.block);
|
|
assertTooltip(this.block);
|
|
});
|
|
|
|
test('Nested Function', function() {
|
|
setNestedFunctionTooltip(this.block);
|
|
assertTooltip(this.block);
|
|
});
|
|
|
|
test('Function returning object', function() {
|
|
setFunctionReturningObjectTooltip(this.block);
|
|
chai.assert.throws(this.block.getTooltip.bind(this.block),
|
|
'Tooltip function must return a string.');
|
|
});
|
|
|
|
test('Object', function() {
|
|
setObjectTooltip(this.block);
|
|
assertTooltip(this.block);
|
|
});
|
|
});
|
|
|
|
suite('Rendered Blocks', function() {
|
|
setup(function() {
|
|
this.renderedWorkspace = Blockly.inject('blocklyDiv');
|
|
this.block = this.renderedWorkspace.newBlock('test_block');
|
|
this.block.initSvg();
|
|
this.block.render();
|
|
});
|
|
|
|
teardown(function() {
|
|
workspaceTeardown.call(this, this.renderedWorkspace);
|
|
});
|
|
|
|
test('String', function() {
|
|
setStringTooltip(this.block);
|
|
assertTooltip(this.block);
|
|
});
|
|
|
|
test('Function', function() {
|
|
setFunctionTooltip(this.block);
|
|
assertTooltip(this.block);
|
|
});
|
|
|
|
test('Nested Function', function() {
|
|
setNestedFunctionTooltip(this.block);
|
|
assertTooltip(this.block);
|
|
});
|
|
|
|
test('Function returning object', function() {
|
|
setFunctionReturningObjectTooltip(this.block);
|
|
chai.assert.throws(this.block.getTooltip.bind(this.block),
|
|
'Tooltip function must return a string.');
|
|
});
|
|
|
|
test('Object', function() {
|
|
setObjectTooltip(this.block);
|
|
assertTooltip(this.block);
|
|
});
|
|
});
|
|
|
|
suite('Headless Fields', function() {
|
|
setup(function() {
|
|
this.block = this.workspace.newBlock('test_block');
|
|
this.field = this.block.getField('FIELD');
|
|
});
|
|
|
|
test('String', function() {
|
|
setStringTooltip(this.field);
|
|
assertTooltip(this.field);
|
|
});
|
|
|
|
test('Function', function() {
|
|
setFunctionTooltip(this.field);
|
|
assertTooltip(this.field);
|
|
});
|
|
|
|
test('Nested Function', function() {
|
|
setNestedFunctionTooltip(this.field);
|
|
assertTooltip(this.field);
|
|
});
|
|
|
|
test('Function returning object', function() {
|
|
setFunctionReturningObjectTooltip(this.field);
|
|
chai.assert.throws(this.field.getTooltip.bind(this.field),
|
|
'Tooltip function must return a string.');
|
|
});
|
|
|
|
test('Object', function() {
|
|
setObjectTooltip(this.field);
|
|
assertTooltip(this.field);
|
|
});
|
|
|
|
test('Null', function() {
|
|
setStringTooltip(this.block);
|
|
this.field.setTooltip(null);
|
|
assertTooltip(this.field);
|
|
});
|
|
});
|
|
|
|
suite('Rendered Fields', function() {
|
|
setup(function() {
|
|
this.renderedWorkspace = Blockly.inject('blocklyDiv');
|
|
this.block = this.renderedWorkspace.newBlock('test_block');
|
|
this.block.initSvg();
|
|
this.block.render();
|
|
this.field = this.block.getField('FIELD');
|
|
});
|
|
|
|
teardown(function() {
|
|
workspaceTeardown.call(this, this.renderedWorkspace);
|
|
});
|
|
|
|
test('String', function() {
|
|
setStringTooltip(this.field);
|
|
assertTooltip(this.field);
|
|
});
|
|
|
|
test('Function', function() {
|
|
setFunctionTooltip(this.field);
|
|
assertTooltip(this.field);
|
|
});
|
|
|
|
test('Nested Function', function() {
|
|
setNestedFunctionTooltip(this.field);
|
|
assertTooltip(this.field);
|
|
});
|
|
|
|
test('Function returning object', function() {
|
|
setFunctionReturningObjectTooltip(this.field);
|
|
chai.assert.throws(this.field.getTooltip.bind(this.field),
|
|
'Tooltip function must return a string.');
|
|
});
|
|
|
|
test('Object', function() {
|
|
setObjectTooltip(this.field);
|
|
assertTooltip(this.field);
|
|
});
|
|
|
|
test('Null', function() {
|
|
setStringTooltip(this.block);
|
|
this.field.setTooltip(null);
|
|
assertTooltip(this.field);
|
|
});
|
|
});
|
|
});
|
|
});
|