Skip to content

Commit

Permalink
Updated tests to wysihtml5 0.4.9. Fixes #57
Browse files Browse the repository at this point in the history
  • Loading branch information
Waxolunist committed Jun 23, 2014
1 parent 137bf14 commit 852e4e0
Show file tree
Hide file tree
Showing 9 changed files with 234 additions and 25 deletions.
71 changes: 71 additions & 0 deletions test/dom/dom_node_test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
module("wysihtml5.dom.domNode", {
setup: function() {
this.container = document.createElement("div");
}
});

test("Simple .prev() test", function() {
this.container.innerHTML = "<span></span><div></div>";
var lastItem = this.container.querySelector("div"),
firstItem = this.container.querySelector("span");
equal(wysihtml5.dom.domNode(lastItem).prev(), firstItem);
});

test(".prev() test with textnode in between", function() {
this.container.innerHTML = "<span></span> confusing text node <div></div>";
var lastItem = this.container.querySelector("div"),
firstItem = this.container.querySelector("span");
equal(wysihtml5.dom.domNode(lastItem).prev({nodeTypes: [1]}), firstItem);
});

test(".prev() test if no prev element exists", function() {
this.container.innerHTML = "<div></div>";
var lastItem = this.container.querySelector("div");
equal(wysihtml5.dom.domNode(lastItem).prev(), null);
});

test(".prev() test if no prev element exists with textnode", function() {
this.container.innerHTML = "confusing text node <div></div>";
var lastItem = this.container.querySelector("div");
equal(wysihtml5.dom.domNode(lastItem).prev({nodeTypes: [1]}), null);
});

test(".prev() test with empty textnode in between and ignoreBlankTexts", function() {
this.container.innerHTML = "<span></span> <div></div>";
var lastItem = this.container.querySelector("div"),
firstItem = this.container.querySelector("span");
equal(wysihtml5.dom.domNode(lastItem).prev({ignoreBlankTexts: true}), firstItem);
});

test("Simple .next() test", function() {
this.container.innerHTML = "<div></div><span></span>";
var firstItem = this.container.querySelector("div"),
lastItem = this.container.querySelector("span");
equal(wysihtml5.dom.domNode(firstItem).next(), lastItem);
});

test(".next() test with textnode in between", function() {
this.container.innerHTML = "<div></div> confusing text node <span></span>";
var firstItem = this.container.querySelector("div"),
lastItem = this.container.querySelector("span");
equal(wysihtml5.dom.domNode(firstItem).next({nodeTypes: [1]}), lastItem);
});

test(".next() test if no next element exists", function() {
this.container.innerHTML = "<div></div>";
var lastItem = this.container.querySelector("div");
equal(wysihtml5.dom.domNode(lastItem).next(), null);
});

test(".next() test if no next element exists with textnode", function() {
this.container.innerHTML = "<div></div> confusing text node ";
var lastItem = this.container.querySelector("div");
equal(wysihtml5.dom.domNode(lastItem).next({nodeTypes: [1]}), null);
});

test(".next() test with empty textnode in between and ignoreBlankTexts", function() {
this.container.innerHTML = "<div></div> <span></span>";
var firstItem = this.container.querySelector("div"),
lastItem = this.container.querySelector("span");
equal(wysihtml5.dom.domNode(firstItem).next({ignoreBlankTexts: true}), lastItem);
});
18 changes: 17 additions & 1 deletion test/dom/get_parent_element_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,4 +158,20 @@ test("Test - with only a classRegExp", function() {
classRegExp: /wysiwyg-text-align-[a-z]+/g
});
equal(result, alignedDiv);
});
});

test("Test with parent container limit", function() {
this.container.innerHTML = '<div><div><p><span>foo</span></p></div></div>';

var spanElement = this.container.querySelector("span"),
limitEl = this.container.querySelector("p"),
nestedDiv = this.container.querySelector("div").querySelector("div"),
result;

result = wysihtml5.dom.getParentElement(spanElement, {
nodeName: "DIV"
}, false, limitEl);

equal(result, null);
});

50 changes: 50 additions & 0 deletions test/dom/parse_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -747,4 +747,54 @@ if (wysihtml5.browser.supported()) {
this.equal(this.sanitize(input_valid, rules), input_valid, "Valid image is kept");
this.equal(this.sanitize(input_valid_2, rules), input_valid_2, "Valid image is kept2");
});

