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(), 'uri');
29 assert.equal(node.getContent(), 'some text content');
30 assert.equal(node.getMetaAttr('uri'), 'some uri');
31 assertDomEqual($('<div wlxml-tag="header" wlxml-class="uri" 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: 'span', klass: 'uri', meta: {uri:'http://some.uri.com'}});
71 var attrs = node.getMetaAttrs();
72 var expected = [{name: 'uri', value: 'http://some.uri.com'}];
74 assert.deepEqual(attrs.sort(), expected.sort());
77 test('get list of node\'s meta attributes when attributes not set', function() {
78 var node = canvasNode.create({tag: 'span', klass: 'uri'});
79 var attrs = node.getMetaAttrs();
80 var expected = [{name: 'uri', value: ''}];
81 assert.deepEqual(attrs.sort(), expected.sort());
84 test('set meta attribute', function() {
85 var node = canvasNode.create({tag: 'tag', klass: 'uri', meta: {'uri': 'some uri'}});
86 node.setMetaAttr('uri', 'some uri 2');
87 assert.equal(node.dom.attr('wlxml-meta-uri'), 'some uri 2');
90 test('changing class changes meta attributes', function() {
91 var node = canvasNode.create({tag: 'span', klass: 'uri', meta: {uri: 'http://some.uri.com'}});
93 assert.equal(node.getMetaAttr('uri'), 'http://some.uri.com');
95 node.setClass('author');
97 assert.equal(node.getMetaAttr('uri'), undefined);
100 test('changing class to another with the same attribute keeps the value', function() {
101 var node = canvasNode.create({tag: 'span', klass: 'uri', meta: {uri: 'http://some.uri.com'}});
102 assert.equal(node.getMetaAttr('uri'), 'http://some.uri.com');
103 node.setClass('uri-subclass');
104 assert.equal(node.getMetaAttr('uri'), 'http://some.uri.com');