2 'libs/jquery-1.9.1.min',
5 'modules/documentCanvas/canvasNode'
6 ], function($, chai, utils, canvasNode) {
10 var assert = chai.assert;
12 var assertDomEqual = function(lhs, rhs) {
15 return assert.ok(lhs[0].isEqualNode(rhs[0]), 'nodes are equal');
19 suite('Create canvas node', function() {
20 test('from description', function() {
21 var node = canvasNode.create({
24 content: 'some text content',
25 meta: {uri: 'some uri'}
27 assert.equal(node.getTag(), 'header');
28 assert.equal(node.getClass(), 'some-class');
29 assert.equal(node.getContent(), 'some text content');
30 assert.equal(node.getMetaAttr('uri'), 'some uri');
31 assertDomEqual($('<div wlxml-tag="header" wlxml-class="some-class" wlxml-meta-uri="some uri">some text content</div>'), node.dom);
34 test('from dom object', function() {
35 var node = canvasNode.create($('<div wlxml-tag="header" wlxml-class="some-class" id="1" wlxml-meta-uri="some uri">'));
36 assert.equal(node.getTag(), 'header');
37 assert.equal(node.getClass(), 'some-class');
38 assert.equal(node.getMetaAttr('uri'), 'some uri');
39 //assertDomEqual($('<div wlxml-tag="header" wlxml-class="some-class">'), node.dom);
43 suite('class information', function() {
44 test('class of', function() {
45 var node = canvasNode.create({tag: 'header', klass: 'a-b-c'});
46 assert.ok(node.isOfClass('a'), 'first level');
47 assert.ok(node.isOfClass('a-b'), 'second level');
48 assert.ok(node.isOfClass('a-b-c'), 'third level');
49 assert.notOk(node.isOfClass('b-c'));
51 var node2 = canvasNode.create({tag: 'header'});
52 assert.notOk(node2.isOfClass('b'));
58 suite('comparing nodes', function() {
59 test('isSame', function() {
60 var html = '<div wlxml-class="some-class" wlxml-tag="some-tag">';
63 assert.ok(canvasNode.create(dom1).isSame(canvasNode.create(dom1)));
64 assert.notOk(canvasNode.create(dom1).isSame(canvasNode.create(dom2)));
68 suite('meta attributes', function() {
69 test('get list of node\'s meta attributes', function() {
70 var node = canvasNode.create({tag: 'tag', klass: 'klass', meta: {a:1, b:2}});
71 var attrs = node.getMetaAttrs();
72 var expected = [{name: 'a', value: '1'}, {name:'b', value: '2'}];
74 assert.deepEqual(attrs.sort(), expected.sort());
77 test('set meta attribute', function() {
78 var node = canvasNode.create({tag: 'tag', meta: {a:'1'}});
79 node.setMetaAttr('a', '2');
80 assert.equal(node.dom.attr('wlxml-meta-a'), '2');