module("wysihtml5.dom.autoLink", {
equal: function(actual, expected, message) {
return QUnit.assert.htmlEqual(actual, expected, message);
},
autoLink: function(html) {
var container = wysihtml5.dom.getAsDom(html);
return wysihtml5.dom.autoLink(container).innerHTML;
}
});
test("Basic test", function() {
ok(wysihtml5.dom.autoLink.URL_REG_EXP, "URL reg exp is revealed to be access globally");
this.equal(
this.autoLink("hey check out this search engine http://www.google.com"),
"hey check out this search engine http://www.google.com",
"Urls starting with http:// are correctly linked"
);
this.equal(
this.autoLink("hey check out this search engine https://www.google.com"),
"hey check out this search engine https://www.google.com",
"Urls starting with https:// are correctly linked"
);
this.equal(
this.autoLink("hey check out this search engine www.google.com"),
"hey check out this search engine www.google.com",
"Urls starting with www. are correctly linked"
);
this.equal(
this.autoLink("hey check out this mail christopher.blum@xing.com"),
"hey check out this mail christopher.blum@xing.com",
"E-Mails are not linked"
);
this.equal(
this.autoLink("http://google.de"),
"http://google.de",
"Single url without www. but with http:// is auto linked"
);
this.equal(
this.autoLink("hey check out this search engine www.google.com"),
"hey check out this search engine www.google.com",
"Already auto-linked stuff isn't causing a relinking"
);
this.equal(
this.autoLink("hey check out this search engine http://www.google.com"),
"hey check out this search engine http://www.google.com",
"Urls inside 'code' elements are not auto linked"
);
this.equal(
this.autoLink("hey check out this search engine
http://www.google.com"), "hey check out this search engine
http://www.google.com", "Urls inside 'pre' elements are not auto linked" ); this.equal( this.autoLink("hey check out this search engine (http://www.google.com)"), "hey check out this search engine (http://www.google.com)", "Parenthesis around url are not part of url #1" ); this.equal( this.autoLink("hey check out this search engine (http://www.google.com?q=hello(spencer))"), "hey check out this search engine (http://www.google.com?q=hello(spencer))", "Parenthesis around url are not part of url #2" ); this.equal( this.autoLink("hey check out this search engine http://www.google.com?q=hello(spencer)"), "hey check out this search engine http://www.google.com?q=hello(spencer)", "Urls in tags are correctly auto linked" ); this.equal( this.autoLink("http://google.de and http://yahoo.com as well as http://de.finance.yahoo.com http://google.com"), "http://google.de and http://yahoo.com as well as http://de.finance.yahoo.com http://google.com", "Multiple urls are correctly auto linked" ); this.equal( this.autoLink(""), "", "Urls in SCRIPT elements are not touched" ); this.equal( this.autoLink(""), "", "Urls in SCRIPT elements are not touched" ); this.equal( this.autoLink(" http://www.google.de"), " http://www.google.de", "Check if white space in front of url is preserved" ); this.equal( this.autoLink("<b>foo</b> http://www.google.de"), "<b>foo</b> http://www.google.de", "Check if plain HTML markup isn't evaluated" ); });