wlxml: metadata wip - as extension
[fnpeditor.git] / src / wlxml / extensions / metadata / metadata.test.js
1 define(function(require) {
2     
3 'use strict';
4
5 /* jshint multistr:true */
6 /* globals describe, it */
7
8 var chai = require('libs/chai'),
9     wlxml = require('wlxml/wlxml'),
10     expect = chai.expect,
11     $ = require('libs/jquery');
12
13 var getDocumentFromXML = function(xml, options) {
14     return wlxml.WLXMLDocumentFromXML(xml, options || {});
15 };
16
17
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'}]);
24     });
25
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'}]);
29     });
30
31     it('serializes node\'s metadata to its metadata child node', function() {
32         var doc = getDocumentFromXML('<section></section>');
33
34         doc.root.addMetadataRow({key: 'key', value: 'value'});
35
36         var metadataNodes = $(doc.toXML()).children('metadata'),
37             keyNodes = metadataNodes.children();
38         
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');
43     });
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);
47     });
48 });
49
50
51 });