4 ], function(chai, wlxml) {
8 /* global it, describe */
10 var expect = chai.expect;
12 var nodeFromXML = function(xml) {
13 return wlxml.WLXMLElementNodeFromXML(xml);
17 describe('WLXMLDocument', function() {
19 describe('Basic wlxml element node properties', function() {
20 it('returns its class', function() {
21 var node = nodeFromXML('<header class="class.subclass"></header>');
22 expect(node.getClass()).to.equal('class.subclass');
25 it('returns its attributes as dict', function() {
26 var node = nodeFromXML('<span meta-attr1="val1" meta-attr2="val2"></span>');
27 expect(node.getMetaAttributes()).to.eql([{name: 'attr1', value: 'val1'}, {name: 'attr2', value: 'val2'}]);
30 it('returns attributes other than class and meta-* as other attributes', function() {
31 var node = nodeFromXML('<span class="uri" meta-attr="val" attr1="val1" attr2="val2"></span>');
32 expect(node.getOtherAttributes()).to.eql({attr1: 'val1', attr2: 'val2'});
36 describe('White space handling', function() {
37 it('ignores white space surrounding block elements', function() {
38 var node = nodeFromXML('<section> <div></div> </section>'),
39 contents = node.contents();
40 expect(contents).to.have.length(1);
41 expect(contents[0].nodeType).to.equal(Node.ELEMENT_NODE);
43 it('ignores white space between block elements', function() {
44 var node = nodeFromXML('<section><div></div> <div></div></section>'),
45 contents = node.contents();
46 expect(contents).to.have.length(2);
47 [0,1].forEach(function(idx) {
48 expect(contents[idx].nodeType).to.equal(Node.ELEMENT_NODE);
51 it('trims white space from the beginning and the end of the block elements', function() {
52 var node = nodeFromXML('<section> Alice <span>has</span> a cat </section>');
53 expect(node.contents()[0].getText()).to.equal('Alice ');
54 expect(node.contents()[2].getText()).to.equal(' a cat');
56 it('normalizes string of white characters to one space at the inline element boundries', function() {
57 var node = nodeFromXML('<span> Alice has a cat </span>');
58 expect(node.contents()[0].getText()).to.equal(' Alice has a cat ');
60 it('normalizes string of white characters to one space before inline element', function() {
61 var node = nodeFromXML('<div>Alice has <span>a cat</span></div>');
62 expect(node.contents()[0].getText()).to.equal('Alice has ');
64 it('normalizes string of white characters to one space after inline element', function() {
65 var node = nodeFromXML('<div>Alice has <span>a</span> cat</div>');
66 expect(node.contents()[2].getText()).to.equal(' cat');