X-Git-Url: https://git.mdrn.pl/fnpeditor.git/blobdiff_plain/ed98b7046fe7f1e484bf9d58d3981054f4b06563..65c64d3696e38bda0e2259d48c8d02978da7a3d8:/src/smartxml/smartxml.test.js diff --git a/src/smartxml/smartxml.test.js b/src/smartxml/smartxml.test.js index 00c3ee9..db9777f 100644 --- a/src/smartxml/smartxml.test.js +++ b/src/smartxml/smartxml.test.js @@ -506,6 +506,32 @@ describe('smartxml', function() { expect(parents).to.eql([b,a]); }); }); + + describe('finding sibling parents of two elements', function() { + it('returns elements themself if they have direct common parent', function() { + var doc = getDocumentFromXML('
A
B
'), + wrappingDiv = doc.root.contents()[0], + divA = wrappingDiv.contents()[0], + divB = wrappingDiv.contents()[1]; + + var siblingParents = doc.getSiblingParents({node1: divA, node2: divB}); + + expect(siblingParents.node1.sameNode(divA)).to.equal(true, 'divA'); + expect(siblingParents.node2.sameNode(divB)).to.equal(true, 'divB'); + }); + + it('returns sibling parents - example 1', function() { + var doc = getDocumentFromXML('
Alice has a cat
'), + aliceText = doc.root.contents()[0], + span = doc.root.contents()[1], + spanText = span.contents()[0]; + + var siblingParents = doc.getSiblingParents({node1: aliceText, node2: spanText}); + + expect(siblingParents.node1.sameNode(aliceText)).to.equal(true, 'aliceText'); + expect(siblingParents.node2.sameNode(span)).to.equal(true, 'span'); + }); + }); }); describe('Serializing document to WLXML', function() {