0
Fork 0
mirror of https://github.com/fastmail/Squire.git synced 2025-01-03 05:00:13 -05:00

Tests run in latest Chrome, FF, Safari + IE10 and 11.

This commit is contained in:
Gert Sønderby 2015-06-16 12:39:31 +02:00 committed by Neil Jenkins
parent 985d886ffd
commit 6aba099388
4 changed files with 26 additions and 23 deletions

View file

@ -3622,7 +3622,7 @@ proto.setTextDirection = function ( direction ) {
function forEachChildInRange( rootNode, range, iterator ) { function forEachChildInRange( rootNode, range, iterator ) {
var walker = new TreeWalker( rootNode, SHOW_ELEMENT, var walker = new TreeWalker( rootNode, SHOW_ELEMENT|SHOW_TEXT,
function ( node ) { function ( node ) {
return node.parentNode === rootNode && return node.parentNode === rootNode &&
isNodeContainedInRange( range, node, false /* include partials */ ); isNodeContainedInRange( range, node, false /* include partials */ );

View file

@ -2164,7 +2164,7 @@ proto.setTextDirection = function ( direction ) {
function forEachChildInRange( rootNode, range, iterator ) { function forEachChildInRange( rootNode, range, iterator ) {
var walker = new TreeWalker( rootNode, SHOW_ELEMENT, var walker = new TreeWalker( rootNode, SHOW_ELEMENT|SHOW_TEXT,
function ( node ) { function ( node ) {
return node.parentNode === rootNode && return node.parentNode === rootNode &&
isNodeContainedInRange( range, node, false /* include partials */ ); isNodeContainedInRange( range, node, false /* include partials */ );

0
test/blank.html Normal file
View file

View file

@ -12,7 +12,9 @@ expect = expect.clone()
}) })
.addAssertion('[not] to contain HTML', function (expect, editor, expectedValue) { .addAssertion('[not] to contain HTML', function (expect, editor, expectedValue) {
this.errorMode = 'bubble'; this.errorMode = 'bubble';
expect(editor.getHTML(), '[not] to be', expectedValue); var actualHTML = editor.getHTML().replace(/<br>/g, '');
// BR tags are inconsistent across browsers. Removing them allows cross-browser testing.
expect(actualHTML, '[not] to be', expectedValue);
}); });
describe('Squire RTE', function () { describe('Squire RTE', function () {
@ -25,45 +27,46 @@ describe('Squire RTE', function () {
function selectAll(editor) { function selectAll(editor) {
var range = doc.createRange(); var range = doc.createRange();
range.setStartBefore(doc.body.childNodes.item(0)); range.setStart(doc.body.childNodes.item(0), 0);
range.setEndAfter(doc.body.childNodes.item(0)); range.setEnd(doc.body.childNodes.item(0), doc.body.childNodes.item(0).childNodes.length);
editor.setSelection(range); editor.setSelection(range);
} }
describe('removeAllFormatting()', function () { describe('removeAllFormatting', function () {
// Trivial cases // Trivial cases
it('removes inline styles', function () { it('removes inline styles', function () {
var startHTML = '<div><i>one</i> <b>two</b> <u>three</u> <sub>four</sub> <sup>five</sup><br></div>'; var startHTML = '<div><i>one</i> <b>two</b> <u>three</u> <sub>four</sub> <sup>five</sup></div>';
editor.setHTML(startHTML); editor.setHTML(startHTML);
expect(editor, 'to contain HTML', startHTML); expect(editor, 'to contain HTML', startHTML);
selectAll(editor); selectAll(editor);
editor.removeAllFormatting(); editor.removeAllFormatting();
expect(editor, 'to contain HTML', '<div><br>one two three four five</div>'); expect(editor, 'to contain HTML', '<div>one two three four five</div>');
}); });
it('removes block styles', function () { it('removes block styles', function () {
var startHTML = '<div><blockquote>one<br></blockquote><ul><li>two<br></li></ul>' + var startHTML = '<div><blockquote>one</blockquote><ul><li>two</li></ul>' +
'<ol><li>three<br></li></ol><table><tbody><tr><th>four<br></th><td>five<br></td></tr></tbody></table></div>'; '<ol><li>three</li></ol><table><tbody><tr><th>four</th><td>five</td></tr></tbody></table></div>';
editor.setHTML(startHTML); editor.setHTML(startHTML);
expect(editor, 'to contain HTML', startHTML); expect(editor, 'to contain HTML', startHTML);
selectAll(editor); selectAll(editor);
editor.removeAllFormatting(); editor.removeAllFormatting();
expect(editor, 'to contain HTML', '<div><br>one</div><div><br>two</div><div><br>three</div><div><br>four</div><div><br>five</div>'); var expectedHTML = '<div><div>one</div><div>two</div><div>three</div><div>four</div><div>five</div></div>';
expect(editor, 'to contain HTML', expectedHTML);
}); });
// Potential bugs // Potential bugs
it('removes styles that begin inside the range', function () { it('removes styles that begin inside the range', function () {
var startHTML = '<div>one <i>two three four five</i><br></div>'; var startHTML = '<div>one <i>two three four five</i></div>';
editor.setHTML(startHTML); editor.setHTML(startHTML);
expect(editor, 'to contain HTML', startHTML); expect(editor, 'to contain HTML', startHTML);
var range = doc.createRange(); var range = doc.createRange();
range.setStart(doc.body.childNodes.item(0), 0); range.setStart(doc.body.childNodes.item(0), 0);
range.setEnd(doc.getElementsByTagName('i').item(0).childNodes.item(0), 4); range.setEnd(doc.getElementsByTagName('i').item(0).childNodes.item(0), 4);
editor.removeAllFormatting(range); editor.removeAllFormatting(range);
expect(editor, 'to contain HTML', '<div>one two <i>three four five</i><br></div>'); expect(editor, 'to contain HTML', '<div>one two <i>three four five</i></div>');
}); });
it('removes styles that end inside the range', function () { it('removes styles that end inside the range', function () {
var startHTML = '<div><i>one two three four</i> five<br></div>'; var startHTML = '<div><i>one two three four</i> five</div>';
editor.setHTML(startHTML); editor.setHTML(startHTML);
expect(editor, 'to contain HTML', startHTML); expect(editor, 'to contain HTML', startHTML);
var range = doc.createRange(); var range = doc.createRange();
@ -74,7 +77,7 @@ describe('Squire RTE', function () {
}); });
it('removes styles enclosed by the range', function () { it('removes styles enclosed by the range', function () {
var startHTML = '<div>one <i>two three four</i> five<br></div>'; var startHTML = '<div>one <i>two three four</i> five</div>';
editor.setHTML(startHTML); editor.setHTML(startHTML);
expect(editor, 'to contain HTML', startHTML); expect(editor, 'to contain HTML', startHTML);
var range = doc.createRange(); var range = doc.createRange();
@ -85,34 +88,34 @@ describe('Squire RTE', function () {
}); });
it('removes styles enclosing the range', function () { it('removes styles enclosing the range', function () {
var startHTML = '<div><i>one two three four five</i><br></div>'; var startHTML = '<div><i>one two three four five</i></div>';
editor.setHTML(startHTML); editor.setHTML(startHTML);
expect(editor, 'to contain HTML', startHTML); expect(editor, 'to contain HTML', startHTML);
var range = doc.createRange(); var range = doc.createRange();
range.setStart(doc.getElementsByTagName('i').item(0).childNodes.item(0), 4); range.setStart(doc.getElementsByTagName('i').item(0).childNodes.item(0), 4);
range.setEnd(doc.getElementsByTagName('i').item(0).childNodes.item(0), 18); range.setEnd(doc.getElementsByTagName('i').item(0).childNodes.item(0), 18);
editor.removeAllFormatting(range); editor.removeAllFormatting(range);
expect(editor, 'to contain HTML', '<div><i>one </i>two three four<i> five</i><br></div>'); expect(editor, 'to contain HTML', '<div><i>one </i>two three four<i> five</i></div>');
}); });
it('removes nested styles and closes tags correctly', function () { it('removes nested styles and closes tags correctly', function () {
var startHTML = '<table><tbody><tr><td>one<br></td></tr><tr><td>two<br></td><td>three<br></td></tr><tr><td>four<br></td><td>five<br></td></tr></tbody></table>'; var startHTML = '<table><tbody><tr><td>one</td></tr><tr><td>two</td><td>three</td></tr><tr><td>four</td><td>five</td></tr></tbody></table>';
editor.setHTML(startHTML); editor.setHTML(startHTML);
expect(editor, 'to contain HTML', startHTML); expect(editor, 'to contain HTML', startHTML);
var range = doc.createRange(); var range = doc.createRange();
range.setStart(doc.getElementsByTagName('td').item(1), 0); range.setStart(doc.getElementsByTagName('td').item(1), 0);
range.setEnd(doc.getElementsByTagName('td').item(2), doc.getElementsByTagName('td').item(2).childNodes.length); range.setEnd(doc.getElementsByTagName('td').item(2), doc.getElementsByTagName('td').item(2).childNodes.length);
editor.removeAllFormatting(range); editor.removeAllFormatting(range);
expect(editor, 'to contain HTML', '<table><tbody><tr><td>one<br></td></tr></tbody></table>' + expect(editor, 'to contain HTML', '<table><tbody><tr><td>one</td></tr></tbody></table>' +
'<div><br>two</div>' + '<div>two</div>' +
'<div><br>three</div>' + '<div>three</div>' +
'<table><tbody><tr><td>four<br></td><td>five<br></td></tr></tbody></table>'); '<table><tbody><tr><td>four</td><td>five</td></tr></tbody></table>');
}); });
}); });
afterEach(function () { afterEach(function () {
editor = null; editor = null;
var iframe = document.getElementById('testFrame'); var iframe = document.getElementById('testFrame');
iframe.src = 'about:blank'; iframe.src = 'blank.html';
}); });
}); });