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('returns empty metadata for node without metadata', function() {
 
  20         var doc = getDocumentFromXML('<section></section>');
 
  21         expect(doc.root.getMetadata().length).to.equal(0);
 
  23     it('allows to set metadata on an element node', function() {
 
  24         var doc = getDocumentFromXML('<section></section>');
 
  26         var row = doc.root.addMetadata({key: 'key', value: 'value'}),
 
  27             metadata = doc.root.getMetadata();
 
  29         expect(metadata.length).to.equal(1);
 
  30         expect(metadata[0]).to.equal(row, 'aaa');
 
  32         expect(row.getKey()).to.equal('key');
 
  33         expect(row.getValue()).to.equal('value');
 
  35     // it('allows to remove specific metadata row', function() {
 
  36     //     var doc = getDocumentFromXML('<section><metadata><dc:key>value</dc:key><dc:key>value</dc:key></metadata></section>'),
 
  37     //         metadata = doc.root.getMetadata();
 
  38     //     expect(metadata.length).to.equal(2);
 
  40     //     expect(metadata.length)
 
  41     //     expect(metadata[0].getValue()).to.equal('value');
 
  43     it('reads node\'s metadata from source of its metadata child node', function() {
 
  44         var doc = getDocumentFromXML('<section><metadata><dc:key>value</dc:key></metadata></section>'),
 
  45             metadata = doc.root.getMetadata();
 
  46         expect(metadata.length).to.equal(1);
 
  47         expect(metadata[0].getKey()).to.equal('key');
 
  48         expect(metadata[0].getValue()).to.equal('value');
 
  51     it('serializes node\'s metadata to its metadata child node', function() {
 
  52         var doc = getDocumentFromXML('<section></section>');
 
  54         doc.root.addMetadata({key: 'key', value: 'value'});
 
  56         var metadataNodes = $(doc.toXML()).children('metadata'),
 
  57             keyNodes = metadataNodes.children();
 
  59         expect(metadataNodes).to.have.length(1);
 
  60         expect(keyNodes).to.have.length(1);
 
  61         expect(keyNodes[0].tagName.toLowerCase()).to.equal('dc:key');
 
  62         expect($(keyNodes[0]).text()).to.equal('value');
 
  64     it('doesn\'t show metadata node on nodes contents', function() {
 
  65         var doc = getDocumentFromXML('<section><metadata><dc:key>value</dc:key></metadata></section>');
 
  66         expect(doc.root.contents()).to.have.length(0);