mirror of
https://github.com/google/blockly.git
synced 2026-01-10 02:17:09 +01:00
Changed sendDeleteEvent to append <xml> tags. Fixed bad <next> tests.
This commit is contained in:
@@ -31,7 +31,7 @@ suite("Trashcan", function() {
|
||||
}
|
||||
};
|
||||
function sendDeleteEvent(xmlString) {
|
||||
var xml = Blockly.Xml.textToDom(xmlString);
|
||||
var xml = Blockly.Xml.textToDom('<xml>' + xmlString + '</xml>');
|
||||
xml = xml.children[0];
|
||||
var event = {
|
||||
type: Blockly.Events.BLOCK_DELETE,
|
||||
@@ -51,11 +51,7 @@ suite("Trashcan", function() {
|
||||
|
||||
suite("Events", function() {
|
||||
test("Delete", function() {
|
||||
sendDeleteEvent(
|
||||
'<xml>' +
|
||||
' <block type="dummy_type"/>' +
|
||||
'</xml>'
|
||||
);
|
||||
sendDeleteEvent('<block type="dummy_type"/>');
|
||||
chai.assert.equal(this.trashcan.contents_.length, 1);
|
||||
});
|
||||
test("Non-Delete", function() {
|
||||
@@ -80,270 +76,170 @@ suite("Trashcan", function() {
|
||||
chai.assert.equal(this.trashcan.contents_.length, 0);
|
||||
});
|
||||
test("Shadow Delete", function() {
|
||||
sendDeleteEvent(
|
||||
'<xml>' +
|
||||
' <shadow type="dummy_type"/>' +
|
||||
'</xml>'
|
||||
);
|
||||
sendDeleteEvent('<shadow type="dummy_type"/>');
|
||||
chai.assert.equal(this.trashcan.contents_.length, 0);
|
||||
});
|
||||
});
|
||||
suite("Unique Contents", function() {
|
||||
test("Simple", function() {
|
||||
sendDeleteEvent(
|
||||
'<xml>' +
|
||||
' <block type="dummy_type"/>' +
|
||||
'</xml>'
|
||||
);
|
||||
sendDeleteEvent(
|
||||
'<xml>' +
|
||||
' <block type="dummy_type"/>' +
|
||||
'</xml>'
|
||||
);
|
||||
sendDeleteEvent('<block type="dummy_type"/>');
|
||||
sendDeleteEvent('<block type="dummy_type"/>');
|
||||
chai.assert.equal(this.trashcan.contents_.length, 1);
|
||||
});
|
||||
test("Different Coords", function() {
|
||||
sendDeleteEvent(
|
||||
'<xml>' +
|
||||
' <block type="dummy_type" x="10" y="10"/>' +
|
||||
'</xml>'
|
||||
);
|
||||
sendDeleteEvent(
|
||||
'<xml>' +
|
||||
' <block type="dummy_type" x="20" y="20"/>' +
|
||||
'</xml>'
|
||||
);
|
||||
sendDeleteEvent('<block type="dummy_type" x="10" y="10"/>');
|
||||
sendDeleteEvent('<block type="dummy_type" x="20" y="20"/>');
|
||||
chai.assert.equal(this.trashcan.contents_.length, 1);
|
||||
});
|
||||
test("Different IDs", function() {
|
||||
sendDeleteEvent(
|
||||
'<xml>' +
|
||||
' <block type="dummy_type" id="id1"/>' +
|
||||
'</xml>'
|
||||
);
|
||||
sendDeleteEvent(
|
||||
'<xml>' +
|
||||
' <block type="dummy_type" id="id2"/>' +
|
||||
'</xml>'
|
||||
);
|
||||
sendDeleteEvent('<block type="dummy_type" id="id1"/>');
|
||||
sendDeleteEvent('<block type="dummy_type" id="id2"/>');
|
||||
chai.assert.equal(this.trashcan.contents_.length, 1);
|
||||
});
|
||||
test("No Disabled - Disabled True", function() {
|
||||
sendDeleteEvent(
|
||||
'<xml>' +
|
||||
' <block type="dummy_type"/>' +
|
||||
'</xml>'
|
||||
);
|
||||
sendDeleteEvent(
|
||||
'<xml>' +
|
||||
' <block type="dummy_type" disabled="true"/>' +
|
||||
'</xml>'
|
||||
);
|
||||
sendDeleteEvent('<block type="dummy_type"/>');
|
||||
sendDeleteEvent('<block type="dummy_type" disabled="true"/>');
|
||||
chai.assert.equal(this.trashcan.contents_.length, 2);
|
||||
});
|
||||
test("No Editable - Editable False", function() {
|
||||
sendDeleteEvent(
|
||||
'<xml>' +
|
||||
' <block type="dummy_type"/>' +
|
||||
'</xml>'
|
||||
);
|
||||
sendDeleteEvent(
|
||||
'<xml>' +
|
||||
' <block type="dummy_type" editable="false"/>' +
|
||||
'</xml>'
|
||||
);
|
||||
sendDeleteEvent('<block type="dummy_type"/>');
|
||||
sendDeleteEvent('<block type="dummy_type" editable="false"/>');
|
||||
chai.assert.equal(this.trashcan.contents_.length, 2);
|
||||
});
|
||||
test("No Movable - Movable False", function() {
|
||||
sendDeleteEvent(
|
||||
'<xml>' +
|
||||
' <block type="dummy_type"/>' +
|
||||
'</xml>'
|
||||
);
|
||||
sendDeleteEvent(
|
||||
'<xml>' +
|
||||
' <block type="dummy_type" movable="false"/>' +
|
||||
'</xml>'
|
||||
);
|
||||
sendDeleteEvent('<block type="dummy_type"/>');
|
||||
sendDeleteEvent('<block type="dummy_type" movable="false"/>');
|
||||
chai.assert.equal(this.trashcan.contents_.length, 2);
|
||||
});
|
||||
test("Different Field Values", function() {
|
||||
sendDeleteEvent(
|
||||
'<xml>' +
|
||||
' <block type="dummy_type">' +
|
||||
' <field name="dummy_name">dummy_value1</field>' +
|
||||
' </block>' +
|
||||
'</xml>'
|
||||
'<block type="dummy_type">' +
|
||||
' <field name="dummy_name">dummy_value1</field>' +
|
||||
'</block>'
|
||||
);
|
||||
sendDeleteEvent(
|
||||
'<xml>' +
|
||||
' <block type="dummy_type">' +
|
||||
' <field name="dummy_name">dummy_value2</field>' +
|
||||
' </block>' +
|
||||
'</xml>'
|
||||
'<block type="dummy_type">' +
|
||||
' <field name="dummy_name">dummy_value2</field>' +
|
||||
'</block>'
|
||||
);
|
||||
chai.assert.equal(this.trashcan.contents_.length, 2);
|
||||
});
|
||||
test("No Values - Values", function() {
|
||||
sendDeleteEvent('<block type="dummy_type"/>');
|
||||
sendDeleteEvent(
|
||||
'<xml>' +
|
||||
' <block type="dummy_type"/>' +
|
||||
'</xml>'
|
||||
);
|
||||
sendDeleteEvent(
|
||||
'<xml>' +
|
||||
' <block type="dummy_type">' +
|
||||
' <value name="dummy_input">' +
|
||||
' <block type="dummy_type"/>' +
|
||||
' </value>' +
|
||||
' </block>' +
|
||||
'</xml>'
|
||||
'<block type="dummy_type">' +
|
||||
' <value name="dummy_input">' +
|
||||
' <block type="dummy_type"/>' +
|
||||
' </value>' +
|
||||
'</block>'
|
||||
);
|
||||
chai.assert.equal(this.trashcan.contents_.length, 2);
|
||||
});
|
||||
test("Different Value Blocks", function() {
|
||||
sendDeleteEvent(
|
||||
'<xml>' +
|
||||
' <block type="dummy_type">' +
|
||||
' <value name="dummy_input">' +
|
||||
' <block type="dummy_type1"/>' +
|
||||
' </value>' +
|
||||
' </block>' +
|
||||
'</xml>'
|
||||
'<block type="dummy_type">' +
|
||||
' <value name="dummy_input">' +
|
||||
' <block type="dummy_type1"/>' +
|
||||
' </value>' +
|
||||
'</block>'
|
||||
);
|
||||
sendDeleteEvent(
|
||||
'<xml>' +
|
||||
' <block type="dummy_type">' +
|
||||
' <value name="dummy_input">' +
|
||||
' <block type="dummy_type2"/>' +
|
||||
' </value>' +
|
||||
' </block>' +
|
||||
'</xml>'
|
||||
'<block type="dummy_type">' +
|
||||
' <value name="dummy_input">' +
|
||||
' <block type="dummy_type2"/>' +
|
||||
' </value>' +
|
||||
'</block>'
|
||||
);
|
||||
chai.assert.equal(this.trashcan.contents_.length, 2);
|
||||
});
|
||||
test("No Statements - Statements", function() {
|
||||
sendDeleteEvent('<block type="dummy_type"/>');
|
||||
sendDeleteEvent(
|
||||
'<xml>' +
|
||||
' <block type="dummy_type"/>' +
|
||||
'</xml>'
|
||||
);
|
||||
sendDeleteEvent(
|
||||
'<xml>' +
|
||||
' <block type="dummy_type">' +
|
||||
' <statement name="dummy_input">' +
|
||||
' <block type="dummy_type"/>' +
|
||||
' </statement>' +
|
||||
' </block>' +
|
||||
'</xml>'
|
||||
'<block type="dummy_type">' +
|
||||
' <statement name="dummy_input">' +
|
||||
' <block type="dummy_type"/>' +
|
||||
' </statement>' +
|
||||
'</block>'
|
||||
);
|
||||
chai.assert.equal(this.trashcan.contents_.length, 2);
|
||||
});
|
||||
test("Different Statement Blocks", function() {
|
||||
sendDeleteEvent(
|
||||
'<xml>' +
|
||||
' <block type="dummy_type">' +
|
||||
' <statement name="dummy_input">' +
|
||||
' <block type="dummy_type1"/>' +
|
||||
' </statement>' +
|
||||
' </block>' +
|
||||
'</xml>'
|
||||
'<block type="dummy_type">' +
|
||||
' <statement name="dummy_input">' +
|
||||
' <block type="dummy_type1"/>' +
|
||||
' </statement>' +
|
||||
'</block>'
|
||||
);
|
||||
sendDeleteEvent(
|
||||
'<xml>' +
|
||||
' <block type="dummy_type">' +
|
||||
' <statement name="dummy_input">' +
|
||||
' <block type="dummy_type2"/>' +
|
||||
' </statement>' +
|
||||
' </block>' +
|
||||
'</xml>'
|
||||
'<block type="dummy_type">' +
|
||||
' <statement name="dummy_input">' +
|
||||
' <block type="dummy_type2"/>' +
|
||||
' </statement>' +
|
||||
'</block>'
|
||||
);
|
||||
chai.assert.equal(this.trashcan.contents_.length, 2);
|
||||
});
|
||||
test("No Next - Next", function() {
|
||||
sendDeleteEvent('<block type="dummy_type"/>');
|
||||
sendDeleteEvent(
|
||||
'<xml>' +
|
||||
' <block type="dummy_type"/>' +
|
||||
'</xml>'
|
||||
);
|
||||
sendDeleteEvent(
|
||||
'<xml>' +
|
||||
' <block type="dummy_type">' +
|
||||
' <next name="dummy_input">' +
|
||||
' <block type="dummy_type"/>' +
|
||||
' </next>' +
|
||||
' </block>' +
|
||||
'</xml>'
|
||||
'<block type="dummy_type">' +
|
||||
' <next>' +
|
||||
' <block type="dummy_type"/>' +
|
||||
' </next>' +
|
||||
'</block>'
|
||||
);
|
||||
chai.assert.equal(this.trashcan.contents_.length, 2);
|
||||
});
|
||||
test("Different Next Blocks", function() {
|
||||
sendDeleteEvent(
|
||||
'<xml>' +
|
||||
' <block type="dummy_type">' +
|
||||
' <statement name="dummy_input">' +
|
||||
' <block type="dummy_type1"/>' +
|
||||
' </statement>' +
|
||||
' </block>' +
|
||||
'</xml>'
|
||||
'<block type="dummy_type">' +
|
||||
' <next>' +
|
||||
' <block type="dummy_type1"/>' +
|
||||
' </next>' +
|
||||
'</block>'
|
||||
);
|
||||
sendDeleteEvent(
|
||||
'<xml>' +
|
||||
' <block type="dummy_type">' +
|
||||
' <statement name="dummy_input">' +
|
||||
' <block type="dummy_type2"/>' +
|
||||
' </statement>' +
|
||||
' </block>' +
|
||||
'</xml>'
|
||||
'<block type="dummy_type">' +
|
||||
' <next>' +
|
||||
' <block type="dummy_type2"/>' +
|
||||
' </next>' +
|
||||
'</block>'
|
||||
);
|
||||
chai.assert.equal(this.trashcan.contents_.length, 2);
|
||||
});
|
||||
test("No Comment - Comment", function() {
|
||||
sendDeleteEvent('<block type="dummy_type"/>');
|
||||
sendDeleteEvent(
|
||||
'<xml>' +
|
||||
' <block type="dummy_type"/>' +
|
||||
'</xml>'
|
||||
);
|
||||
sendDeleteEvent(
|
||||
'<xml>' +
|
||||
' <block type="dummy_type">' +
|
||||
' <comment>comment_text</comment>' +
|
||||
' </block>' +
|
||||
'</xml>'
|
||||
'<block type="dummy_type">' +
|
||||
' <comment>comment_text</comment>' +
|
||||
'</block>'
|
||||
);
|
||||
chai.assert.equal(this.trashcan.contents_.length, 2);
|
||||
});
|
||||
test("Different Comment Text", function() {
|
||||
sendDeleteEvent(
|
||||
'<xml>' +
|
||||
' <block type="dummy_type">' +
|
||||
' <comment>comment_text1</comment>' +
|
||||
' </block>' +
|
||||
'</xml>'
|
||||
'<block type="dummy_type">' +
|
||||
' <comment>comment_text1</comment>' +
|
||||
'</block>'
|
||||
);
|
||||
sendDeleteEvent(
|
||||
'<xml>' +
|
||||
' <block type="dummy_type">' +
|
||||
' <comment>comment_text2</comment>' +
|
||||
' </block>' +
|
||||
'</xml>'
|
||||
'<block type="dummy_type">' +
|
||||
' <comment>comment_text2</comment>' +
|
||||
'</block>'
|
||||
);
|
||||
chai.assert.equal(this.trashcan.contents_.length, 2);
|
||||
});
|
||||
test("Different Comment Size", function() {
|
||||
sendDeleteEvent(
|
||||
'<xml>' +
|
||||
' <block type="dummy_type">' +
|
||||
' <comment h="10" w="10">comment_text</comment>' +
|
||||
' </block>' +
|
||||
'</xml>'
|
||||
'<block type="dummy_type">' +
|
||||
' <comment h="10" w="10">comment_text</comment>' +
|
||||
'</block>'
|
||||
);
|
||||
sendDeleteEvent(
|
||||
'<xml>' +
|
||||
' <block type="dummy_type">' +
|
||||
' <comment h="20" w="20">comment_text</comment>' +
|
||||
' </block>' +
|
||||
'</xml>'
|
||||
'<block type="dummy_type">' +
|
||||
' <comment h="20" w="20">comment_text</comment>' +
|
||||
'</block>'
|
||||
);
|
||||
// TODO: Is this how we want this to work? The difference is not
|
||||
// related to the content.
|
||||
@@ -351,52 +247,38 @@ suite("Trashcan", function() {
|
||||
});
|
||||
test("Different Comment Pinned", function() {
|
||||
sendDeleteEvent(
|
||||
'<xml>' +
|
||||
' <block type="dummy_type">' +
|
||||
' <comment pinned="false">comment_text</comment>' +
|
||||
' </block>' +
|
||||
'</xml>'
|
||||
'<block type="dummy_type">' +
|
||||
' <comment pinned="false">comment_text</comment>' +
|
||||
'</block>'
|
||||
);
|
||||
sendDeleteEvent(
|
||||
'<xml>' +
|
||||
' <block type="dummy_type">' +
|
||||
' <comment pinned="true">comment_text</comment>' +
|
||||
' </block>' +
|
||||
'</xml>'
|
||||
'<block type="dummy_type">' +
|
||||
' <comment pinned="true">comment_text</comment>' +
|
||||
'</block>'
|
||||
);
|
||||
// TODO: Is this how we want this to work? The difference is not
|
||||
// related to the content.
|
||||
chai.assert.equal(this.trashcan.contents_.length, 2);
|
||||
});
|
||||
test("No Mutator - Mutator", function() {
|
||||
sendDeleteEvent('<block type="dummy_type"/>');
|
||||
sendDeleteEvent(
|
||||
'<xml>' +
|
||||
' <block type="dummy_type"/>' +
|
||||
'</xml>'
|
||||
);
|
||||
sendDeleteEvent(
|
||||
'<xml>' +
|
||||
' <block type="dummy_type">' +
|
||||
' <mutation dummy_attribute="dummy_value"></mutation>' +
|
||||
' </block>' +
|
||||
'</xml>'
|
||||
'<block type="dummy_type">' +
|
||||
' <mutation dummy_attribute="dummy_value"></mutation>' +
|
||||
'</block>'
|
||||
);
|
||||
chai.assert.equal(this.trashcan.contents_.length, 2);
|
||||
});
|
||||
test("Different Mutator", function() {
|
||||
sendDeleteEvent(
|
||||
'<xml>' +
|
||||
' <block type="dummy_type">' +
|
||||
' <mutation dummy_attribute="dummy_value1"></mutation>' +
|
||||
' </block>' +
|
||||
'</xml>'
|
||||
'<block type="dummy_type">' +
|
||||
' <mutation dummy_attribute="dummy_value1"></mutation>' +
|
||||
'</block>'
|
||||
);
|
||||
sendDeleteEvent(
|
||||
'<xml>' +
|
||||
' <block type="dummy_type">' +
|
||||
' <mutation dummy_attribute="dummy_value2"></mutation>' +
|
||||
' </block>' +
|
||||
'</xml>'
|
||||
'<block type="dummy_type">' +
|
||||
' <mutation dummy_attribute="dummy_value2"></mutation>' +
|
||||
'</block>'
|
||||
);
|
||||
chai.assert.equal(this.trashcan.contents_.length, 2);
|
||||
});
|
||||
@@ -414,16 +296,8 @@ suite("Trashcan", function() {
|
||||
});
|
||||
test("Last In First Out", function() {
|
||||
workspace.options.maxTrashcanContents = 1;
|
||||
sendDeleteEvent(
|
||||
'<xml>' +
|
||||
' <block type="dummy_type1"/>' +
|
||||
'</xml>'
|
||||
);
|
||||
sendDeleteEvent(
|
||||
'<xml>' +
|
||||
' <block type="dummy_type2"/>' +
|
||||
'</xml>'
|
||||
);
|
||||
sendDeleteEvent('<block type="dummy_type1"/>');
|
||||
sendDeleteEvent('<block type="dummy_type2"/>');
|
||||
chai.assert.equal(this.trashcan.contents_.length, 1);
|
||||
chai.assert.equal(
|
||||
Blockly.Xml.textToDom(this.trashcan.contents_[0])
|
||||
|
||||
Reference in New Issue
Block a user