X-Git-Url: https://git.mdrn.pl/fnpeditor.git/blobdiff_plain/275952d30bfcd6f5aecc2710a0df0cd489ea71f6..33bebd4a55d538b7229e3d6cd0673e39ee28a81e:/src/wlxml/wlxml.test.js?ds=sidebyside diff --git a/src/wlxml/wlxml.test.js b/src/wlxml/wlxml.test.js index c802ae3..936093e 100644 --- a/src/wlxml/wlxml.test.js +++ b/src/wlxml/wlxml.test.js @@ -251,6 +251,43 @@ describe('WLXMLDocument', function() { }); + describe('Extension', function() { + var doc, extension, elementNode, textNode, testClassNode; + + beforeEach(function() { + doc = getDocumentFromXML('
Alice
'); + elementNode = doc.root; + textNode = doc.root.contents()[0]; + testClassNode = doc.root.contents('.test_class'); + extension = {}; + + expect(testClassNode.object).to.be.undefined; + + }); + + it('allows adding method to an ElementNode of specific class', function() { + extension = {wlxmlClass: {test_class: {methods: { + testMethod: function() { return this; } + }}}}; + doc.registerExtension(extension); + testClassNode = doc.root.contents()[1]; + expect(testClassNode.object.testMethod().sameNode(testClassNode)).to.equal(true, '1'); + }); + + it('allows adding transformation to an ElementNode of specific class', function() { + extension = {wlxmlClass: {test_class: {transformations: { + testTransformation: function() { return this; }, + testTransformation2: {impl: function() { return this; }} + }}}}; + doc.registerExtension(extension); + testClassNode = doc.root.contents()[1]; + expect(testClassNode.object.transform('testTransformation').sameNode(testClassNode)).to.equal(true, '1'); + expect(testClassNode.object.transform('testTransformation2').sameNode(testClassNode)).to.equal(true, '1'); + }); + + + }); + }); }); \ No newline at end of file