X-Git-Url: https://git.mdrn.pl/fnpeditor.git/blobdiff_plain/0f406b246f9261651b5982be71a49189349c8e3e..f7c97ef38dc00ec9b5358ae0bf959a5e6f99271c:/modules/documentCanvas/tests/canvas.test.js?ds=inline
diff --git a/modules/documentCanvas/tests/canvas.test.js b/modules/documentCanvas/tests/canvas.test.js
index 386e375..0589c11 100644
--- a/modules/documentCanvas/tests/canvas.test.js
+++ b/modules/documentCanvas/tests/canvas.test.js
@@ -2,102 +2,177 @@ define([
'libs/jquery-1.9.1.min',
'libs/chai',
'./utils.js',
-'modules/documentCanvas/canvas'
-], function($, chai, utils, canvas) {
+'modules/documentCanvas/canvas',
+'modules/documentCanvas/canvasNode'
+], function($, chai, utils, canvas, canvasNode) {
'use strict';
var assert = chai.assert;
+ var assertDomEqual = utils.assertDomEqual;
- assert.xmlEqual = function(lhsText, rhsText) {
- var cleanLhs = utils.cleanUp(lhsText);
- var cleanRhs = utils.cleanUp(rhsText);
-
- var lhs = $(cleanLhs);
- var rhs = $(cleanRhs);
-
- this.equal(lhs.length, 1);
- this.equal(rhs.length, 1);
-
- lhs = lhs.get(0);
- rhs = rhs.get(0);
-
- var test = lhs.isEqualNode(rhs);
- if(!test) {
- console.log(cleanLhs);
- console.log(cleanRhs);
- }
- return this.ok(test, 'xmls are equal');
- };
- var retrievingTest = function(title, xml) {
- test(title, function() {
- var c = new canvas.Canvas(xml);
- assert.xmlEqual(c.toXML(), xml);
+ suite('Quering nodes', function() {
+ test('getting preceding node', function() {
+ var c = canvas.create('
');
+ });
+
+ test('append node to another node', function() {
+ var c = canvas.create('
');
+ var node = canvasNode.create({tag: 'header', klass: 'some-class'});
+ var to = c.findNodes('div')[0];
+ c.nodeAppend({node: node, to: to});
+ assertDomEqual(c.getContent(), '
');
+ });
+
+ test('insert node after another node', function() {
+ var c = canvas.create('
');
+ var node = canvasNode.create({tag: 'header', klass: 'some-class'});
+ var after = c.findNodes('div')[0];
+ c.nodeInsertAfter({node: node, after: after});
+ assertDomEqual(c.getContent(), '
');
});
test('wrap text in node', function() {
- var c = new canvas.Canvas('
');
- var header = c.getNode({tag: 'header'})[0];
- c.insertNode({place: 'wrapText', context: header, tag: 'span', klass: 'url', offsetStart: 1, offsetEnd: 6});
- assert.xmlEqual(c.toXML(), '
');
+ var c = canvas.create('
');
+ var header = c.findNodes({tag: 'header'})[0];
+ var wrapper = canvasNode.create({tag: 'aside'});
+ c.nodeWrap({inside: header, _with: wrapper, offsetStart: 1, offsetEnd: 6})
+ assertDomEqual(c.getContent(), '
');
});
test('split node', function() {
- var c = new canvas.Canvas('
');
- var header = c.getNode({tag: 'header'})[0];
- c.splitNode({node: header, offset: 4});
- assert.xmlEqual(c.toXML(), '\
-
'
- );
+ var c = canvas.create('
');
+ var header = c.findNodes({tag: 'header'})[0];
+ var newNode = c.nodeSplit({node: header, offset: 4});
+ assertDomEqual(c.getContent(), utils.cleanUp('\
+
'));
+ assert.ok(newNode.isSame(c.findNodes({tag: 'header'})[1]));
+ });
+
+ test('split root node', function() {
+ var c = canvas.create('
cat
');
+ var header = c.findNodes({tag: 'header'})[0];
+ var newNode = c.nodeSplit({node: header, offset: 1});
+ assertDomEqual(c.getContent(), utils.cleanUp('\
+
c
\
+
at
'));
+ assert.ok(newNode.isSame(c.findNodes({tag: 'header'})[1]));
});
- test('list', function() {
- var c = new canvas.Canvas('
');
- var div1 = c.getNode({tag:'div'})[0];
- var div2 = c.getNode({tag:'div'})[1];
+ test('split node with subnodes', function() {
+ var c = canvas.create(utils.cleanUp('\
+
\
+
Fancy and niceheader 1
\
+
'));
+ var header = c.findNodes({tag: 'header'})[0];
+ var newNode = c.nodeSplit({node: header, offset: 5});
+ assertDomEqual(c.getContent(), utils.cleanUp('\
+
\
+
Fancy
\
+
and niceheader 1
\
+
'));
+ });
+
+ test('remove node', function() {
+ var c = canvas.create('
some text
');
+ var span = c.findNodes({tag: 'span'})[0];
+ c.nodeRemove({node: span});
+ assertDomEqual(c.getContent(), '
');
+ });
+ });
+
+
+ suite('Lists', function() {
+ test('create from existing nodes', function() {
+ var c = canvas.create(utils.cleanUp('\
+
\
+
alice
\
+ has\
+
a
\
+
cat
\
+
or not
\
+
'
+ ));
+
+ var div_alice = c.findNodes({tag: 'div'})[0];
+ var div_cat = c.findNodes({tag:'div'})[2];
- c.createList({start: div1, end: div2});
+ c.listCreate({start: div_alice, end: div_cat});
- assert.xmlEqual(c.toXML(), '\
-
\
- \
-
Alice
\
-
has
\
-
a cat
\
+ assertDomEqual(c.getContent(), utils.cleanUp('\
+
\
+
\
+
alice
\
+
has
\
+
a
\
+
cat
\
\
- ');
+
or not
\
+
'));
+ });
+
+ test('create from existing nodes - start/end order doesn\'t matter', function() {
+ var html = utils.cleanUp('\
+
alice
\
+
cat
');
+ var expected = utils.cleanUp('\
+
');
+
+ var c = canvas.create(html);
+ var div_alice = c.findNodes({tag: 'div'})[0];
+ var div_cat = c.findNodes({tag:'div'})[1];
+ c.listCreate({start: div_cat, end: div_alice});
+ assertDomEqual(c.getContent(), expected);
+ c = canvas.create(html);
+ div_alice = c.findNodes({tag: 'div'})[0];
+ div_cat = c.findNodes({tag:'div'})[1];
+ c.listCreate({start: div_alice, end: div_cat});
+ assertDomEqual(c.getContent(), expected);
+ });
+
+ test('remove', function() {
+ var c = canvas.create(utils.cleanUp('\
+
'));
+ var item = c.findNodes({klass: 'item'})[1];
+ c.listRemove({pointer: item});
+ assertDomEqual(c.getContent(), utils.cleanUp('\
+
'));
});
});
-
});
\ No newline at end of file