X-Git-Url: https://git.mdrn.pl/fnpeditor.git/blobdiff_plain/4a10da821d96b8e462cc9db5e74e2507445eee76..530d5b117e9513fa9282015d3eb231088275c615:/modules/documentCanvas/tests/canvasNode.test.js?ds=sidebyside diff --git a/modules/documentCanvas/tests/canvasNode.test.js b/modules/documentCanvas/tests/canvasNode.test.js index f9507d9..2452fff 100644 --- a/modules/documentCanvas/tests/canvasNode.test.js +++ b/modules/documentCanvas/tests/canvasNode.test.js @@ -1,62 +1,108 @@ -define([ -'libs/jquery-1.9.1.min', -'libs/chai', -'./utils.js', -'modules/documentCanvas/canvasNode' -], function($, chai, utils, canvasNode) { - -'use strict'; - -var assert = chai.assert; - -var assertDomEqual = function(lhs, rhs) { - lhs.attr('id', ''); - rhs.attr('id', ''); - return assert.ok(lhs[0].isEqualNode(rhs[0]), 'nodes are equal'); - -}; - -suite('Create canvas node', function() { - test('from description', function() { - var node = canvasNode.create({tag: 'header', klass: 'some-class', content: 'some text content'}); - assert.equal(node.getTag(), 'header'); - assert.equal(node.getClass(), 'some-class'); - assert.equal(node.getContent(), 'some text content'); - assertDomEqual($('
some text content
'), node.dom); - }); - - test('from dom object', function() { - var node = canvasNode.create($('
')); - assert.equal(node.getTag(), 'header'); - assert.equal(node.getClass(), 'some-class'); - //assertDomEqual($('
'), node.dom); - }); -}); - -suite('class information', function() { - test('class of', function() { - var node = canvasNode.create({tag: 'header', klass: 'a-b-c'}); - assert.ok(node.isOfClass('a'), 'first level'); - assert.ok(node.isOfClass('a-b'), 'second level'); - assert.ok(node.isOfClass('a-b-c'), 'third level'); - assert.notOk(node.isOfClass('b-c')); - - var node2 = canvasNode.create({tag: 'header'}); - assert.notOk(node2.isOfClass('b')); - - }); - -}); - -suite('comparing nodes', function() { - test('isSame', function() { - var html = '
'; - var dom1 = $(html); - var dom2 = $(html); - assert.ok(canvasNode.create(dom1).isSame(canvasNode.create(dom1))); - assert.notOk(canvasNode.create(dom1).isSame(canvasNode.create(dom2))); - }); -}); - - +define([ +'libs/jquery-1.9.1.min', +'libs/chai', +'./utils.js', +'modules/documentCanvas/canvasNode' +], function($, chai, utils, canvasNode) { + +'use strict'; + +var assert = chai.assert; + +var assertDomEqual = function(lhs, rhs) { + lhs.attr('id', ''); + rhs.attr('id', ''); + return assert.ok(lhs[0].isEqualNode(rhs[0]), 'nodes are equal'); + +}; + +suite('Create canvas node', function() { + test('from description', function() { + 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(), 'uri'); + assert.equal(node.getContent(), 'some text content'); + assert.equal(node.getMetaAttr('uri'), 'some uri'); + assertDomEqual($('
some text content
'), node.dom); + }); + + test('from dom object', function() { + var node = canvasNode.create($('
')); + assert.equal(node.getTag(), 'header'); + assert.equal(node.getClass(), 'some-class'); + assert.equal(node.getMetaAttr('uri'), 'some uri'); + //assertDomEqual($('
'), node.dom); + }); +}); + +suite('class information', function() { + test('class of', function() { + var node = canvasNode.create({tag: 'header', klass: 'a-b-c'}); + assert.ok(node.isOfClass('a'), 'first level'); + assert.ok(node.isOfClass('a-b'), 'second level'); + assert.ok(node.isOfClass('a-b-c'), 'third level'); + assert.notOk(node.isOfClass('b-c')); + + var node2 = canvasNode.create({tag: 'header'}); + assert.notOk(node2.isOfClass('b')); + + }); + +}); + +suite('comparing nodes', function() { + test('isSame', function() { + var html = '
'; + var dom1 = $(html); + var dom2 = $(html); + assert.ok(canvasNode.create(dom1).isSame(canvasNode.create(dom1))); + assert.notOk(canvasNode.create(dom1).isSame(canvasNode.create(dom2))); + }); +}); + +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