mirror of
https://github.com/google/blockly.git
synced 2026-01-07 09:00:11 +01:00
chore: apply prefer-const rule fixes in mocha tests (#5682)
This commit is contained in:
@@ -10,24 +10,24 @@ const {addBlockTypeToCleanup, assertVariableValues, createGenUidStubWithReturns,
|
||||
|
||||
|
||||
suite('XML', function() {
|
||||
let assertSimpleFieldDom = function(fieldDom, name, text) {
|
||||
const assertSimpleFieldDom = function(fieldDom, name, text) {
|
||||
chai.assert.equal(text, fieldDom.textContent);
|
||||
chai.assert.equal(name, fieldDom.getAttribute('name'));
|
||||
};
|
||||
let assertNonSerializingFieldDom = function(fieldDom) {
|
||||
const assertNonSerializingFieldDom = function(fieldDom) {
|
||||
chai.assert.isUndefined(fieldDom.childNodes[0]);
|
||||
};
|
||||
let assertNonVariableField = function(fieldDom, name, text) {
|
||||
const assertNonVariableField = function(fieldDom, name, text) {
|
||||
assertSimpleFieldDom(fieldDom, name, text);
|
||||
chai.assert.isNull(fieldDom.getAttribute('id'), 'id');
|
||||
chai.assert.isNull(fieldDom.getAttribute('variabletype'), 'variabletype');
|
||||
};
|
||||
let assertVariableDomField = function(fieldDom, name, type, id, text) {
|
||||
const assertVariableDomField = function(fieldDom, name, type, id, text) {
|
||||
assertSimpleFieldDom(fieldDom, name, text);
|
||||
chai.assert.equal(fieldDom.getAttribute('variabletype'), type);
|
||||
chai.assert.equal(fieldDom.getAttribute('id'), id);
|
||||
};
|
||||
let assertVariableDom = function(fieldDom, type, id, text) {
|
||||
const assertVariableDom = function(fieldDom, type, id, text) {
|
||||
chai.assert.equal(fieldDom.getAttribute('type'), type);
|
||||
chai.assert.equal(fieldDom.getAttribute('id'), id);
|
||||
chai.assert.equal(fieldDom.textContent, text);
|
||||
@@ -74,7 +74,7 @@ suite('XML', function() {
|
||||
});
|
||||
suite('textToDom', function() {
|
||||
test('Basic', function() {
|
||||
let dom = Blockly.Xml.textToDom(this.complexXmlText);
|
||||
const dom = Blockly.Xml.textToDom(this.complexXmlText);
|
||||
chai.assert.equal(dom.nodeName, 'xml', 'XML tag');
|
||||
chai.assert.equal(dom.getElementsByTagName('block').length, 6, 'Block tags');
|
||||
});
|
||||
@@ -99,9 +99,9 @@ suite('XML', function() {
|
||||
}
|
||||
],
|
||||
}]);
|
||||
let block = new Blockly.Block(this.workspace,
|
||||
const block = new Blockly.Block(this.workspace,
|
||||
'field_angle_test_block');
|
||||
let resultFieldDom = Blockly.Xml.blockToDom(block).childNodes[0];
|
||||
const resultFieldDom = Blockly.Xml.blockToDom(block).childNodes[0];
|
||||
assertNonVariableField(resultFieldDom, 'ANGLE', '90');
|
||||
});
|
||||
test('Checkbox', function() {
|
||||
@@ -116,9 +116,9 @@ suite('XML', function() {
|
||||
}
|
||||
],
|
||||
}]);
|
||||
let block = new Blockly.Block(this.workspace,
|
||||
const block = new Blockly.Block(this.workspace,
|
||||
'field_checkbox_test_block');
|
||||
let resultFieldDom = Blockly.Xml.blockToDom(block).childNodes[0];
|
||||
const resultFieldDom = Blockly.Xml.blockToDom(block).childNodes[0];
|
||||
assertNonVariableField(resultFieldDom, 'CHECKBOX', 'TRUE');
|
||||
});
|
||||
test('Colour', function() {
|
||||
@@ -133,9 +133,9 @@ suite('XML', function() {
|
||||
}
|
||||
],
|
||||
}]);
|
||||
let block = new Blockly.Block(this.workspace,
|
||||
const block = new Blockly.Block(this.workspace,
|
||||
'field_colour_test_block');
|
||||
let resultFieldDom = Blockly.Xml.blockToDom(block).childNodes[0];
|
||||
const resultFieldDom = Blockly.Xml.blockToDom(block).childNodes[0];
|
||||
assertNonVariableField(resultFieldDom, 'COLOUR', '#000099');
|
||||
});
|
||||
test('Dropdown', function() {
|
||||
@@ -163,9 +163,9 @@ suite('XML', function() {
|
||||
}
|
||||
],
|
||||
}]);
|
||||
let block = new Blockly.Block(this.workspace,
|
||||
const block = new Blockly.Block(this.workspace,
|
||||
'field_dropdown_test_block');
|
||||
let resultFieldDom = Blockly.Xml.blockToDom(block).childNodes[0];
|
||||
const resultFieldDom = Blockly.Xml.blockToDom(block).childNodes[0];
|
||||
assertNonVariableField(resultFieldDom, 'DROPDOWN', 'A');
|
||||
});
|
||||
test('Image', function() {
|
||||
@@ -183,9 +183,9 @@ suite('XML', function() {
|
||||
}
|
||||
],
|
||||
}]);
|
||||
let block = new Blockly.Block(this.workspace,
|
||||
const block = new Blockly.Block(this.workspace,
|
||||
'field_image_test_block');
|
||||
let resultFieldDom = Blockly.Xml.blockToDom(block);
|
||||
const resultFieldDom = Blockly.Xml.blockToDom(block);
|
||||
assertNonSerializingFieldDom(resultFieldDom);
|
||||
});
|
||||
test('Label', function() {
|
||||
@@ -200,9 +200,9 @@ suite('XML', function() {
|
||||
}
|
||||
],
|
||||
}]);
|
||||
let block = new Blockly.Block(this.workspace,
|
||||
const block = new Blockly.Block(this.workspace,
|
||||
'field_label_test_block');
|
||||
let resultFieldDom = Blockly.Xml.blockToDom(block);
|
||||
const resultFieldDom = Blockly.Xml.blockToDom(block);
|
||||
assertNonSerializingFieldDom(resultFieldDom);
|
||||
});
|
||||
test('Label Serializable', function() {
|
||||
@@ -217,9 +217,9 @@ suite('XML', function() {
|
||||
}
|
||||
],
|
||||
}]);
|
||||
let block = new Blockly.Block(this.workspace,
|
||||
const block = new Blockly.Block(this.workspace,
|
||||
'field_label_serializable_test_block');
|
||||
let resultFieldDom = Blockly.Xml.blockToDom(block).childNodes[0];
|
||||
const resultFieldDom = Blockly.Xml.blockToDom(block).childNodes[0];
|
||||
assertNonVariableField(resultFieldDom, 'LABEL', 'default');
|
||||
});
|
||||
test('Number', function() {
|
||||
@@ -234,9 +234,9 @@ suite('XML', function() {
|
||||
}
|
||||
],
|
||||
}]);
|
||||
let block = new Blockly.Block(this.workspace,
|
||||
const block = new Blockly.Block(this.workspace,
|
||||
'field_number_test_block');
|
||||
let resultFieldDom = Blockly.Xml.blockToDom(block).childNodes[0];
|
||||
const resultFieldDom = Blockly.Xml.blockToDom(block).childNodes[0];
|
||||
assertNonVariableField(resultFieldDom, 'NUMBER', '97');
|
||||
});
|
||||
test('Text Input', function() {
|
||||
@@ -251,9 +251,9 @@ suite('XML', function() {
|
||||
}
|
||||
],
|
||||
}]);
|
||||
let block = new Blockly.Block(this.workspace,
|
||||
const block = new Blockly.Block(this.workspace,
|
||||
'field_text_input_test_block');
|
||||
let resultFieldDom = Blockly.Xml.blockToDom(block).childNodes[0];
|
||||
const resultFieldDom = Blockly.Xml.blockToDom(block).childNodes[0];
|
||||
assertNonVariableField(resultFieldDom, 'TEXT', 'default');
|
||||
});
|
||||
suite('Variable Fields', function() {
|
||||
@@ -272,18 +272,18 @@ suite('XML', function() {
|
||||
});
|
||||
test('Variable Trivial', function() {
|
||||
this.workspace.createVariable('name1', '', 'id1');
|
||||
let block = new Blockly.Block(this.workspace,
|
||||
const block = new Blockly.Block(this.workspace,
|
||||
'field_variable_test_block');
|
||||
block.inputList[0].fieldRow[0].setValue('id1');
|
||||
let resultFieldDom = Blockly.Xml.blockToDom(block).childNodes[0];
|
||||
const resultFieldDom = Blockly.Xml.blockToDom(block).childNodes[0];
|
||||
assertVariableDomField(resultFieldDom, 'VAR', null, 'id1', 'name1');
|
||||
});
|
||||
test('Variable Typed', function() {
|
||||
this.workspace.createVariable('name1', 'string', 'id1');
|
||||
let block = new Blockly.Block(this.workspace,
|
||||
const block = new Blockly.Block(this.workspace,
|
||||
'field_variable_test_block');
|
||||
block.inputList[0].fieldRow[0].setValue('id1');
|
||||
let resultFieldDom = Blockly.Xml.blockToDom(block).childNodes[0];
|
||||
const resultFieldDom = Blockly.Xml.blockToDom(block).childNodes[0];
|
||||
assertVariableDomField(resultFieldDom, 'VAR', 'string', 'id1', 'name1');
|
||||
});
|
||||
test('Variable Default Case', function() {
|
||||
@@ -291,12 +291,12 @@ suite('XML', function() {
|
||||
this.workspace.createVariable('name1');
|
||||
|
||||
Blockly.Events.disable();
|
||||
let block = new Blockly.Block(this.workspace,
|
||||
const block = new Blockly.Block(this.workspace,
|
||||
'field_variable_test_block');
|
||||
block.inputList[0].fieldRow[0].setValue('1');
|
||||
Blockly.Events.enable();
|
||||
|
||||
let resultFieldDom = Blockly.Xml.blockToDom(block).childNodes[0];
|
||||
const resultFieldDom = Blockly.Xml.blockToDom(block).childNodes[0];
|
||||
// Expect type is null and ID is '1' since we don't specify type and ID.
|
||||
assertVariableDomField(resultFieldDom, 'VAR', null, '1', 'name1');
|
||||
});
|
||||
@@ -311,18 +311,18 @@ suite('XML', function() {
|
||||
});
|
||||
test('Text', function() {
|
||||
this.block.setCommentText('test text');
|
||||
let xml = Blockly.Xml.blockToDom(this.block);
|
||||
let commentXml = xml.firstChild;
|
||||
const xml = Blockly.Xml.blockToDom(this.block);
|
||||
const commentXml = xml.firstChild;
|
||||
chai.assert.equal(commentXml.tagName, 'comment');
|
||||
chai.assert.equal(commentXml.innerHTML, 'test text');
|
||||
});
|
||||
test('No Text', function() {
|
||||
let xml = Blockly.Xml.blockToDom(this.block);
|
||||
const xml = Blockly.Xml.blockToDom(this.block);
|
||||
chai.assert.isNull(xml.firstChild);
|
||||
});
|
||||
test('Empty Text', function() {
|
||||
this.block.setCommentText('');
|
||||
let xml = Blockly.Xml.blockToDom(this.block);
|
||||
const xml = Blockly.Xml.blockToDom(this.block);
|
||||
chai.assert.isNull(xml.firstChild);
|
||||
});
|
||||
});
|
||||
@@ -339,25 +339,25 @@ suite('XML', function() {
|
||||
});
|
||||
test('Text', function() {
|
||||
this.block.setCommentText('test text');
|
||||
let xml = Blockly.Xml.blockToDom(this.block);
|
||||
let commentXml = xml.firstChild;
|
||||
const xml = Blockly.Xml.blockToDom(this.block);
|
||||
const commentXml = xml.firstChild;
|
||||
chai.assert.equal(commentXml.tagName, 'comment');
|
||||
chai.assert.equal(commentXml.innerHTML, 'test text');
|
||||
});
|
||||
test('No Text', function() {
|
||||
let xml = Blockly.Xml.blockToDom(this.block);
|
||||
const xml = Blockly.Xml.blockToDom(this.block);
|
||||
chai.assert.isNull(xml.firstChild);
|
||||
});
|
||||
test('Empty Text', function() {
|
||||
this.block.setCommentText('');
|
||||
let xml = Blockly.Xml.blockToDom(this.block);
|
||||
const xml = Blockly.Xml.blockToDom(this.block);
|
||||
chai.assert.isNull(xml.firstChild);
|
||||
});
|
||||
test('Size', function() {
|
||||
this.block.setCommentText('test text');
|
||||
this.block.getCommentIcon().setBubbleSize(100, 200);
|
||||
let xml = Blockly.Xml.blockToDom(this.block);
|
||||
let commentXml = xml.firstChild;
|
||||
const xml = Blockly.Xml.blockToDom(this.block);
|
||||
const commentXml = xml.firstChild;
|
||||
chai.assert.equal(commentXml.tagName, 'comment');
|
||||
chai.assert.equal(commentXml.getAttribute('w'), 100);
|
||||
chai.assert.equal(commentXml.getAttribute('h'), 200);
|
||||
@@ -365,15 +365,15 @@ suite('XML', function() {
|
||||
test('Pinned True', function() {
|
||||
this.block.setCommentText('test text');
|
||||
this.block.getCommentIcon().setVisible(true);
|
||||
let xml = Blockly.Xml.blockToDom(this.block);
|
||||
let commentXml = xml.firstChild;
|
||||
const xml = Blockly.Xml.blockToDom(this.block);
|
||||
const commentXml = xml.firstChild;
|
||||
chai.assert.equal(commentXml.tagName, 'comment');
|
||||
chai.assert.equal(commentXml.getAttribute('pinned'), 'true');
|
||||
});
|
||||
test('Pinned False', function() {
|
||||
this.block.setCommentText('test text');
|
||||
let xml = Blockly.Xml.blockToDom(this.block);
|
||||
let commentXml = xml.firstChild;
|
||||
const xml = Blockly.Xml.blockToDom(this.block);
|
||||
const commentXml = xml.firstChild;
|
||||
chai.assert.equal(commentXml.tagName, 'comment');
|
||||
chai.assert.equal(commentXml.getAttribute('pinned'), 'false');
|
||||
});
|
||||
@@ -401,10 +401,10 @@ suite('XML', function() {
|
||||
test('One Variable', function() {
|
||||
createGenUidStubWithReturns('1');
|
||||
this.workspace.createVariable('name1');
|
||||
let resultDom =
|
||||
const resultDom =
|
||||
Blockly.Xml.variablesToDom(this.workspace.getAllVariables());
|
||||
chai.assert.equal(resultDom.children.length, 1);
|
||||
let resultVariableDom = resultDom.children[0];
|
||||
const resultVariableDom = resultDom.children[0];
|
||||
chai.assert.equal(resultVariableDom.textContent, 'name1');
|
||||
chai.assert.isNull(resultVariableDom.getAttribute('type'));
|
||||
chai.assert.equal(resultVariableDom.getAttribute('id'), '1');
|
||||
@@ -415,11 +415,11 @@ suite('XML', function() {
|
||||
// If events are enabled during block construction, it will create a
|
||||
// default variable.
|
||||
Blockly.Events.disable();
|
||||
let block = new Blockly.Block(this.workspace, 'field_variable_test_block');
|
||||
const block = new Blockly.Block(this.workspace, 'field_variable_test_block');
|
||||
block.inputList[0].fieldRow[0].setValue('id1');
|
||||
Blockly.Events.enable();
|
||||
|
||||
let resultDom = Blockly.Xml.variablesToDom(this.workspace.getAllVariables());
|
||||
const resultDom = Blockly.Xml.variablesToDom(this.workspace.getAllVariables());
|
||||
chai.assert.equal(resultDom.children.length, 2);
|
||||
assertVariableDom(resultDom.children[0], null, 'id1',
|
||||
'name1');
|
||||
@@ -427,23 +427,23 @@ suite('XML', function() {
|
||||
'name2');
|
||||
});
|
||||
test('No variables', function() {
|
||||
let resultDom =
|
||||
const resultDom =
|
||||
Blockly.Xml.variablesToDom(this.workspace.getAllVariables());
|
||||
chai.assert.equal(resultDom.children.length, 0);
|
||||
});
|
||||
});
|
||||
suite('domToText', function() {
|
||||
test('Round tripping', function() {
|
||||
let dom = Blockly.Xml.textToDom(this.complexXmlText);
|
||||
let text = Blockly.Xml.domToText(dom);
|
||||
const dom = Blockly.Xml.textToDom(this.complexXmlText);
|
||||
const text = Blockly.Xml.domToText(dom);
|
||||
chai.assert.equal(text.replace(/\s+/g, ''),
|
||||
this.complexXmlText.replace(/\s+/g, ''), 'Round trip');
|
||||
});
|
||||
});
|
||||
suite('domToPrettyText', function() {
|
||||
test('Round tripping', function() {
|
||||
let dom = Blockly.Xml.textToDom(this.complexXmlText);
|
||||
let text = Blockly.Xml.domToPrettyText(dom);
|
||||
const dom = Blockly.Xml.textToDom(this.complexXmlText);
|
||||
const text = Blockly.Xml.domToPrettyText(dom);
|
||||
chai.assert.equal(text.replace(/\s+/g, ''),
|
||||
this.complexXmlText.replace(/\s+/g, ''), 'Round trip');
|
||||
});
|
||||
@@ -458,7 +458,7 @@ suite('XML', function() {
|
||||
suite('Dynamic Category Blocks', function() {
|
||||
test('Untyped Variables', function() {
|
||||
this.workspace.createVariable('name1', '', 'id1');
|
||||
let blocksArray =
|
||||
const blocksArray =
|
||||
Blockly.Variables.flyoutCategoryBlocks(this.workspace);
|
||||
for (let i = 0, xml; (xml = blocksArray[i]); i++) {
|
||||
Blockly.Xml.domToBlock(xml, this.workspace);
|
||||
@@ -468,7 +468,7 @@ suite('XML', function() {
|
||||
this.workspace.createVariable('name1', 'String', 'id1');
|
||||
this.workspace.createVariable('name2', 'Number', 'id2');
|
||||
this.workspace.createVariable('name3', 'Colour', 'id3');
|
||||
let blocksArray =
|
||||
const blocksArray =
|
||||
Blockly.VariablesDynamic.flyoutCategoryBlocks(this.workspace);
|
||||
for (let i = 0, xml; (xml = blocksArray[i]); i++) {
|
||||
Blockly.Xml.domToBlock(xml, this.workspace);
|
||||
@@ -478,7 +478,7 @@ suite('XML', function() {
|
||||
suite('Comments', function() {
|
||||
suite('Headless', function() {
|
||||
test('Text', function() {
|
||||
let block = Blockly.Xml.domToBlock(Blockly.Xml.textToDom(
|
||||
const block = Blockly.Xml.domToBlock(Blockly.Xml.textToDom(
|
||||
'<block type="empty_block">' +
|
||||
' <comment>test text</comment>' +
|
||||
'</block>'
|
||||
@@ -486,7 +486,7 @@ suite('XML', function() {
|
||||
chai.assert.equal(block.getCommentText(), 'test text');
|
||||
});
|
||||
test('No Text', function() {
|
||||
let block = Blockly.Xml.domToBlock(Blockly.Xml.textToDom(
|
||||
const block = Blockly.Xml.domToBlock(Blockly.Xml.textToDom(
|
||||
'<block type="empty_block">' +
|
||||
' <comment></comment>' +
|
||||
'</block>'
|
||||
@@ -494,7 +494,7 @@ suite('XML', function() {
|
||||
chai.assert.equal(block.getCommentText(), '');
|
||||
});
|
||||
test('Size', function() {
|
||||
let block = Blockly.Xml.domToBlock(Blockly.Xml.textToDom(
|
||||
const block = Blockly.Xml.domToBlock(Blockly.Xml.textToDom(
|
||||
'<block type="empty_block">' +
|
||||
' <comment w="100" h="200">test text</comment>' +
|
||||
'</block>'
|
||||
@@ -503,7 +503,7 @@ suite('XML', function() {
|
||||
{width: 100, height: 200});
|
||||
});
|
||||
test('Pinned True', function() {
|
||||
let block = Blockly.Xml.domToBlock(Blockly.Xml.textToDom(
|
||||
const block = Blockly.Xml.domToBlock(Blockly.Xml.textToDom(
|
||||
'<block type="empty_block">' +
|
||||
' <comment pinned="true">test text</comment>' +
|
||||
'</block>'
|
||||
@@ -511,7 +511,7 @@ suite('XML', function() {
|
||||
chai.assert.isTrue(block.commentModel.pinned);
|
||||
});
|
||||
test('Pinned False', function() {
|
||||
let block = Blockly.Xml.domToBlock(Blockly.Xml.textToDom(
|
||||
const block = Blockly.Xml.domToBlock(Blockly.Xml.textToDom(
|
||||
'<block type="empty_block">' +
|
||||
' <comment pinned="false">test text</comment>' +
|
||||
'</block>'
|
||||
@@ -519,7 +519,7 @@ suite('XML', function() {
|
||||
chai.assert.isFalse(block.commentModel.pinned);
|
||||
});
|
||||
test('Pinned Undefined', function() {
|
||||
let block = Blockly.Xml.domToBlock(Blockly.Xml.textToDom(
|
||||
const block = Blockly.Xml.domToBlock(Blockly.Xml.textToDom(
|
||||
'<block type="empty_block">' +
|
||||
' <comment>test text</comment>' +
|
||||
'</block>'
|
||||
@@ -536,7 +536,7 @@ suite('XML', function() {
|
||||
});
|
||||
|
||||
test('Text', function() {
|
||||
let block = Blockly.Xml.domToBlock(Blockly.Xml.textToDom(
|
||||
const block = Blockly.Xml.domToBlock(Blockly.Xml.textToDom(
|
||||
'<block type="empty_block">' +
|
||||
' <comment>test text</comment>' +
|
||||
'</block>'
|
||||
@@ -545,7 +545,7 @@ suite('XML', function() {
|
||||
chai.assert.isNotNull(block.getCommentIcon());
|
||||
});
|
||||
test('No Text', function() {
|
||||
let block = Blockly.Xml.domToBlock(Blockly.Xml.textToDom(
|
||||
const block = Blockly.Xml.domToBlock(Blockly.Xml.textToDom(
|
||||
'<block type="empty_block">' +
|
||||
' <comment></comment>' +
|
||||
'</block>'
|
||||
@@ -554,7 +554,7 @@ suite('XML', function() {
|
||||
chai.assert.isNotNull(block.getCommentIcon());
|
||||
});
|
||||
test('Size', function() {
|
||||
let block = Blockly.Xml.domToBlock(Blockly.Xml.textToDom(
|
||||
const block = Blockly.Xml.domToBlock(Blockly.Xml.textToDom(
|
||||
'<block type="empty_block">' +
|
||||
' <comment w="100" h="200">test text</comment>' +
|
||||
'</block>'
|
||||
@@ -567,7 +567,7 @@ suite('XML', function() {
|
||||
});
|
||||
suite('Pinned', function() {
|
||||
test('Pinned True', function() {
|
||||
let block = Blockly.Xml.domToBlock(Blockly.Xml.textToDom(
|
||||
const block = Blockly.Xml.domToBlock(Blockly.Xml.textToDom(
|
||||
'<block type="empty_block">' +
|
||||
' <comment pinned="true">test text</comment>' +
|
||||
'</block>'
|
||||
@@ -578,7 +578,7 @@ suite('XML', function() {
|
||||
chai.assert.isTrue(block.getCommentIcon().isVisible());
|
||||
});
|
||||
test('Pinned False', function() {
|
||||
let block = Blockly.Xml.domToBlock(Blockly.Xml.textToDom(
|
||||
const block = Blockly.Xml.domToBlock(Blockly.Xml.textToDom(
|
||||
'<block type="empty_block">' +
|
||||
' <comment pinned="false">test text</comment>' +
|
||||
'</block>'
|
||||
@@ -589,7 +589,7 @@ suite('XML', function() {
|
||||
chai.assert.isFalse(block.getCommentIcon().isVisible());
|
||||
});
|
||||
test('Pinned Undefined', function() {
|
||||
let block = Blockly.Xml.domToBlock(Blockly.Xml.textToDom(
|
||||
const block = Blockly.Xml.domToBlock(Blockly.Xml.textToDom(
|
||||
'<block type="empty_block">' +
|
||||
' <comment>test text</comment>' +
|
||||
'</block>'
|
||||
@@ -623,7 +623,7 @@ suite('XML', function() {
|
||||
});
|
||||
test('Backwards compatibility', function() {
|
||||
createGenUidStubWithReturns('1');
|
||||
let dom = Blockly.Xml.textToDom(
|
||||
const dom = Blockly.Xml.textToDom(
|
||||
'<xml xmlns="https://developers.google.com/blockly/xml">' +
|
||||
' <block type="field_variable_test_block" id="block_id">' +
|
||||
' <field name="VAR">name1</field>' +
|
||||
@@ -634,7 +634,7 @@ suite('XML', function() {
|
||||
assertVariableValues(this.workspace, 'name1', '', '1');
|
||||
});
|
||||
test('Variables at top', function() {
|
||||
let dom = Blockly.Xml.textToDom(
|
||||
const dom = Blockly.Xml.textToDom(
|
||||
'<xml xmlns="https://developers.google.com/blockly/xml">' +
|
||||
' <variables>' +
|
||||
' <variable type="type1" id="id1">name1</variable>' +
|
||||
@@ -652,7 +652,7 @@ suite('XML', function() {
|
||||
assertVariableValues(this.workspace, 'name3', '', 'id3');
|
||||
});
|
||||
test('Variables at top duplicated variables tag', function() {
|
||||
let dom = Blockly.Xml.textToDom(
|
||||
const dom = Blockly.Xml.textToDom(
|
||||
'<xml xmlns="https://developers.google.com/blockly/xml">' +
|
||||
' <variables>' +
|
||||
' </variables>' +
|
||||
@@ -664,7 +664,7 @@ suite('XML', function() {
|
||||
});
|
||||
});
|
||||
test('Variables at top missing type', function() {
|
||||
let dom = Blockly.Xml.textToDom(
|
||||
const dom = Blockly.Xml.textToDom(
|
||||
'<xml xmlns="https://developers.google.com/blockly/xml">' +
|
||||
' <variables>' +
|
||||
' <variable id="id1">name1</variable>' +
|
||||
@@ -678,7 +678,7 @@ suite('XML', function() {
|
||||
});
|
||||
});
|
||||
test('Variables at top mismatch block type', function() {
|
||||
let dom = Blockly.Xml.textToDom(
|
||||
const dom = Blockly.Xml.textToDom(
|
||||
'<xml xmlns="https://developers.google.com/blockly/xml">' +
|
||||
' <variables>' +
|
||||
' <variable type="type1" id="id1">name1</variable>' +
|
||||
@@ -708,21 +708,21 @@ suite('XML', function() {
|
||||
workspaceTeardown.call(this, this.workspace);
|
||||
});
|
||||
test('Headless', function() {
|
||||
let dom = Blockly.Xml.textToDom(
|
||||
const dom = Blockly.Xml.textToDom(
|
||||
'<xml xmlns="https://developers.google.com/blockly/xml">' +
|
||||
' <block type="test_block" inline="true" x="21" y="23">' +
|
||||
' </block>' +
|
||||
'</xml>');
|
||||
Blockly.Xml.appendDomToWorkspace(dom, this.workspace);
|
||||
chai.assert.equal(this.workspace.getAllBlocks(false).length, 1, 'Block count');
|
||||
let newBlockIds = Blockly.Xml.appendDomToWorkspace(dom, this.workspace);
|
||||
const newBlockIds = Blockly.Xml.appendDomToWorkspace(dom, this.workspace);
|
||||
chai.assert.equal(this.workspace.getAllBlocks(false).length, 2, 'Block count');
|
||||
chai.assert.equal(newBlockIds.length, 1, 'Number of new block ids');
|
||||
});
|
||||
});
|
||||
suite('workspaceToDom -> domToWorkspace -> workspaceToDom', function() {
|
||||
setup(function() {
|
||||
let options = {
|
||||
const options = {
|
||||
comments: true
|
||||
};
|
||||
this.renderedWorkspace = Blockly.inject('blocklyDiv', options);
|
||||
@@ -733,19 +733,19 @@ suite('XML', function() {
|
||||
workspaceTeardown.call(this, this.renderedWorkspace);
|
||||
workspaceTeardown.call(this, this.headlessWorkspace);
|
||||
});
|
||||
let assertRoundTrip = function(originWs, targetWs) {
|
||||
let originXml = Blockly.Xml.workspaceToDom(originWs);
|
||||
const assertRoundTrip = function(originWs, targetWs) {
|
||||
const originXml = Blockly.Xml.workspaceToDom(originWs);
|
||||
Blockly.Xml.domToWorkspace(originXml, targetWs);
|
||||
let targetXml = Blockly.Xml.workspaceToDom(targetWs);
|
||||
const targetXml = Blockly.Xml.workspaceToDom(targetWs);
|
||||
|
||||
let expectedXmlText = Blockly.Xml.domToText(originXml);
|
||||
let actualXmlText = Blockly.Xml.domToText(targetXml);
|
||||
const expectedXmlText = Blockly.Xml.domToText(originXml);
|
||||
const actualXmlText = Blockly.Xml.domToText(targetXml);
|
||||
|
||||
chai.assert.equal(actualXmlText, expectedXmlText);
|
||||
};
|
||||
suite('Rendered -> XML -> Headless -> XML', function() {
|
||||
test('Comment', function() {
|
||||
let block = Blockly.Xml.domToBlock(Blockly.Xml.textToDom(
|
||||
const block = Blockly.Xml.domToBlock(Blockly.Xml.textToDom(
|
||||
'<block type="empty_block"/>'
|
||||
), this.renderedWorkspace);
|
||||
block.setCommentText('test text');
|
||||
@@ -756,7 +756,7 @@ suite('XML', function() {
|
||||
});
|
||||
suite('Headless -> XML -> Rendered -> XML', function() {
|
||||
test('Comment', function() {
|
||||
let block = Blockly.Xml.domToBlock(Blockly.Xml.textToDom(
|
||||
const block = Blockly.Xml.domToBlock(Blockly.Xml.textToDom(
|
||||
'<block type="empty_block"/>'
|
||||
), this.headlessWorkspace);
|
||||
block.setCommentText('test text');
|
||||
@@ -771,11 +771,11 @@ suite('XML', function() {
|
||||
});
|
||||
suite('generateVariableFieldDom', function() {
|
||||
test('Case Sensitive', function() {
|
||||
let varId = 'testId';
|
||||
let type = 'testType';
|
||||
let name = 'testName';
|
||||
const varId = 'testId';
|
||||
const type = 'testType';
|
||||
const name = 'testName';
|
||||
|
||||
let mockVariableModel = {
|
||||
const mockVariableModel = {
|
||||
type: type,
|
||||
name: name,
|
||||
getId: function() {
|
||||
@@ -783,9 +783,9 @@ suite('XML', function() {
|
||||
}
|
||||
};
|
||||
|
||||
let generatedXml = Blockly.Xml.domToText(
|
||||
const generatedXml = Blockly.Xml.domToText(
|
||||
Blockly.Variables.generateVariableFieldDom(mockVariableModel));
|
||||
let expectedXml =
|
||||
const expectedXml =
|
||||
'<field xmlns="https://developers.google.com/blockly/xml"' +
|
||||
' name="VAR"' +
|
||||
' id="' + varId + '"' +
|
||||
|
||||
Reference in New Issue
Block a user