mirror of
https://github.com/google/blockly.git
synced 2026-01-08 09:30:06 +01:00
chore: use prettier instead of clang-format (#7014)
* chore: add and configure prettier * chore: remove clang-format * chore: remove clang-format config * chore: lint additional ts files * chore: fix lint errors in blocks * chore: add prettier-ignore where needed * chore: ignore js blocks when formatting * chore: fix playground html syntax * chore: fix yaml spacing from merge * chore: convert text blocks to use arrow functions * chore: format everything with prettier * chore: fix lint unused imports in blocks
This commit is contained in:
committed by
GitHub
parent
af991f5e1b
commit
88ff901a72
@@ -6,22 +6,27 @@
|
||||
|
||||
goog.declareModuleId('Blockly.test.input');
|
||||
|
||||
import {sharedTestSetup, sharedTestTeardown} from './test_helpers/setup_teardown.js';
|
||||
import {
|
||||
sharedTestSetup,
|
||||
sharedTestTeardown,
|
||||
} from './test_helpers/setup_teardown.js';
|
||||
|
||||
|
||||
suite('Inputs', function() {
|
||||
setup(function() {
|
||||
suite('Inputs', function () {
|
||||
setup(function () {
|
||||
sharedTestSetup.call(this);
|
||||
Blockly.defineBlocksWithJsonArray([{
|
||||
"type": "empty_block",
|
||||
"message0": "",
|
||||
"args0": [],
|
||||
}]);
|
||||
Blockly.defineBlocksWithJsonArray([
|
||||
{
|
||||
'type': 'empty_block',
|
||||
'message0': '',
|
||||
'args0': [],
|
||||
},
|
||||
]);
|
||||
|
||||
this.workspace = Blockly.inject('blocklyDiv');
|
||||
this.block = Blockly.Xml.domToBlock(Blockly.utils.xml.textToDom(
|
||||
'<block type="empty_block"/>'
|
||||
), this.workspace);
|
||||
this.block = Blockly.Xml.domToBlock(
|
||||
Blockly.utils.xml.textToDom('<block type="empty_block"/>'),
|
||||
this.workspace
|
||||
);
|
||||
|
||||
this.renderStub = sinon.stub(this.block, 'queueRender');
|
||||
this.bumpNeighboursStub = sinon.stub(this.block, 'bumpNeighbours');
|
||||
@@ -33,36 +38,36 @@ suite('Inputs', function() {
|
||||
this.renderStub.resetHistory();
|
||||
this.bumpNeighboursStub.resetHistory();
|
||||
});
|
||||
teardown(function() {
|
||||
teardown(function () {
|
||||
sharedTestTeardown.call(this);
|
||||
});
|
||||
suite('Insert Field At', function() {
|
||||
suite('Index Bounds', function() {
|
||||
test('< 0', function() {
|
||||
suite('Insert Field At', function () {
|
||||
suite('Index Bounds', function () {
|
||||
test('< 0', function () {
|
||||
const field = new Blockly.FieldLabel('field');
|
||||
chai.assert.throws(function() {
|
||||
chai.assert.throws(function () {
|
||||
this.dummy.insertFieldAt(-1, field);
|
||||
});
|
||||
});
|
||||
test('> length', function() {
|
||||
test('> length', function () {
|
||||
const field = new Blockly.FieldLabel('field');
|
||||
chai.assert.throws(function() {
|
||||
chai.assert.throws(function () {
|
||||
this.dummy.insertFieldAt(1, field);
|
||||
});
|
||||
});
|
||||
});
|
||||
suite('Values', function() {
|
||||
suite('Values', function () {
|
||||
// We're mostly just testing that it doesn't throw errors.
|
||||
test('Field', function() {
|
||||
test('Field', function () {
|
||||
const field = new Blockly.FieldLabel('field');
|
||||
this.dummy.insertFieldAt(0, field);
|
||||
chai.assert.equal(this.dummy.fieldRow[0], field);
|
||||
});
|
||||
test('String', function() {
|
||||
test('String', function () {
|
||||
this.dummy.insertFieldAt(0, 'field');
|
||||
chai.assert.instanceOf(this.dummy.fieldRow[0], Blockly.FieldLabel);
|
||||
});
|
||||
test('String w/ field_label overwritten', function() {
|
||||
test('String w/ field_label overwritten', function () {
|
||||
Blockly.fieldRegistry.unregister('field_label');
|
||||
Blockly.fieldRegistry.register('field_label', Blockly.FieldNumber);
|
||||
|
||||
@@ -72,25 +77,25 @@ suite('Inputs', function() {
|
||||
Blockly.fieldRegistry.unregister('field_label');
|
||||
Blockly.fieldRegistry.register('field_label', Blockly.FieldLabel);
|
||||
});
|
||||
test('Empty String', function() {
|
||||
test('Empty String', function () {
|
||||
this.dummy.insertFieldAt(0, '');
|
||||
chai.assert.isEmpty(this.dummy.fieldRow);
|
||||
});
|
||||
test('Empty String W/ Name', function() {
|
||||
test('Empty String W/ Name', function () {
|
||||
this.dummy.insertFieldAt(0, '', 'NAME');
|
||||
chai.assert.instanceOf(this.dummy.fieldRow[0], Blockly.FieldLabel);
|
||||
});
|
||||
test('Null', function() {
|
||||
test('Null', function () {
|
||||
this.dummy.insertFieldAt(0, null);
|
||||
chai.assert.isEmpty(this.dummy.fieldRow);
|
||||
});
|
||||
test('Undefined', function() {
|
||||
test('Undefined', function () {
|
||||
this.dummy.insertFieldAt(0, undefined);
|
||||
chai.assert.isEmpty(this.dummy.fieldRow);
|
||||
});
|
||||
});
|
||||
suite('Prefixes and Suffixes', function() {
|
||||
test('Prefix', function() {
|
||||
suite('Prefixes and Suffixes', function () {
|
||||
test('Prefix', function () {
|
||||
const field = new Blockly.FieldLabel('field');
|
||||
const prefix = new Blockly.FieldLabel('prefix');
|
||||
field.prefixField = prefix;
|
||||
@@ -98,7 +103,7 @@ suite('Inputs', function() {
|
||||
this.dummy.appendField(field);
|
||||
chai.assert.deepEqual(this.dummy.fieldRow, [prefix, field]);
|
||||
});
|
||||
test('Suffix', function() {
|
||||
test('Suffix', function () {
|
||||
const field = new Blockly.FieldLabel('field');
|
||||
const suffix = new Blockly.FieldLabel('suffix');
|
||||
field.suffixField = suffix;
|
||||
@@ -106,7 +111,7 @@ suite('Inputs', function() {
|
||||
this.dummy.appendField(field);
|
||||
chai.assert.deepEqual(this.dummy.fieldRow, [field, suffix]);
|
||||
});
|
||||
test('Prefix and Suffix', function() {
|
||||
test('Prefix and Suffix', function () {
|
||||
const field = new Blockly.FieldLabel('field');
|
||||
const prefix = new Blockly.FieldLabel('prefix');
|
||||
const suffix = new Blockly.FieldLabel('suffix');
|
||||
@@ -116,42 +121,36 @@ suite('Inputs', function() {
|
||||
this.dummy.appendField(field);
|
||||
chai.assert.deepEqual(this.dummy.fieldRow, [prefix, field, suffix]);
|
||||
});
|
||||
test('Dropdown - Prefix', function() {
|
||||
const field = new Blockly.FieldDropdown(
|
||||
[
|
||||
['prefix option1', 'OPTION1'],
|
||||
['prefix option2', 'OPTION2'],
|
||||
]
|
||||
);
|
||||
test('Dropdown - Prefix', function () {
|
||||
const field = new Blockly.FieldDropdown([
|
||||
['prefix option1', 'OPTION1'],
|
||||
['prefix option2', 'OPTION2'],
|
||||
]);
|
||||
|
||||
this.dummy.appendField(field);
|
||||
chai.assert.equal(this.dummy.fieldRow.length, 2);
|
||||
});
|
||||
test('Dropdown - Suffix', function() {
|
||||
const field = new Blockly.FieldDropdown(
|
||||
[
|
||||
['option1 suffix', 'OPTION1'],
|
||||
['option2 suffix', 'OPTION2'],
|
||||
]
|
||||
);
|
||||
test('Dropdown - Suffix', function () {
|
||||
const field = new Blockly.FieldDropdown([
|
||||
['option1 suffix', 'OPTION1'],
|
||||
['option2 suffix', 'OPTION2'],
|
||||
]);
|
||||
|
||||
this.dummy.appendField(field);
|
||||
chai.assert.equal(this.dummy.fieldRow.length, 2);
|
||||
});
|
||||
test('Dropdown - Prefix and Suffix', function() {
|
||||
const field = new Blockly.FieldDropdown(
|
||||
[
|
||||
['prefix option1 suffix', 'OPTION1'],
|
||||
['prefix option2 suffix', 'OPTION2'],
|
||||
]
|
||||
);
|
||||
test('Dropdown - Prefix and Suffix', function () {
|
||||
const field = new Blockly.FieldDropdown([
|
||||
['prefix option1 suffix', 'OPTION1'],
|
||||
['prefix option2 suffix', 'OPTION2'],
|
||||
]);
|
||||
|
||||
this.dummy.appendField(field);
|
||||
chai.assert.equal(this.dummy.fieldRow.length, 3);
|
||||
});
|
||||
});
|
||||
suite('Field Initialization', function() {
|
||||
test('Rendered', function() {
|
||||
suite('Field Initialization', function () {
|
||||
test('Rendered', function () {
|
||||
const field = new Blockly.FieldLabel('field');
|
||||
const setBlockSpy = sinon.spy(field, 'setSourceBlock');
|
||||
const initSpy = sinon.spy(field, 'init');
|
||||
@@ -168,7 +167,7 @@ suite('Inputs', function() {
|
||||
});
|
||||
// TODO: InsertFieldAt does not properly handle initialization in
|
||||
// headless mode.
|
||||
test.skip('Headless', function() {
|
||||
test.skip('Headless', function () {
|
||||
const field = new Blockly.FieldLabel('field');
|
||||
const setBlockSpy = sinon.spy(field, 'setSourceBlock');
|
||||
const initModelSpy = sinon.spy(field, 'initModel');
|
||||
@@ -187,13 +186,13 @@ suite('Inputs', function() {
|
||||
});
|
||||
});
|
||||
});
|
||||
suite('Remove Field', function() {
|
||||
test('Field Not Found', function() {
|
||||
chai.assert.throws(function() {
|
||||
suite('Remove Field', function () {
|
||||
test('Field Not Found', function () {
|
||||
chai.assert.throws(function () {
|
||||
this.dummy.removeField('FIELD');
|
||||
});
|
||||
});
|
||||
test('Rendered', function() {
|
||||
test('Rendered', function () {
|
||||
const field = new Blockly.FieldLabel('field');
|
||||
const disposeSpy = sinon.spy(field, 'dispose');
|
||||
this.dummy.appendField(field, 'FIELD');
|
||||
@@ -206,7 +205,7 @@ suite('Inputs', function() {
|
||||
sinon.assert.calledOnce(this.renderStub);
|
||||
sinon.assert.calledOnce(this.bumpNeighboursStub);
|
||||
});
|
||||
test('Headless', function() {
|
||||
test('Headless', function () {
|
||||
const field = new Blockly.FieldLabel('field');
|
||||
const disposeSpy = sinon.spy(field, 'dispose');
|
||||
this.dummy.appendField(field, 'FIELD');
|
||||
@@ -222,41 +221,41 @@ suite('Inputs', function() {
|
||||
sinon.assert.notCalled(this.bumpNeighboursStub);
|
||||
});
|
||||
});
|
||||
suite('Field Ordering/Manipulation', function() {
|
||||
setup(function() {
|
||||
suite('Field Ordering/Manipulation', function () {
|
||||
setup(function () {
|
||||
this.a = new Blockly.FieldLabel('a');
|
||||
this.b = new Blockly.FieldLabel('b');
|
||||
this.c = new Blockly.FieldLabel('c');
|
||||
});
|
||||
test('Append A, B, C', function() {
|
||||
test('Append A, B, C', function () {
|
||||
this.dummy.appendField(this.a, 'A');
|
||||
this.dummy.appendField(this.b, 'B');
|
||||
this.dummy.appendField(this.c, 'C');
|
||||
|
||||
chai.assert.deepEqual(this.dummy.fieldRow, [this.a, this.b, this.c]);
|
||||
});
|
||||
test('Append B, C; Insert A at Start', function() {
|
||||
test('Append B, C; Insert A at Start', function () {
|
||||
this.dummy.appendField(this.b, 'B');
|
||||
this.dummy.appendField(this.c, 'C');
|
||||
this.dummy.insertFieldAt(0, this.a, 'A');
|
||||
|
||||
chai.assert.deepEqual(this.dummy.fieldRow, [this.a, this.b, this.c]);
|
||||
});
|
||||
test('Append A, C; Insert B Between', function() {
|
||||
test('Append A, C; Insert B Between', function () {
|
||||
this.dummy.appendField(this.a, 'A');
|
||||
this.dummy.appendField(this.c, 'C');
|
||||
this.dummy.insertFieldAt(1, this.b, 'B');
|
||||
|
||||
chai.assert.deepEqual(this.dummy.fieldRow, [this.a, this.b, this.c]);
|
||||
});
|
||||
test('Append A, B; Insert C at End', function() {
|
||||
test('Append A, B; Insert C at End', function () {
|
||||
this.dummy.appendField(this.a, 'A');
|
||||
this.dummy.appendField(this.b, 'B');
|
||||
this.dummy.insertFieldAt(2, this.c, 'C');
|
||||
|
||||
chai.assert.deepEqual(this.dummy.fieldRow, [this.a, this.b, this.c]);
|
||||
});
|
||||
test('Append A, B, C; Remove A, B, C', function() {
|
||||
test('Append A, B, C; Remove A, B, C', function () {
|
||||
this.dummy.appendField(this.a, 'A');
|
||||
this.dummy.appendField(this.b, 'B');
|
||||
this.dummy.appendField(this.c, 'C');
|
||||
@@ -267,7 +266,7 @@ suite('Inputs', function() {
|
||||
|
||||
chai.assert.isEmpty(this.dummy.fieldRow);
|
||||
});
|
||||
test('Append A, B, C; Remove A', function() {
|
||||
test('Append A, B, C; Remove A', function () {
|
||||
this.dummy.appendField(this.a, 'A');
|
||||
this.dummy.appendField(this.b, 'B');
|
||||
this.dummy.appendField(this.c, 'C');
|
||||
@@ -276,7 +275,7 @@ suite('Inputs', function() {
|
||||
|
||||
chai.assert.deepEqual(this.dummy.fieldRow, [this.b, this.c]);
|
||||
});
|
||||
test('Append A, B, C; Remove B', function() {
|
||||
test('Append A, B, C; Remove B', function () {
|
||||
this.dummy.appendField(this.a, 'A');
|
||||
this.dummy.appendField(this.b, 'B');
|
||||
this.dummy.appendField(this.c, 'C');
|
||||
@@ -285,7 +284,7 @@ suite('Inputs', function() {
|
||||
|
||||
chai.assert.deepEqual(this.dummy.fieldRow, [this.a, this.c]);
|
||||
});
|
||||
test('Append A, B, C; Remove C', function() {
|
||||
test('Append A, B, C; Remove C', function () {
|
||||
this.dummy.appendField(this.a, 'A');
|
||||
this.dummy.appendField(this.b, 'B');
|
||||
this.dummy.appendField(this.c, 'C');
|
||||
@@ -294,7 +293,7 @@ suite('Inputs', function() {
|
||||
|
||||
chai.assert.deepEqual(this.dummy.fieldRow, [this.a, this.b]);
|
||||
});
|
||||
test('Append A, B; Remove A; Append C', function() {
|
||||
test('Append A, B; Remove A; Append C', function () {
|
||||
this.dummy.appendField(this.a, 'A');
|
||||
this.dummy.appendField(this.b, 'B');
|
||||
this.dummy.removeField('A');
|
||||
|
||||
Reference in New Issue
Block a user