test("Test valid type definition visible_content_object ", function() {
var rules = {
"type_definitions": {
"visible_content_object": {
"methods": {
"has_visible_contet": 1
}
},
},
"tags": {
'div': {
"one_of_type": {
"visible_content_object": 1
},
"remove_action": "unwrap",
"check_attributes": {
"style": "any"
}
},
'img': {
"check_attributes": {
"src": "any"
}
},
'span': {}
}
},
input1 = '<div></div>',
input2 = '<div> <span> </span> </div>',
input3 = '<div><img src="pic.jpg"/></div>',
input4 = '<div>test</div>',
input5 = '<div style="width: 10px; height: 10px;"> <span> </span> </div>',
tester = document.createElement('div');

this.equal(this.sanitize(input1, rules), "", "Empty DIV gets removed");
this.equal(this.sanitize(input2, rules), " <span> </span> ", "DIV with no textual content gets unwrapped");

this.equal(this.sanitize(input3, rules), input3, "DIV with img inside is kept");
this.equal(this.sanitize(input4, rules), input4, "DIV with textual content is kept");

document.body.appendChild(tester);

tester.innerHTML = input2;
this.equal(this.sanitize(tester, rules).innerHTML, " <span> </span> ", "DIV with no dimesions and in dom gets unwrapped");

tester.innerHTML = input5;
this.equal(this.sanitize(tester, rules).innerHTML, input5 , "DIV with dimensions and in dom is kept");

});
}
14 changes: 14 additions & 0 deletions test/dom/unwrap_test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module("wysihtml5.dom.unwrap", {
setup: function() {
this.inner = "<span>test</span><p>tes2</p>";
this.container = document.createElement("div");
this.containerInner = document.createElement("div");
this.containerInner.innerHTML = this.inner;
this.container.appendChild(this.containerInner);
}
});

