Skip to content

Commit

Permalink
Fix wrong unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
Park Hyunwoo committed Sep 12, 2014
1 parent 3506d50 commit c91d30e
Showing 1 changed file with 64 additions and 62 deletions.
126 changes: 64 additions & 62 deletions test/unit/dom.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ define(['jquery', 'summernote/core/dom', 'summernote/core/func'], function ($, d
var $cont, $b, elB;

// basic case
$cont = $('<div><b>b</b><u>u</u><s>s</s><i>i</i></div>'); //busi
$cont = $('<div class="note-editable"><b>b</b><u>u</u><s>s</s><i>i</i></div>'); //busi
$b = $cont.find('b');
elB = $b[0].firstChild;

Expand All @@ -27,7 +27,7 @@ define(['jquery', 'summernote/core/dom', 'summernote/core/func'], function ($, d
test('dom.listAncestor', function () {
var $cont, $b, $u, $s, $i;

$cont = $('<div><i><s><u><b>b</b></u></s></i></div>'); //busi
$cont = $('<div class="note-editable"><i><s><u><b>b</b></u></s></i></div>'); //busi
$b = $cont.find('b');
$u = $cont.find('u');
$s = $cont.find('s');
Expand All @@ -46,7 +46,7 @@ define(['jquery', 'summernote/core/dom', 'summernote/core/func'], function ($, d
test('dom.listDescendant', function () {
var $cont, $b, $u, $s, $i;

$cont = $('<div><b></b><u></u><s></s><i></i></div>'); //busi
$cont = $('<div class="note-editable"><b></b><u></u><s></s><i></i></div>'); //busi
$b = $cont.find('b');
$u = $cont.find('u');
$s = $cont.find('s');
Expand All @@ -67,23 +67,24 @@ define(['jquery', 'summernote/core/dom', 'summernote/core/func'], function ($, d
});

test('dom.commonAncestor', function () {
var $cont, $span, $b, $u, $s, $i;
var $cont, $span, $div, $b, $u, $s, $i;

$cont = $('<div><span><b>b</b><u>u</u></span><span><s>s</s><i>i</i></span></div>');
$cont = $('<div class="note-editable"><div><span><b>b</b><u>u</u></span><span><s>s</s><i>i</i></span></div></div>');
$span = $cont.find('span');
$div = $cont.find('div');
$b = $cont.find('b');
$u = $cont.find('u');
$s = $cont.find('s');
$i = $cont.find('i');

equal(dom.commonAncestor($b[0], $u[0]), $span[0], 'common(b, u) => span');
equal(dom.commonAncestor($b[0], $s[0]), $cont[0], 'common(b, s) => div');
equal(dom.commonAncestor($b[0], $s[0]), $div[0], 'common(b, s) => div');
});

test('dom.listNext', function () {
var $cont, $b, $u, $s, $i;

$cont = $('<div><b>b</b><u>u</u><s>s</s><i>i</i></div>'); //busi
$cont = $('<div class="note-editable"><b>b</b><u>u</u><s>s</s><i>i</i></div>'); //busi
$b = $cont.find('b');
$u = $cont.find('u');
$s = $cont.find('s');
Expand All @@ -98,7 +99,7 @@ define(['jquery', 'summernote/core/dom', 'summernote/core/func'], function ($, d
test('dom.listPrev', function () {
var $cont, $b, $u, $s, $i;

$cont = $('<div><b>b</b><u>u</u><s>s</s><i>i</i></div>'); //busi
$cont = $('<div class="note-editable"><b>b</b><u>u</u><s>s</s><i>i</i></div>'); //busi
$b = $cont.find('b');
$u = $cont.find('u');
$s = $cont.find('s');
Expand All @@ -113,7 +114,7 @@ define(['jquery', 'summernote/core/dom', 'summernote/core/func'], function ($, d
test('dom.position', function () {
var $cont, $b, $u, $s, $i;

$cont = $('<div><b>b</b><u>u</u><s>s</s><i>i</i></div>'); //busi
$cont = $('<div class="note-editable"><b>b</b><u>u</u><s>s</s><i>i</i></div>'); //busi
$b = $cont.find('b');
$u = $cont.find('u');
$s = $cont.find('s');
Expand All @@ -130,7 +131,7 @@ define(['jquery', 'summernote/core/dom', 'summernote/core/func'], function ($, d
test('dom.makeOffsetPath', function () {
var $cont, $b, $u, $s, $i;

$cont = $('<div><b>b</b><u>u</u><s>s</s><i>i</i></div>'); //busi
$cont = $('<div class="note-editable"><b>b</b><u>u</u><s>s</s><i>i</i></div>'); //busi
$b = $cont.find('b');
$u = $cont.find('u');
$s = $cont.find('s');
Expand All @@ -154,7 +155,7 @@ define(['jquery', 'summernote/core/dom', 'summernote/core/func'], function ($, d
test('dom.fromOffsetPath', function () {
var $cont, $b, $u, $s, $i;

$cont = $('<div><b>b</b><u>u</u><s>s</s><i>i</i></div>'); //busi
$cont = $('<div class="note-editable"><b>b</b><u>u</u><s>s</s><i>i</i></div>'); //busi
$b = $cont.find('b');
$u = $cont.find('u');
$s = $cont.find('s');
Expand All @@ -173,69 +174,70 @@ define(['jquery', 'summernote/core/dom', 'summernote/core/func'], function ($, d
};

test('dom.splitTree', function () {
var $cont, $b, $u, $s, $i, $span;
var $busi, $para, $cont, $b, $u, $s, $i, $span;
$busi = $('<div class="note-editable"><p><b>b</b><u>u</u><s>strike</s><i>i</i></p></div>'); //busi

// 01. element pivot case
$cont = $('<div><b>b</b><u>u</u><s>s</s><i>i</i></div>'); //busi
$u = $cont.find('u');
dom.splitTree($cont[0], { node: $u[0], offset: 0 });
equalsToUpperCase($cont.html(), '<b>b</b><u><br></u>', 'splitBy u tag with offset 0');
equalsToUpperCase($cont.next().html(), '<u>u</u><s>s</s><i>i</i>', 'right hand side');

$cont = $('<div><b>b</b><u>u</u><s>s</s><i>i</i></div>'); //busi
$u = $cont.find('u');
dom.splitTree($cont[0], { node: $u[0], offset: 1 });
equalsToUpperCase($cont.html(), '<b>b</b><u>u</u>', 'splitBy u tag with offset 1');
equalsToUpperCase($cont.next().html(), '<u><br></u><s>s</s><i>i</i>', 'right hand side');

$cont = $('<div><b>b</b><u>u</u><s>s</s><i>i</i></div>'); //busi
$b = $cont.find('b');
dom.splitTree($cont[0], { node: $b[0], offset: 0 });
equalsToUpperCase($cont.html(), '<b><br></b>', 'splitBy b tag with offset 0 (left edge case)');
equalsToUpperCase($cont.next().html(), '<b>b</b><u>u</u><s>s</s><i>i</i>', 'right hand side');

$cont = $('<div><b>b</b><u>u</u><s>s</s><i>i</i></div>'); //busi
$i = $cont.find('i');
dom.splitTree($cont[0], { node: $i[0], offset: 1 });
equalsToUpperCase($cont.html(),
'<b>b</b><u>u</u><s>s</s><i>i</i>', 'splitBy i tag with offset 1 (right edge case)');
equalsToUpperCase($cont.next().html(), '<i><br></i>', 'right hand side');
$para = $busi.clone().find('p');
$u = $para.find('u');
dom.splitTree($para[0], { node: $u[0], offset: 0 });
equalsToUpperCase($para.html(), '<b>b</b><u><br></u>', 'splitBy u tag with offset 0');
equalsToUpperCase($para.next().html(), '<u>u</u><s>strike</s><i>i</i>', 'right hand side');

$para = $busi.clone().find('p');
$u = $para.find('u');
dom.splitTree($para[0], { node: $u[0], offset: 1 });
equalsToUpperCase($para.html(), '<b>b</b><u>u</u>', 'splitBy u tag with offset 1');
equalsToUpperCase($para.next().html(), '<u><br></u><s>strike</s><i>i</i>', 'right hand side');

$para = $busi.clone().find('p');
$b = $para.find('b');
dom.splitTree($para[0], { node: $b[0], offset: 0 });
equalsToUpperCase($para.html(), '<b><br></b>', 'splitBy b tag with offset 0 (left edge case)');
equalsToUpperCase($para.next().html(), '<b>b</b><u>u</u><s>strike</s><i>i</i>', 'right hand side');

$para = $busi.clone().find('p');
$i = $para.find('i');
dom.splitTree($para[0], { node: $i[0], offset: 1 });
equalsToUpperCase($para.html(),
'<b>b</b><u>u</u><s>strike</s><i>i</i>', 'splitBy i tag with offset 1 (right edge case)');
equalsToUpperCase($para.next().html(), '<i><br></i>', 'right hand side');

// 02. textNode case
$cont = $('<div><b>b</b><u>u</u><s>strike</s><i>i</i></div>'); //bustrikei
$s = $cont.find('s');
dom.splitTree($cont[0], { node: $s[0].firstChild, offset: 3 });
equalsToUpperCase($cont.html(), '<b>b</b><u>u</u><s>str</s>', 'splitBy s tag with offset 3 (middle case)');
equalsToUpperCase($cont.next().html(), '<s>ike</s><i>i</i>', 'right hand side');

$cont = $('<div><b>b</b><u>u</u><s>strike</s><i>i</i></div>'); //bustrikei
$s = $cont.find('s');
dom.splitTree($cont[0], { node: $s[0].firstChild, offset: 0 });
equalsToUpperCase($cont.html(), '<b>b</b><u>u</u><s><br></s>', 'splitBy s tag with offset 0 (left edge case)');
equalsToUpperCase($cont.next().html(), '<s>strike</s><i>i</i>', 'right hand side');

$cont = $('<div><b>b</b><u>u</u><s>strike</s><i>i</i></div>'); //bustrikei
$s = $cont.find('s');
dom.splitTree($cont[0], { node: $s[0].firstChild, offset: 6});
equalsToUpperCase($cont.html(), '<b>b</b><u>u</u><s>strike</s>', 'splitBy s tag with offset 6 (right edge case)');
equalsToUpperCase($cont.next().html(), '<s><br></s><i>i</i>', 'right hand side');

$cont = $('<div><b>b</b><u>u</u><s>strike</s><i>i</i></div>'); //bustrikei
$s = $cont.find('s');
$para = $busi.clone().find('p');
$s = $para.find('s');
dom.splitTree($para[0], { node: $s[0].firstChild, offset: 3 });
equalsToUpperCase($para.html(), '<b>b</b><u>u</u><s>str</s>', 'splitBy s tag with offset 3 (middle case)');
equalsToUpperCase($para.next().html(), '<s>ike</s><i>i</i>', 'right hand side');

$para = $busi.clone().find('p');
$s = $para.find('s');
dom.splitTree($para[0], { node: $s[0].firstChild, offset: 0 });
equalsToUpperCase($para.html(), '<b>b</b><u>u</u><s><br></s>', 'splitBy s tag with offset 0 (left edge case)');
equalsToUpperCase($para.next().html(), '<s>strike</s><i>i</i>', 'right hand side');

$para = $busi.clone().find('p');
$s = $para.find('s');
dom.splitTree($para[0], { node: $s[0].firstChild, offset: 6});
equalsToUpperCase($para.html(), '<b>b</b><u>u</u><s>strike</s>', 'splitBy s tag with offset 6 (right edge case)');
equalsToUpperCase($para.next().html(), '<s><br></s><i>i</i>', 'right hand side');

$para = $busi.clone().find('p');
$s = $para.find('s');
dom.splitTree($s[0], { node: $s[0].firstChild, offset: 3});
equalsToUpperCase($cont.html(), '<b>b</b><u>u</u><s>str</s><s>ike</s><i>i</i>',
equalsToUpperCase($para.html(), '<b>b</b><u>u</u><s>str</s><s>ike</s><i>i</i>',
'splitBy s tag with offset 3 (2 depth case)');

$cont = $('<div><b>b</b><u>u</u><s>strike</s><i>i</i></div>'); //bustrikei
$s = $cont.find('s');
$para = $busi.clone().find('p');
$s = $para.find('s');
dom.splitTree($s[0].firstChild, { node: $s[0].firstChild, offset: 3});
equalsToUpperCase($cont.html(), '<b>b</b><u>u</u><s>strike</s><i>i</i>',
equalsToUpperCase($para.html(), '<b>b</b><u>u</u><s>strike</s><i>i</i>',
'splitBy s tag with offset 3 (1 depth, textNode case)');

$cont = $('<div><span><b>b</b><u>u</u><s>s</s><i>i</i></span></div>'); //busi
$cont = $('<div class="note-editable"><p><span><b>b</b><u>u</u><s>s</s><i>i</i></span></p></div>'); //busi
$span = $cont.find('span');
dom.splitTree($span[0], { node: $span[0], offset: 2});
equalsToUpperCase($cont.html(), '<span><b>b</b><u>u</u></span><span><s>s</s><i>i</i></span>',
equalsToUpperCase($cont.html(), '<p><span><b>b</b><u>u</u></span><span><s>s</s><i>i</i></span></p>',
'splitBy span tag with offset 2 (1 depth, element case)');
});
};
Expand Down

0 comments on commit c91d30e

Please sign in to comment.