Initial commit of 001code-html Scratch frontend project.
Includes scratch-gui, scratch-vm, scratch-blocks, scratch-render, scratch-l10n, and deployment config. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
41
scratch-vm/test/integration/tw_label_block.js
Normal file
41
scratch-vm/test/integration/tw_label_block.js
Normal file
@@ -0,0 +1,41 @@
|
||||
const htmlparser = require('htmlparser2');
|
||||
const {test} = require('tap');
|
||||
const VirtualMachine = require('../../src/virtual-machine');
|
||||
const BlockType = require('../../src/extension-support/block-type');
|
||||
|
||||
test('Label blocks', t => {
|
||||
const vm = new VirtualMachine();
|
||||
vm.extensionManager._registerInternalExtension({
|
||||
getInfo: () => ({
|
||||
id: 'testlabel',
|
||||
name: `Label Test`,
|
||||
blocks: [
|
||||
{
|
||||
blockType: BlockType.LABEL,
|
||||
text: 'test <>&"\''
|
||||
}
|
||||
]
|
||||
})
|
||||
});
|
||||
|
||||
const xmlList = vm.runtime.getBlocksXML();
|
||||
t.equal(xmlList.length, 1);
|
||||
|
||||
const parsedXML = htmlparser.parseDOM(xmlList[0].xml);
|
||||
// Expecting something like this:
|
||||
// <category name="Label Test" id="testlabel" colour="#0FBD8C" secondaryColour="#0DA57A">
|
||||
// <label text="<>&"'"></label>
|
||||
// </category>
|
||||
t.equal(parsedXML.length, 1);
|
||||
|
||||
const category = parsedXML[0];
|
||||
t.equal(category.name, 'category');
|
||||
t.equal(category.children.length, 1);
|
||||
|
||||
const label = category.children[0];
|
||||
t.equal(label.name, 'label');
|
||||
t.equal(label.children.length, 0);
|
||||
t.equal(label.attribs.text, 'test <>&"'');
|
||||
|
||||
t.end();
|
||||
});
|
||||
Reference in New Issue
Block a user