fix: changes to meta attribute were being lost
[fnpeditor.git] / modules / documentCanvas / tests / canvasNode.test.js
index a1595f7..2452fff 100644 (file)
@@ -18,17 +18,24 @@ var assertDomEqual = function(lhs, rhs) {
 
 suite('Create canvas node', function() {  
     test('from description', function() {
-        var node = canvasNode.create({tag: 'header', klass: 'some-class', content: 'some text content'});
+        var node = canvasNode.create({
+            tag: 'header',
+            klass: 'uri',
+            content: 'some text content',
+            meta: {uri: 'some uri'}
+        });
         assert.equal(node.getTag(), 'header');
-        assert.equal(node.getClass(), 'some-class');
+        assert.equal(node.getClass(), 'uri');
         assert.equal(node.getContent(), 'some text content');
-        assertDomEqual($('<div wlxml-tag="header" wlxml-class="some-class">some text content</div>'), node.dom);
+        assert.equal(node.getMetaAttr('uri'), 'some uri');
+        assertDomEqual($('<div wlxml-tag="header" wlxml-class="uri" wlxml-meta-uri="some uri">some text content</div>'), node.dom);
     });
     
     test('from dom object', function() {
-        var node = canvasNode.create($('<div wlxml-tag="header" wlxml-class="some-class" id="1">'));
+        var node = canvasNode.create($('<div wlxml-tag="header" wlxml-class="some-class" id="1" wlxml-meta-uri="some uri">'));
         assert.equal(node.getTag(), 'header');
         assert.equal(node.getClass(), 'some-class');
+        assert.equal(node.getMetaAttr('uri'), 'some uri');
         //assertDomEqual($('<div wlxml-tag="header" wlxml-class="some-class">'), node.dom);
     });
 });
@@ -58,5 +65,44 @@ suite('comparing nodes', function() {
     });
 });
 
+suite('meta attributes', function() {
+    test('get list of node\'s meta attributes', function() {
+        var node = canvasNode.create({tag: 'span', klass: 'uri', meta: {uri:'http://some.uri.com'}});
+        var attrs = node.getMetaAttrs();
+        var expected = [{name: 'uri', value: 'http://some.uri.com'}];
+
+        assert.deepEqual(attrs.sort(), expected.sort());
+    });
+
+    test('get list of node\'s meta attributes when attributes not set', function() {
+        var node = canvasNode.create({tag: 'span', klass: 'uri'});
+        var attrs = node.getMetaAttrs();
+        var expected = [{name: 'uri', value: ''}];
+        assert.deepEqual(attrs.sort(), expected.sort());
+    });
+
+    test('set meta attribute', function() {
+        var node = canvasNode.create({tag: 'tag', klass: 'uri', meta: {'uri': 'some uri'}});
+        node.setMetaAttr('uri', 'some uri 2');
+        assert.equal(node.dom.attr('wlxml-meta-uri'), 'some uri 2');
+    });
+
+    test('changing class changes meta attributes', function() {
+        var node = canvasNode.create({tag: 'span', klass: 'uri', meta: {uri: 'http://some.uri.com'}});
+        
+        assert.equal(node.getMetaAttr('uri'), 'http://some.uri.com');
+
+        node.setClass('author');
+
+        assert.equal(node.getMetaAttr('uri'), undefined);
+    });
+
+    test('changing class to another with the same attribute keeps the value', function() {
+        var node = canvasNode.create({tag: 'span', klass: 'uri', meta: {uri: 'http://some.uri.com'}});
+        assert.equal(node.getMetaAttr('uri'), 'http://some.uri.com');
+        node.setClass('uri-subclass');
+        assert.equal(node.getMetaAttr('uri'), 'http://some.uri.com');
+    });
+});
 
 });
\ No newline at end of file