WIP: Note editing, markdown to html
[oweals/karmaworld.git] / karmaworld / apps / wysihtml5 / static / wysihtml5 / wysihtml-0.4.17 / test / dom / auto_link_test.js
1 module("wysihtml5.dom.autoLink", {
2   equal: function(actual, expected, message) {
3     return QUnit.assert.htmlEqual(actual, expected, message);
4   },
5   
6   autoLink: function(html) {
7     var container = wysihtml5.dom.getAsDom(html);
8     return wysihtml5.dom.autoLink(container).innerHTML;
9   } 
10 });
11
12
13 test("Basic test", function() {
14   ok(wysihtml5.dom.autoLink.URL_REG_EXP, "URL reg exp is revealed to be access globally");
15   
16   this.equal(
17     this.autoLink("hey check out this search engine http://www.google.com"),
18     "hey check out this search engine <a href=\"http://www.google.com\">http://www.google.com</a>",
19     "Urls starting with http:// are correctly linked"
20   );
21   
22   this.equal(
23     this.autoLink("hey check out this search engine https://www.google.com"),
24     "hey check out this search engine <a href=\"https://www.google.com\">https://www.google.com</a>",
25     "Urls starting with https:// are correctly linked"
26   );
27   
28   this.equal(
29     this.autoLink("hey check out this search engine www.google.com"),
30     "hey check out this search engine <a href=\"http://www.google.com\">www.google.com</a>",
31     "Urls starting with www. are correctly linked"
32   );
33   
34   this.equal(
35     this.autoLink("hey check out this mail christopher.blum@xing.com"),
36     "hey check out this mail christopher.blum@xing.com",
37     "E-Mails are not linked"
38   );
39   
40   this.equal(
41     this.autoLink("http://google.de"),
42     "<a href=\"http://google.de\">http://google.de</a>",
43     "Single url without www. but with http:// is auto linked"
44   );
45   
46   this.equal(
47     this.autoLink("hey check out this search engine <a href=\"http://www.google.com\">www.google.com</a>"),
48     "hey check out this search engine <a href=\"http://www.google.com\">www.google.com</a>",
49     "Already auto-linked stuff isn't causing a relinking"
50   );
51   
52   this.equal(
53     this.autoLink("hey check out this search engine <code><span>http://www.google.com</span></code>"),
54     "hey check out this search engine <code><span>http://www.google.com</span></code>",
55     "Urls inside 'code' elements are not auto linked"
56   );
57   
58   this.equal(
59     this.autoLink("hey check out this search engine <pre>http://www.google.com</pre>"),
60     "hey check out this search engine <pre>http://www.google.com</pre>",
61     "Urls inside 'pre' elements are not auto linked"
62   );
63   
64   this.equal(
65     this.autoLink("hey check out this search engine (http://www.google.com)"),
66     "hey check out this search engine (<a href=\"http://www.google.com\">http://www.google.com</a>)",
67     "Parenthesis around url are not part of url #1"
68   );
69   
70   this.equal(
71     this.autoLink("hey check out this search engine (http://www.google.com?q=hello(spencer))"),
72     "hey check out this search engine (<a href=\"http://www.google.com?q=hello(spencer)\">http://www.google.com?q=hello(spencer)</a>)",
73     "Parenthesis around url are not part of url #2"
74   );
75   
76   this.equal(
77     this.autoLink("hey check out this search engine <span>http://www.google.com?q=hello(spencer)</span>"),
78     "hey check out this search engine <span><a href=\"http://www.google.com?q=hello(spencer)\">http://www.google.com?q=hello(spencer)</a></span>",
79     "Urls in tags are correctly auto linked"
80   );
81   
82   this.equal(
83     this.autoLink("http://google.de and http://yahoo.com as well as <span>http://de.finance.yahoo.com</span> <a href=\"http://google.com\" class=\"more\">http://google.com</a>"),
84     "<a href=\"http://google.de\">http://google.de</a> and <a href=\"http://yahoo.com\">http://yahoo.com</a> as well as <span><a href=\"http://de.finance.yahoo.com\">http://de.finance.yahoo.com</a></span> <a href=\"http://google.com\" class=\"more\">http://google.com</a>",
85     "Multiple urls are correctly auto linked"
86   );
87   
88   this.equal(
89     this.autoLink("<script>http://google.de</script>"),
90     "<script>http://google.de</script>",
91     "Urls in SCRIPT elements are not touched"
92   );
93   
94   this.equal(
95     this.autoLink("<script>http://google.de</script>"),
96     "<script>http://google.de</script>",
97     "Urls in SCRIPT elements are not touched"
98   );
99   
100   this.equal(
101     this.autoLink(" http://www.google.de"),
102     " <a href=\"http://www.google.de\">http://www.google.de</a>",
103     "Check if white space in front of url is preserved"
104   );
105   
106   this.equal(
107     this.autoLink("&lt;b&gt;foo&lt;/b&gt; http://www.google.de"),
108     "&lt;b&gt;foo&lt;/b&gt; <a href=\"http://www.google.de\">http://www.google.de</a>",
109     "Check if plain HTML markup isn't evaluated"
110   );
111 });