test("Basic test", function() {
wysihtml5.dom.unwrap(this.containerInner);
equal(this.container.innerHTML, this.inner, "Unwrapping element works splendid.");
});
70 changes: 64 additions & 6 deletions test/editor_commands_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -277,33 +277,91 @@ if (wysihtml5.browser.supported()) {

// create table
asyncTest("Create lists", function() {
expect(4);
expect(7);
var that = this,
editor = new wysihtml5.Editor(this.editableArea),
text = "";

editor.on("load", function() {
var editableElement = that.editableArea,
expectText = '<ul><li></li></ul>',
expectTextBr = '<ul><li><br></li></ul>',
expectTextWithContents = '<ul><li>text</li></ul>',
expectTextWithContentsBr = '<ul><li>text<br></li></ul>',
expectOrdText = '<ol><li></li></ol>',
expectOrdTextWithContents = '<ol><li>text</li></ol>';
expectOrdTextBr = '<ol><li><br></li></ol>',
expectOrdTextWithContents = '<ol><li>text</li></ol>',
expectOrdTextWithContentsBr = '<ol><li>text<br></li></ol>';

editor.setValue(text, true);
editor.composer.selection.selectNode(editor.editableElement);
editor.composer.commands.exec('insertUnorderedList');
equal(editableElement.innerHTML.toLowerCase(), expectText, "Unordered list created");
ok(editableElement.innerHTML.toLowerCase() == expectText || editableElement.innerHTML.toLowerCase() == expectTextBr, "Unordered list created");

editor.composer.commands.exec('insertHTML', 'text');
equal(editableElement.innerHTML.toLowerCase(), expectTextWithContents, "In unordered list placed caret correctly");
ok(editableElement.innerHTML.toLowerCase() == expectTextWithContents || editableElement.innerHTML.toLowerCase() == expectTextWithContentsBr , "In unordered list placed caret correctly");

editor.setValue(text, true);
editor.composer.selection.selectNode(editor.editableElement);
editor.composer.commands.exec('insertOrderedList');
equal(editableElement.innerHTML.toLowerCase(), expectOrdText, "Ordered list created");
ok(editableElement.innerHTML.toLowerCase() == expectOrdText || editableElement.innerHTML.toLowerCase() == expectOrdTextBr, "Ordered list created");

editor.composer.commands.exec('insertHTML', 'text');
equal(editableElement.innerHTML.toLowerCase(), expectOrdTextWithContents, "In ordered list placed caret correctly");
ok(editableElement.innerHTML.toLowerCase() == expectOrdTextWithContents || editableElement.innerHTML.toLowerCase() == expectOrdTextWithContentsBr, "In ordered list placed caret correctly");

editableElement.innerHTML = '<ul><li>test</li><li class="second">test</li><li>test</li></ul>';
editor.composer.selection.selectNode(editor.editableElement.querySelector('.second'));
editor.composer.commands.exec('indentList');
equal(editableElement.innerHTML.toLowerCase(), '<ul><li>test<ul><li class="second">test</li></ul></li><li>test</li></ul>', "List indent increases level correctly");

editor.composer.commands.exec('outdentList');
equal(editableElement.innerHTML.toLowerCase(), '<ul><li>test</li><li class="second">test</li><li>test</li></ul>', "List outdent decreases level correctly");

editor.composer.commands.exec('outdentList');
equal(editableElement.innerHTML.toLowerCase(), '<ul><li>test</li></ul><br>test<ul><li>test</li></ul>', "List outdent escapes current list item correctly out of list");


start();
});
});


// create blockQuote
asyncTest("Create blockquote", function() {
expect(4);
var that = this,
editor = new wysihtml5.Editor(this.editableArea, {
parserRules: {
tags: {
h1: true,
p: true,
blockquote: true
}
}
}),
text = "<h1>heading</h1><p>text</p>",
text2 = "test<h1>heading</h1>test";

editor.on("load", function() {
var editableElement = that.editableArea;

editor.setValue(text, true);

editor.composer.selection.selectNode(editor.editableElement);
editor.composer.commands.exec('insertBlockQuote');
equal(editableElement.innerHTML.toLowerCase(), "<blockquote>" + text + "</blockquote>" , "Blockquote created with headings and paragraphs preserved.");

editor.composer.commands.exec('insertBlockQuote');
equal(editableElement.innerHTML.toLowerCase(), text, "Blockquote removed with headings and paragraphs preserved.");


editor.setValue(text2, true);
editor.composer.selection.selectNode(editor.editableElement.querySelector('h1'));
editor.composer.commands.exec('insertBlockQuote');
equal(editableElement.innerHTML.toLowerCase(), "test<blockquote><h1>heading</h1></blockquote>test" , "Blockquote created.");

editor.composer.commands.exec('insertBlockQuote');
equal(editableElement.innerHTML.toLowerCase(), "test<br><h1>heading</h1><br>test" , "Blockquote removed and line breaks added.");

start();
});
Expand Down
8 changes: 4 additions & 4 deletions test/editor_contenteditablemode_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,8 @@ if (wysihtml5.browser.supported()) {
equal(composerElement.innerHTML.toLowerCase(), html, "Editor content correctly set after calling 'setValue'");
ok(!editor.isEmpty(), "'isEmpty' returns correct value when the composer element isn't actually empty");

var value = editor.getValue();
equal(value.toLowerCase(), html, "Editor content correctly returned after calling 'getValue'");
var value = editor.getValue(false, false);
equal(value.toLowerCase(), html, "Editor content correctly returned after calling 'getValue(false, false)'");

editor.clear();
value = editor.getValue();
Expand Down Expand Up @@ -224,7 +224,7 @@ if (wysihtml5.browser.supported()) {
equal(editor.config.parserRules, parserRules, "Parser rules correctly set on config object");
// Invoke parsing via second parameter of setValue()
editor.setValue(input, true);
equal(editor.getValue().toLowerCase(), output, "HTML got correctly parsed within setValue()");
equal(editor.getValue(false, false).toLowerCase(), output, "HTML got correctly parsed within setValue()");
start();
});
});
Expand Down Expand Up @@ -283,7 +283,7 @@ if (wysihtml5.browser.supported()) {

// Invoke parsing via second parameter of setValue()
editor.setValue(input, true);
equal(editor.getValue().toLowerCase(), output, "HTML got correctly parsed within setValue()");
equal(editor.getValue(false, false).toLowerCase(), output, "HTML got correctly parsed within setValue()");
start();
});
});
Expand Down
9 changes: 4 additions & 5 deletions test/editor_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -369,8 +369,8 @@ if (wysihtml5.browser.supported()) {
equal(composerElement.innerHTML.toLowerCase(), html, "Editor content correctly set after calling 'setValue'");
ok(!editor.isEmpty(), "'isEmpty' returns correct value when the composer element isn't actually empty");

var value = editor.getValue();
equal(value.toLowerCase(), html, "Editor content correctly returned after calling 'getValue'");
var value = editor.getValue(false, false);
equal(value.toLowerCase(), html, "Editor content correctly returned after calling 'getValue(false, false)'");

editor.clear();
value = editor.getValue();
Expand Down Expand Up @@ -415,7 +415,7 @@ if (wysihtml5.browser.supported()) {
equal(editor.config.parserRules, parserRules, "Parser rules correctly set on config object");
// Invoke parsing via second parameter of setValue()
editor.setValue(input, true);
equal(editor.getValue().toLowerCase(), output, "HTML got correctly parsed within setValue()");
equal(editor.getValue(false, false).toLowerCase(), output, "HTML got correctly parsed within setValue()");
start();
});
});
Expand All @@ -428,7 +428,6 @@ if (wysihtml5.browser.supported()) {
parserRules = { script: undefined },
input = this.textareaElement.value,
output = input;

var editor = new wysihtml5.Editor(this.textareaElement, {
parserRules: parserRules,
parser: function(html, config) {
Expand All @@ -445,7 +444,7 @@ if (wysihtml5.browser.supported()) {

// Invoke parsing via second parameter of setValue()
editor.setValue(input, true);
equal(editor.getValue().toLowerCase(), output, "HTML got correctly parsed within setValue()");
equal(editor.getValue(false, false).toLowerCase(), output, "HTML got correctly parsed within setValue()");

start();
});
Expand Down
3 changes: 2 additions & 1 deletion test/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
'<script src="dom/observe_test.js"><\/script>' +
'<script src="dom/get_as_dom_test.js"><\/script>' +
'<script src="dom/get_parent_element_test.js"><\/script>' +
'<script src="dom/get_next_previous_element.js"><\/script>' +
'<script src="dom/dom_node_test.js"><\/script>' +
'<script src="dom/get_style_test.js"><\/script>' +
'<script src="dom/has_element_with_tag_name_test.js"><\/script>' +
'<script src="dom/has_element_with_class_name_test.js"><\/script>' +
Expand All @@ -53,6 +53,7 @@
'<script src="dom/set_attributes_test.js"><\/script>' +
'<script src="dom/parse_test.js"><\/script>' +
'<script src="dom/table_test.js"><\/script>' +
'<script src="dom/unwrap_test.js"><\/script>' +
'<script src="quirks/clean_pasted_html_test.js"><\/script>' +
'<script src="undo_manager_test.js"><\/script>' +
'<script src="editor_test.js"><\/script>' +
Expand Down
16 changes: 8 additions & 8 deletions test/undo_manager_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,19 +52,19 @@ if (wysihtml5.browser.supportsCommand(document, "insertHTML")) {
editor.setValue("1 2 3 4 5");

that.triggerUndo(editor);
equal(editor.getValue(), "1 2 3 4");
equal(editor.getValue(false, false), "1 2 3 4");
that.triggerRedo(editor);
that.triggerRedo(editor);
equal(editor.getValue(), "1 2 3 4 5");
equal(editor.getValue(false, false), "1 2 3 4 5");
that.triggerUndo(editor);
that.triggerUndo(editor);
equal(editor.getValue(), "1 2 3");
equal(editor.getValue(false, false), "1 2 3");
that.triggerUndo(editor);
that.triggerUndo(editor);
equal(editor.getValue(), "1");
equal(editor.getValue(false, false), "1");
that.triggerUndo(editor);
that.triggerUndo(editor);
equal(editor.getValue(), "1");
equal(editor.getValue(false, false), "1");

start();
});
Expand All @@ -81,12 +81,12 @@ if (wysihtml5.browser.supportsCommand(document, "insertHTML")) {
editor.setValue("<i><b>1</b></i>").fire("beforecommand:composer");

that.triggerUndo(editor);
equal(editor.getValue(), "<b>1</b>");
equal(editor.getValue(false, false), "<b>1</b>");
that.triggerRedo(editor);
equal(editor.getValue(), "<i><b>1</b></i>");
equal(editor.getValue(false, false), "<i><b>1</b></i>");
that.triggerUndo(editor);
that.triggerUndo(editor);
equal(editor.getValue(), "1");
equal(editor.getValue(false, false), "1");

start();
});
Expand Down

0 comments on commit 852e4e0

Please sign in to comment.