Skip to content

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
GarboMuffin committed Aug 7, 2023
1 parent 7115abb commit c32c666
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions test/integration/tw_xml_block.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
const htmlparser = require('htmlparser2');
const {test} = require('tap');
const VirtualMachine = require('../../src/virtual-machine');
const BlockType = require('../../src/extension-support/block-type');

test('XML blocks', t => {
const vm = new VirtualMachine();
vm.extensionManager._registerInternalExtension({
getInfo: () => ({
id: 'testxml',
name: 'XML Test',
blocks: [
{
blockType: BlockType.XML,
xml: '<test it="works">!</test>'
}
]
})
});

const xmlList = vm.runtime.getBlocksXML();
t.equal(xmlList.length, 1);

const parsedXML = htmlparser.parseDOM(xmlList[0].xml);
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, 'test');
t.equal(label.attribs.it, 'works');
t.equal(label.children.length, 1);
t.equal(label.children[0].data, '!');

t.end();
});

0 comments on commit c32c666

Please sign in to comment.