WIP: Note editing, markdown to html
[oweals/karmaworld.git] / karmaworld / apps / wysihtml5 / static / wysihtml5 / wysihtml-0.4.17 / test / quirks / clean_pasted_html_test.js
1 if (wysihtml5.browser.supported()) {
2   module("wysihtml5.quirks.cleanPastedHTML", {
3     setup: function() {
4       this.refNode = document.createElement("div");
5       this.refNode.style.fontSize = "24px";
6       this.refNode.style.color = "rgba(0,0,0)";
7       this.uneditableClass = "wysihtml5-uneditable-container";
8     },
9
10     teardown: function() {
11
12     }
13
14   });
15
16   test("Basic test", function(assert) {
17     var rules = {
18       tags: {
19         "u": {},
20         "a": {
21           "check_attributes": {
22             "href": "href",
23             "rel": "any",
24             "target": "any"
25           }
26         },
27         "b": {}
28       },
29       selectors: {
30         "a u": "unwrap"
31       }
32     };
33
34     var options = {
35       "referenceNode": this.refNode,
36       "rules": [{"set":rules}],
37       "uneditableClass": this.uneditableClass
38     };
39
40     assert.htmlEqual(
41       wysihtml5.quirks.cleanPastedHTML("<u>See: </u><a href=\"http://www.google.com\"><u><b>best search engine</b></u></a>", options),
42       "<u>See: </u><a href=\"http://www.google.com\"><b>best search engine</b></a>",
43       "Correctly removed <u> within <a>"
44     );
45   });
46
47   test("Non-breakable space test", function(assert) {
48     var options = {
49       "referenceNode": this.refNode,
50       "rules": [{"set": {}}],
51       "uneditableClass": this.uneditableClass
52     };
53
54     assert.htmlEqual(
55       wysihtml5.quirks.cleanPastedHTML("test&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;", options),
56       "test &nbsp; &nbsp; ",
57       "Correctly split nonbreakable spaces"
58     );
59   });
60
61   test("Ruleset picking tests", function(assert) {
62     var options = {
63       "referenceNode": this.refNode,
64       "rules": [
65         {
66           "condition": /class="?Mso/i,
67           "set": {
68             "tags": {
69             }
70           }
71         },
72         {
73           "set": {
74             "classes": "any",
75             "comments": 1,
76             "tags": {
77               "p": {},
78               "span": {}
79             }
80           }
81         }
82       ],
83       "uneditableClass": this.uneditableClass
84     };
85
86     assert.htmlEqual(
87       wysihtml5.quirks.cleanPastedHTML('<p class="MsoNormal">test</p>', options),
88       "test",
89       "Picked correctly to first ruleset"
90     );
91     assert.htmlEqual(
92       wysihtml5.quirks.cleanPastedHTML('<p class="MsoNormal">test<!-- secret comment here --></p>', options),
93       "test",
94       "First ruleset removes comments correctly"
95     );
96
97
98     assert.htmlEqual(
99       wysihtml5.quirks.cleanPastedHTML('<p class="SomeOtherClass">test</p>', options),
100       '<p class="SomeOtherClass">test</p>',
101       "Picked correctly to second ruleset"
102     );
103     assert.htmlEqual(
104       wysihtml5.quirks.cleanPastedHTML('<p class="SomeOtherClass">test<!-- secret comment here --></p>', options),
105       '<p class="SomeOtherClass">test<!-- secret comment here --></p>',
106       "Second ruleset keeps comments correctly"
107     );
108   });
109
110   test("Root color and font-size removal tests", function(assert) {
111     var options = {
112       "referenceNode": this.refNode,
113       "rules": [{"set": {
114         "tags": {
115           "span": {
116             "keep_styles": {
117               "color": 1,
118               "fontSize": 1
119             }
120           }
121         }
122       }}],
123       "uneditableClass": this.uneditableClass
124     };
125
126     assert.htmlEqual(
127       wysihtml5.quirks.cleanPastedHTML('<span style="color:rgba(0,0,0);font-size:24px;">test</span>', options),
128       'test',
129       "Correctly removed defult styles"
130     );
131
132     assert.htmlEqual(
133       wysihtml5.quirks.cleanPastedHTML('<span style="color:rgb(1,2,3);">test</span>', options),
134       '<span style="color:rgb(1,2,3);">test</span>',
135       "Correctly kept different style"
136     );
137
138     assert.htmlEqual(
139       wysihtml5.quirks.cleanPastedHTML('<span style="color:rgb(1,2,3); font-size: 24px;">test</span>', options),
140       '<span style="color:rgb(1,2,3);">test</span>',
141       "Correctly moved one and kept another"
142     );
143
144     assert.htmlEqual(
145       wysihtml5.quirks.cleanPastedHTML('<span style="color:rgb(1,2,3); font-size: 35px;">test</span>', options),
146       '<span style="color:rgb(1,2,3); font-size: 35px;">test</span>',
147       "Correctly kept all styles"
148     );
149   });
150
151
152 }