1 define(function(require) {
5 /* jshint multistr:true */
6 /* globals describe, it */
8 var chai = require('libs/chai'),
9 wlxml = require('wlxml/wlxml'),
11 $ = require('libs/jquery');
13 var getDocumentFromXML = function(xml, options) {
14 return wlxml.WLXMLDocumentFromXML(xml, options || {});
18 describe.only('Metadata API', function() {
19 it('allows to set metadata on an element node', function() {
20 var doc = getDocumentFromXML('<section></section>');
21 expect(doc.root.getMetadata()).to.deep.equal([]);
22 doc.root.addMetadataRow({key: 'key', value: 'value'});
23 expect(doc.root.getMetadata()).to.deep.equal([{key: 'key', value: 'value'}]);
26 it('reads node\'s metadata from its metadata child node', function() {
27 var doc = getDocumentFromXML('<section><metadata><dc:key>value</dc:key></metadata></section>');
28 expect(doc.root.getMetadata()).to.deep.equal([{key: 'key', value: 'value'}]);
31 it('serializes node\'s metadata to its metadata child node', function() {
32 var doc = getDocumentFromXML('<section></section>');
34 doc.root.addMetadataRow({key: 'key', value: 'value'});
36 var metadataNodes = $(doc.toXML()).children('metadata'),
37 keyNodes = metadataNodes.children();
39 expect(metadataNodes).to.have.length(1);
40 expect(keyNodes).to.have.length(1);
41 expect(keyNodes[0].tagName.toLowerCase()).to.equal('dc:key');
42 expect($(keyNodes[0]).text()).to.equal('value');
44 it('doesnt show metadata node on nodes contents', function() {
45 var doc = getDocumentFromXML('<section><metadata><dc:key>value</dc:key></metadata></section>');
46 expect(doc.root.contents()).to.have.length(0);