'); //busi
- $b = $cont.find('b');
- $u = $cont.find('u');
- $s = $cont.find('s');
- $i = $cont.find('i');
+ it('should return an array of next sibling elements including itself', function () {
+ expect(dom.listNext($u[0])).to.deep.equal([$u[0], $s[0], $i[0]]);
+ });
- deepEqual(dom.listNext($u[0]), [$u[0], $s[0], $i[0]], 'with no pred');
- deepEqual(dom.listNext($i[0]), [$i[0]], 'last item with no pred');
+ it('should return itself if there are no next sibling', function () {
+ expect(dom.listNext($i[0])).to.deep.equal([$i[0]]);
+ });
- deepEqual(dom.listNext($s[0], func.eq($i[0])), [$s[0]], 's to i');
+ it('should restun an array of next sibling elements before predicate is true', function () {
+ expect(dom.listNext($s[0], func.eq($i[0]))).to.deep.equal([$s[0]]);
+ });
});
- test('dom.listPrev', function () {
+ describe('listPrev', function () {
var $cont, $b, $u, $s, $i;
+ before(function () {
+ $cont = $('
',
- 'splitBy span tag with offset 2 (1 depth, element case)');
+
+ describe('splitTree', function () {
+ var $para;
+ beforeEach(function () {
+ var $busi = $('
bustrikei
'); //busi
+ $para = $busi.clone().find('p');
+ });
+
+ describe('element pivot case', function () {
+ it('should be splited by u tag with offset 0', function () {
+ var $u = $para.find('u');
+ dom.splitTree($para[0], {node: $u[0], offset: 0 });
+
+ helper.equalsToUpperCase($para.html(), 'b ', expect);
+ helper.equalsToUpperCase($para.next().html(), 'ustrikei', expect); // right hand side
+ });
+
+ it('should be splited by u tag with offset 1', function () {
+ var $u = $para.find('u');
+ dom.splitTree($para[0], {node: $u[0], offset: 1 });
+
+ helper.equalsToUpperCase($para.html(), 'bu', expect);
+ helper.equalsToUpperCase($para.next().html(), ' strikei', expect); // right hand side
+ });
+
+ it('should be splited by b tag with offset 0 (left edge case)', function () {
+ var $b = $para.find('b');
+ dom.splitTree($para[0], {node: $b[0], offset: 0 });
+
+ helper.equalsToUpperCase($para.html(), ' ', expect);
+ helper.equalsToUpperCase($para.next().html(), 'bustrikei', expect); // right hand side
+ });
+
+ it('should be splited by i tag with offset 1 (right edge case)', function () {
+ var $i = $para.find('i');
+ dom.splitTree($para[0], {node: $i[0], offset: 1 });
+
+ helper.equalsToUpperCase($para.html(), 'bustrikei', expect);
+ helper.equalsToUpperCase($para.next().html(), ' ', expect); // right hand side
+ });
+ });
+
+ describe('textNode case', function () {
+ it('should be splited by s tag with offset 3 (middle case)', function () {
+ var $s = $para.find('s');
+ dom.splitTree($para[0], {node: $s[0].firstChild, offset: 3 });
+
+ helper.equalsToUpperCase($para.html(), 'bustr', expect);
+ helper.equalsToUpperCase($para.next().html(), 'ikei', expect); // right hand side
+ });
+
+ it('should be splited by s tag with offset 0 (left edge case)', function () {
+ var $s = $para.find('s');
+ dom.splitTree($para[0], {node: $s[0].firstChild, offset: 0 });
+
+ helper.equalsToUpperCase($para.html(), 'bu ', expect);
+ helper.equalsToUpperCase($para.next().html(), 'strikei', expect); // right hand side
+ });
+
+ it('should be splited by s tag with offset 6 (right edge case)', function () {
+ var $s = $para.find('s');
+ dom.splitTree($para[0], {node: $s[0].firstChild, offset: 6 });
+
+ helper.equalsToUpperCase($para.html(), 'bustrike', expect);
+ helper.equalsToUpperCase($para.next().html(), ' i', expect); // right hand side
+ });
+
+ it('should be splited by s tag with offset 3 (2 depth case)', function () {
+ var $s = $para.find('s');
+ dom.splitTree($s[0], {node: $s[0].firstChild, offset: 3 });
+
+ helper.equalsToUpperCase($para.html(), 'bustrikei', expect);
+ });
+
+ it('should be splited by s tag with offset 3 (1 depth and textNode case)', function () {
+ var $s = $para.find('s');
+ dom.splitTree($s[0].firstChild, {node: $s[0].firstChild, offset: 3 });
+
+ helper.equalsToUpperCase($para.html(), 'bustrikei', expect);
+ });
+
+ it('should be splited by span tag with offset 2 (1 depth and element case)', function () {
+ var $cont = $('
');
+ describe('splitPoint', function () {
+ it('should retun rightNode and container for empty paragraph with inline', function () {
+ var $editable = $('
');
+ var $para = $editable.clone().find('p');
+ var $br = $para.find('br');
+ var result = dom.splitPoint({ node: $para[0], offset: 0 }, true);
+ expect(result).to.deep.equal({ rightNode: $br[0], container: $para[0] });
+
+ });
});
- };
+ });
});
diff --git a/test/unit/func.spec.js b/test/unit/func.spec.js
index bd1e3e814..740e307f0 100644
--- a/test/unit/func.spec.js
+++ b/test/unit/func.spec.js
@@ -4,56 +4,57 @@
* summernote may be freely distributed under the MIT license./
*/
define([
+ 'chai',
'summernote/core/func'
-], function (func) {
- return function () {
- test('func.eq2', function () {
- ok(func.eq2(1, 1), 'should return true');
- ok(!func.eq2(1, '1'), 'should return false');
+], function (chai, func) {
+ 'use strict';
+
+ var expect = chai.expect;
+
+ describe('core.func', function () {
+ describe('eq2', function () {
+ it('should return true if two values are same', function () {
+ expect(func.eq2(1, 1)).to.be.ok;
+ });
+
+ it('should return false if two values are not same', function () {
+ expect(func.eq2(1, '1')).to.be.not.ok;
+ });
});
- test('func.peq2', function () {
- ok(func.peq2('prop')({
- prop: 'hello'
- }, {
- prop: 'hello'
- }), 'should return true');
-
- ok(!func.peq2('prop')({
- prop: 'hello'
- }, {
- prop: 'world'
- }), 'should return false');
+ describe('peq2', function () {
+ it('should return true when two properties are same', function () {
+ expect(func.peq2('prop')({ prop: 'hello' }, { prop: 'hello' })).to.be.ok;
+ });
+
+ it('should return false when two properties are not same', function () {
+ expect(func.peq2('prop')({ prop: 'hello' }, { prop: 'world' })).to.be.not.ok;
+ });
});
- test('func.uniqueId', function () {
- equal(func.uniqueId('note-'), 'note-1', 'should returns uniqueId with prefix');
- equal(func.uniqueId('note-'), 'note-2', 'should returns uniqueId with prefix');
- equal(func.uniqueId('note-'), 'note-3', 'should returns uniqueId with prefix');
+ describe('uniqueId', function () {
+ it('should return uniqueId with the prefix as a parameter', function () {
+ expect(func.uniqueId('note-')).to.be.equal('note-1');
+ expect(func.uniqueId('note-')).to.be.equal('note-2');
+ expect(func.uniqueId('note-')).to.be.equal('note-3');
+ });
});
- test('func.invertObject', function () {
- deepEqual(func.invertObject({
- keyA: 'valueA',
- keyB: 'valueB'
- }), {
- valueA: 'keyA',
- valueB: 'keyB'
- }, 'should returns inverted object');
+ describe('invertObject', function () {
+ it('should return inverted object between keys and values', function () {
+ expect(func.invertObject({ keyA: 'valueA', keyB: 'valueB' }))
+ .to.deep.equal({ valueA: 'keyA', valueB: 'keyB'});
+ });
});
- test('func.namespaceToCamel', function () {
- equal(
- func.namespaceToCamel('upload.image'),
- 'UploadImage',
- 'shuold returns camel text'
- );
-
- equal(
- func.namespaceToCamel('upload.image', 'summernote'),
- 'summernoteUploadImage',
- 'shuold returns camel text with prefix'
- );
+ describe('namespaceToCamel', function () {
+ it('should return camelcase text', function () {
+ expect(func.namespaceToCamel('upload.image')).to.be.equal('UploadImage');
+ });
+
+ it('should return prefixed camelcase text', function () {
+ expect(func.namespaceToCamel('upload.image', 'summernote')).to.be.equal('summernoteUploadImage');
+ });
});
- };
+ });
});
diff --git a/test/unit/key.spec.js b/test/unit/key.spec.js
index e29b737b4..692458cf0 100644
--- a/test/unit/key.spec.js
+++ b/test/unit/key.spec.js
@@ -4,15 +4,23 @@
* summernote may be freely distributed under the MIT license./
*/
define([
+ 'chai',
'summernote/core/key'
-], function (key) {
- return function () {
- test('key.isEdit', function () {
- ok(key.isEdit(key.code.BACKSPACE), 'isEdit with BACKSPACE should returns true');
- });
+], function (chai, key) {
+ 'use strict';
+
+ var expect = chai.expect;
- test('key.isMove', function () {
- ok(key.isMove(key.code.LEFT), 'isEdit with LEFT should returns true');
+ describe('core.key', function () {
+ describe('isEdit', function () {
+ it('should return true for BACKSPACE', function () {
+ expect(key.isEdit(key.code.BACKSPACE)).to.be.true;
+ });
+ });
+ describe('isMove', function () {
+ it('should return true for LEFT', function () {
+ expect(key.isMove(key.code.LEFT)).to.be.true;
+ });
});
- };
+ });
});
diff --git a/test/unit/list.spec.js b/test/unit/list.spec.js
index aff65e3e9..3fe555930 100644
--- a/test/unit/list.spec.js
+++ b/test/unit/list.spec.js
@@ -3,77 +3,116 @@
* (c) 2013~ Alan Hong
* summernote may be freely distributed under the MIT license./
*/
-define(['jquery', 'summernote/core/list'], function ($, list) {
- return function () {
- test('list.head', function () {
- deepEqual(list.head([1, 2, 3]), 1, 'should return the first element');
+define(['chai', 'jquery', 'summernote/core/list'], function (chai, $, list) {
+ 'use strict';
+
+ var expect = chai.expect;
+
+ describe('core.list', function () {
+ describe('head', function () {
+ it('should return the first element', function () {
+ expect(list.head([1, 2, 3])).to.be.equal(1);
+ });
});
- test('list.last', function () {
- deepEqual(list.last([1, 2, 3]), 3, 'should return the last element');
+ describe('last', function () {
+ it('should return the last element', function () {
+ expect(list.last([1, 2, 3])).to.be.equal(3);
+ });
});
- test('list.initial', function () {
- deepEqual(list.initial([1, 2, 3]), [1, 2], 'should exclude last element');
+ describe('initial', function () {
+ it('should exclude last element', function () {
+ expect(list.initial([1, 2, 3])).to.deep.equal([1, 2]);
+ });
});
- test('list.tail', function () {
- deepEqual(list.tail([1, 2, 3]), [2, 3], 'should exclude first element');
+ describe('tail', function () {
+ it('should exclude first element', function () {
+ expect(list.tail([1, 2, 3])).to.deep.equal([2, 3]);
+ });
});
var isEven = function (num) {
return num % 2 === 0;
};
- test('list.find', function () {
- deepEqual(list.find([1, 2, 3], isEven), 2, 'should returns first matched element');
+ describe('find', function () {
+ it('should return first matched element', function () {
+ expect(list.find([1, 2, 3], isEven)).to.be.equal(2);
+ });
});
- test('list.all', function () {
- deepEqual(list.all([1, 2, 3], isEven), false, 'should returns false');
- deepEqual(list.all([2, 4], isEven), true, 'should returns true');
+ describe('all', function () {
+ it('should return false if all elements are not even', function () {
+ expect(list.all([1, 2, 3], isEven)).to.be.false;
+ });
+
+ it('should return true if all elements are even', function () {
+ expect(list.all([2, 4], isEven)).to.be.true;
+ });
});
- test('list.sum', function () {
- deepEqual(list.contains([1, 2, 3], 4), false, 'should returns false');
- deepEqual(list.contains([1, 2, 4], 4), true, 'should returns true');
+ describe('all', function () {
+ it('should return false if the element is not contained', function () {
+ expect(list.contains([1, 2, 3], 4)).to.be.false;
+ });
+
+ it('should return true if the element is contained', function () {
+ expect(list.contains([1, 2, 4], 4)).to.be.true;
+ });
});
- test('list.sum', function () {
- deepEqual(list.sum([1, 2, 3]), 6, 'should return 6');
- deepEqual(list.sum([1, 2, 3], function (v) { return v * 2; }), 12, 'should return 12');
+ describe('sum', function () {
+ it('should return sum of all elements', function () {
+ expect(list.sum([1, 2, 3])).to.be.equal(6);
+ });
+
+ it('should return sum of all elements iterated', function () {
+ var result = list.sum([1, 2, 3], function (v) { return v * 2; });
+ expect(result).to.be.equal(12);
+ });
});
- test('list.from', function () {
- var $cont, $b, $u, $s, $i;
- $cont = $('
busi
'); //busi
- $b = $cont.find('b');
- $u = $cont.find('u');
- $s = $cont.find('s');
- $i = $cont.find('i');
+ describe('from', function () {
+ it('should return an array of childNodes', function () {
+ var $cont, $b, $u, $s, $i;
+ $cont = $('
busi
'); //busi
+ $b = $cont.find('b');
+ $u = $cont.find('u');
+ $s = $cont.find('s');
+ $i = $cont.find('i');
- deepEqual(list.from($cont[0].childNodes),
- [$b[0], $u[0], $s[0], $i[0]], 'should return array of childNodes');
+ expect(list.from($cont[0].childNodes)).to.deep.equal([$b[0], $u[0], $s[0], $i[0]]);
+ });
});
- test('list.clusterBy', function () {
- var aaClustered = list.clusterBy([1, 1, 2, 2, 3], function (itemA, itemB) {
- return itemA === itemB;
+ describe('clusterBy', function () {
+ it('should cluster by equality 1', function () {
+ var aaClustered = list.clusterBy([1, 1, 2, 2, 3], function (itemA, itemB) {
+ return itemA === itemB;
+ });
+ expect(aaClustered).to.deep.equal([[1, 1], [2, 2], [3]]);
});
- deepEqual([[1, 1], [2, 2], [3]], aaClustered, 'should cluster by equality 1');
- aaClustered = list.clusterBy([1, 2, 2, 1, 3], function (itemA, itemB) {
- return itemA === itemB;
+ it('should cluster by equality 2', function () {
+ var aaClustered = list.clusterBy([1, 2, 2, 1, 3], function (itemA, itemB) {
+ return itemA === itemB;
+ });
+ expect(aaClustered).to.deep.equal([[1], [2, 2], [1], [3]]);
});
- deepEqual([[1], [2, 2], [1], [3]], aaClustered, 'should cluster by equality 2');
});
- test('list.compact', function () {
- deepEqual(list.compact([0, 1, false, 2, '', 3]), [1, 2, 3], 'falsey values of `array` removed');
+ describe('compact', function () {
+ it('should remove all elements has falsey value', function () {
+ expect(list.compact([0, 1, false, 2, '', 3])).to.deep.equal([1, 2, 3]);
+ });
});
- test('list.unique', function () {
- deepEqual(list.unique([1, 2, 3, 3, 2, 1]), [1, 2, 3], 'returns duplicate-free version of array');
+ describe('unique', function () {
+ it('should return duplicate-free version of array', function () {
+ expect(list.unique([1, 2, 3, 3, 2, 1])).to.deep.equal([1, 2, 3]);
+ });
});
- };
+ });
});
diff --git a/test/unit/range.spec.js b/test/unit/range.spec.js
index e458c08d3..f8a9ea72a 100644
--- a/test/unit/range.spec.js
+++ b/test/unit/range.spec.js
@@ -4,397 +4,406 @@
* summernote may be freely distributed under the MIT license./
*/
define([
+ 'chai',
+ 'helper',
'jquery',
- 'summernote/core/agent',
'summernote/core/dom',
'summernote/core/range'
-], function ($, agent, dom, range) {
- return function (helper) {
- test('rng.nodes', function () {
- var rng, $cont, $para, $li, $h1, $h2, $b;
-
- //01. 1 depth
- $cont = $('
',
- 'rng.pasteHTML with inlines should not split text.'
- );
+ describe('insertNode', function () {
+ it('should split paragraph when inserting a block element', function () {
+ var $cont = $('
', expect);
+ });
+
+ it('should not split paragraph when inserting an inline element', function () {
+ var $cont = $('
text
');
+ var $p = $cont.find('p');
+ var $u = $('u');
+
+ var rng = range.create($p[0].firstChild, 2, $p[0].firstChild, 2);
+ rng.insertNode($u[0]);
+ helper.equalsToUpperCase($cont.html(), '
teuxt
', expect);
+ });
+
+ it('should not split paragraph when inserting an inline element case 2', function () {
+ var $cont = $('
bold
');
+ var $b = $cont.find('b');
+ var $u = $('u');
+
+ var rng = range.create($b[0].firstChild, 2, $b[0].firstChild, 2);
+ rng.insertNode($u[0]);
+ helper.equalsToUpperCase($cont.html(), '
bould
', expect);
+ });
});
- test('rng.deleteContents', function () {
- var $cont, $p, $b, $u;
+ describe('pasteHTML', function () {
+ it('should not split a block element when inserting inline elements into it', function () {
+ var $cont = $('
text
');
+ var $p = $cont.find('p');
+ var markup = 'spanitalic';
+
+ var rng = range.create($p[0].firstChild, 2);
+ rng.pasteHTML(markup);
+
+ helper.equalsToUpperCase($cont.html(), '
tespanitalicxt
', expect);
+ });
+
+ it('should split an inline element when pasting inline elements into it', function () {
+ var $cont = $('
bold
');
+ var $b = $cont.find('b');
+ var markup = 'spanitalic';
- // deleteContents on partial text
- $cont = $('
', 'rng.deleteContents on full text should remove text');
+ var rng = range.create($b[0].firstChild, 2);
+ rng.pasteHTML(markup);
+ helper.equalsToUpperCase($cont.html(), '
bospan
italic
ld
', expect);
+ });
});
- test('rng.wrapBodyInlineWithPara', function () {
+ describe('deleteContents', function () {
var $cont, $b;
+ beforeEach(function () {
+ $cont = $('
',
- 'rng.wrapBodyInlineWithPara with inline should wrap text with paragraph.'
- );
+ it('should remove text only for partial text', function () {
+ var rng = range.create($b[0].firstChild, 1, $b[0].firstChild, 3);
+ rng.deleteContents();
+
+ helper.equalsToUpperCase($cont.html(), '
bdu
', expect);
+ });
+
+ it('should remove text for entire text', function () {
+ var rng = range.create($b[0].firstChild, 0, $b[0].firstChild, 4);
+ rng.deleteContents();
+
+ helper.equalsToUpperCase($cont.html(), '
u
', expect);
+ });
});
- test('rng.getWordRange', function () {
- var $cont, rng;
-
- $cont = $('
super simple wysiwyg editor
');
-
- // no word before cursor
- rng = range.create(
- $cont[0].firstChild, 0
- ).getWordRange();
-
- deepEqual([
- rng.sc, rng.so, rng.ec, rng.eo
- ], [
- $cont[0].firstChild, 0, $cont[0].firstChild, 0
- ], 'rng.getWordRange with no word before cursor should return itself');
-
- // find word before cursor
- rng = range.create(
- $cont[0].firstChild, 5
- ).getWordRange();
-
- deepEqual([
- rng.sc, rng.so, rng.ec, rng.eo
- ], [
- $cont[0].firstChild, 0, $cont[0].firstChild, 5
- ], 'rng.getWordRange with word before cursor should return expanded range');
-
- rng = range.create(
- $cont[0].firstChild, 3
- ).getWordRange();
-
- deepEqual([
- rng.sc, rng.so, rng.ec, rng.eo
- ], [
- $cont[0].firstChild, 0, $cont[0].firstChild, 3
- ], 'rng.getWordRange with half word before cursor should expanded range');
-
- rng = range.create(
- $cont[0].firstChild, 12
- ).getWordRange();
-
- deepEqual([
- rng.sc, rng.so, rng.ec, rng.eo
- ], [
- $cont[0].firstChild, 6, $cont[0].firstChild, 12
- ], 'rng.getWordRange with half word before cursor should expanded range');
+ describe('wrapBodyInlineWithPara', function () {
+ it('should insert an empty paragraph when there is no contents', function () {
+ var $cont = $('');
+
+ var rng = range.create($cont[0], 0);
+ rng.wrapBodyInlineWithPara();
+
+ helper.equalsToUpperCase($cont.html(), '
', expect);
+ });
+
+ it('should wrap text with paragraph for text', function () {
+ var $cont = $('
');
+ });
+
+ it('should return the range itself when there is no word before cursor', function () {
+ var rng = range.create($cont[0].firstChild, 0).getWordRange();
+
+ expect(rng.sc).to.deep.equal($cont[0].firstChild);
+ expect(rng.so).to.equal(0);
+ expect(rng.ec).to.deep.equal($cont[0].firstChild);
+ expect(rng.eo).to.equal(0);
+ });
+
+ it('should return expanded range when there is a word before cursor', function () {
+ var rng = range.create($cont[0].firstChild, 5).getWordRange();
+
+ expect(rng.sc).to.deep.equal($cont[0].firstChild);
+ expect(rng.so).to.equal(0);
+ expect(rng.ec).to.deep.equal($cont[0].firstChild);
+ expect(rng.eo).to.equal(5);
+ });
+
+ it('should return expanded range when there is a half word before cursor', function () {
+ var rng = range.create($cont[0].firstChild, 3).getWordRange();
+
+ expect(rng.sc).to.deep.equal($cont[0].firstChild);
+ expect(rng.so).to.equal(0);
+ expect(rng.ec).to.deep.equal($cont[0].firstChild);
+ expect(rng.eo).to.equal(3);
+ });
+
+ it('should return expanded range when there are words before cursor', function () {
+ var rng = range.create($cont[0].firstChild, 12).getWordRange();
+
+ expect(rng.sc).to.deep.equal($cont[0].firstChild);
+ expect(rng.so).to.equal(6);
+ expect(rng.ec).to.deep.equal($cont[0].firstChild);
+ expect(rng.eo).to.equal(12);
+ });
});
- };
+ });
});
diff --git a/test/unit/style.spec.js b/test/unit/style.spec.js
index 0f3d2f978..651aeed53 100644
--- a/test/unit/style.spec.js
+++ b/test/unit/style.spec.js
@@ -4,122 +4,92 @@
* summernote may be freely distributed under the MIT license./
*/
define([
+ 'chai',
'jquery',
- 'summernote/core/dom',
'summernote/core/range',
'summernote/editing/Style'
-], function ($, dom, range, Style) {
- return function () {
+], function (chai, $, range, Style) {
+ 'use strict';
+
+ var expect = chai.expect;
+
+ describe('editing.Style', function () {
var style = new Style();
- var equalsToUpperCase = function (actual, expected, comment) {
- ok(actual.toUpperCase() === expected.toUpperCase(), comment);
- };
-
- test('style.styleNodes basic', function () {
- var $cont, $p, $b, $span, rng, nodes;
-
- $cont = $('
',
- 'should wrap each texts with span except not single blood line'
- );
- });
+ describe('styleNodes', function () {
+ it('should wrap selected text with span', function () {
+ var $cont = $('
text
');
+ var $p = $cont.find('p');
+ var rng = range.create($p[0].firstChild, 0, $p[0].firstChild, 4);
+ style.styleNodes(rng);
+
+ expect($cont.html()).to.deep.equal('
text
');
+ });
- test('style.styleNodes options', function () {
- var $cont, $p, rng, nodes;
+ it('should split text and wrap selected text with span', function () {
+ var $cont = $('
text
');
+ var $p = $cont.find('p');
+ var rng = range.create($p[0].firstChild, 1, $p[0].firstChild, 3);
+ style.styleNodes(rng);
- $cont = $('