Debian Codegraph @

extensions/WikiEditor/tests/qunit/ext.wikiEditor.toolbar.test.js

raw symbols SCIP
1 QUnit.module( 'ext.wikiEditor.toolbar', function ( hooks ) {
2 hooks.beforeEach( function () {
3 var $target = $( '<textarea>' )
4 .attr( 'id', 'wpTextBox1' )
5 .appendTo( '#qunit-fixture' );
6 this.$target = $target;
7 $target.wikiEditor( 'addModule', 'toolbar' );
8 this.$ui = $target.data( 'wikiEditor-context' ).$ui;
9 } );
10
11 QUnit.test( 'Toolbars', function ( assert ) {
12 // Add toolbar section
13 var data = {
14 sections: {
15 emoticons: {
16 type: 'toolbar',
17 label: 'Emoticons'
18 }
19 }
20 };
21 assert.strictEqual( this.$ui.find( '*[rel="emoticons"].section' ).length, 0, 'Before adding toolbar section' );
22 this.$target.wikiEditor( 'addToToolbar', data );
23 assert.strictEqual( this.$ui.find( '*[rel="emoticons"].section' ).length, 1, 'After adding toolbar section' );
24
25 // Add toolbar group
26 data = {
27 section: 'emoticons',
28 groups: {
29 faces: {
30 label: 'Faces'
31 }
32 }
33 };
34 assert.strictEqual( this.$ui.find( '*[rel="emoticons"].section *[rel="faces"].group' ).length, 0, 'Before adding toolbar group' );
35 this.$target.wikiEditor( 'addToToolbar', data );
36 assert.strictEqual( this.$ui.find( '*[rel="emoticons"].section *[rel="faces"].group' ).length, 1, 'After adding toolbar group' );
37
38 // Add button tool
39 data = {
40 section: 'emoticons',
41 group: 'faces',
42 tools: {
43 smile: {
44 label: 'Smile!',
45 type: 'button',
46 icon: 'http://upload.wikimedia.org/wikipedia/commons/thumb/a/a4/Gnome-face-smile.svg/22px-Gnome-face-smile.svg.png',
47 action: {
48 type: 'encapsulate',
49 options: {
50 pre: ':)'
51 }
52 }
53 }
54 }
55 };
56 assert.strictEqual( this.$ui.find( '*[rel="emoticons"].section *[rel="faces"].group *[rel="smile"].tool' ).length, 0, 'Before adding button' );
57 this.$target.wikiEditor( 'addToToolbar', data );
58 assert.strictEqual( this.$ui.find( '*[rel="emoticons"].section *[rel="faces"].group *[rel="smile"].tool' ).length, 1, 'After adding button' );
59
60 // Remove button tool
61 data = {
62 section: 'emoticons',
63 group: 'faces',
64 tool: 'smile'
65 };
66 assert.strictEqual( this.$ui.find( '*[rel="emoticons"].section *[rel="faces"].group *[rel="smile"].tool' ).length, 1, 'Before removing button' );
67 this.$target.wikiEditor( 'removeFromToolbar', data );
68 assert.strictEqual( this.$ui.find( '*[rel="emoticons"].section *[rel="faces"].group *[rel="smile"].tool' ).length, 0, 'After removing button' );
69
70 // Add select tool
71 data = {
72 section: 'emoticons',
73 group: 'faces',
74 tools: {
75 icons: {
76 label: 'Icons',
77 type: 'select',
78 list: {
79 wink: {
80 label: 'Wink',
81 action: {
82 type: 'encapsulate',
83 options: {
84 pre: ';)'
85 }
86 }
87 },
88 frown: {
89 label: 'Frown',
90 action: {
91 type: 'encapsulate',
92 options: {
93 pre: ':('
94 }
95 }
96 },
97 bigSmile: {
98 label: 'Big smile',
99 action: {
100 type: 'encapsulate',
101 options: {
102 pre: ':D'
103 }
104 }
105 }
106 }
107 }
108 }
109 };
110 assert.strictEqual( this.$ui.find( '*[rel="emoticons"].section *[rel="faces"].group *[rel="icons"].tool' ).length, 0, 'Before adding select' );
111 this.$target.wikiEditor( 'addToToolbar', data );
112 assert.strictEqual( this.$ui.find( '*[rel="emoticons"].section *[rel="faces"].group *[rel="icons"].tool' ).length, 1, 'After adding select' );
113
114 // Remove select tool
115 data = {
116 section: 'emoticons',
117 group: 'faces',
118 tool: 'icons'
119 };
120 assert.strictEqual( this.$ui.find( '*[rel="emoticons"].section *[rel="faces"].group *[rel="icons"].tool' ).length, 1, 'Before removing select' );
121 this.$target.wikiEditor( 'removeFromToolbar', data );
122 assert.strictEqual( this.$ui.find( '*[rel="emoticons"].section *[rel="faces"].group *[rel="icons"].tool' ).length, 0, 'After removing select' );
123
124 // Remove toolbar group
125 data = {
126 section: 'emoticons',
127 group: 'faces'
128 };
129 assert.strictEqual( this.$ui.find( '*[rel="emoticons"].section *[rel="faces"].group' ).length, 1, 'Before removing toolbar group' );
130 this.$target.wikiEditor( 'removeFromToolbar', data );
131 assert.strictEqual( this.$ui.find( '*[rel="emoticons"].section *[rel="faces"].group' ).length, 0, 'After removing toolbar group' );
132
133 // Remove toolbar section
134 data = {
135 section: 'emoticons'
136 };
137 assert.strictEqual( this.$ui.find( '*[rel="emoticons"].section' ).length, 1, 'Before removing toolbar section' );
138 this.$target.wikiEditor( 'removeFromToolbar', data );
139 assert.strictEqual( this.$ui.find( '*[rel="emoticons"].section' ).length, 0, 'After removing toolbar section' );
140 } );
141
142 QUnit.test( 'Booklets', function ( assert ) {
143 // Add booklet section
144 var data = {
145 sections: {
146 info: {
147 type: 'booklet',
148 label: 'Info'
149 }
150 }
151 };
152 assert.strictEqual( this.$ui.find( '*[rel="info"].section' ).length, 0, 'Before adding booklet section' );
153 this.$target.wikiEditor( 'addToToolbar', data );
154 assert.strictEqual( this.$ui.find( '*[rel="info"].section' ).length, 1, 'After adding booklet section' );
155
156 // Add table page
157 data = {
158 section: 'info',
159 pages: {
160 colors: {
161 layout: 'table',
162 label: 'Colors',
163 headings: [
164 { text: 'Name' },
165 { text: 'Temperature' },
166 { text: 'Swatch' }
167 ]
168 }
169 }
170 };
171 assert.strictEqual( this.$ui.find( '*[rel="info"].section *[rel="colors"].page' ).length, 0, 'Before adding table page' );
172 this.$target.wikiEditor( 'addToToolbar', data );
173 assert.strictEqual( this.$ui.find( '*[rel="info"].section *[rel="colors"].page' ).length, 1, 'After adding table page' );
174
175 // Add table rows
176 data = {
177 section: 'info',
178 page: 'colors',
179 rows: [
180 {
181 name: { text: 'Red' },
182 temp: { text: 'Warm' },
183 swatch: { html: '<div style="width: 10px; height: 10px; background-color: red;">' }
184 },
185 {
186 name: { text: 'Blue' },
187 temp: { text: 'Cold' },
188 swatch: { html: '<div style="width: 10px; height: 10px; background-color: blue;">' }
189 },
190 {
191 name: { text: 'Silver' },
192 temp: { text: 'Neutral' },
193 swatch: { html: '<div style="width: 10px; height: 10px; background-color: silver;">' }
194 }
195 ]
196 };
197 assert.strictEqual( this.$ui.find( '*[rel="info"].section *[rel="colors"].page tr td' ).length, 0, 'Before adding table rows' );
198 this.$target.wikiEditor( 'addToToolbar', data );
199 assert.strictEqual( this.$ui.find( '*[rel="info"].section *[rel="colors"].page tr td' ).length, 9, 'After adding table rows' );
200
201 // Remove table row
202 data = {
203 section: 'info',
204 page: 'colors',
205 row: 0
206 };
207 assert.strictEqual( this.$ui.find( '*[rel="info"].section *[rel="colors"].page tr td' ).length, 9, 'Before removing table row' );
208 this.$target.wikiEditor( 'removeFromToolbar', data );
209 assert.strictEqual( this.$ui.find( '*[rel="info"].section *[rel="colors"].page tr td' ).length, 6, 'After removing table row' );
210
211 // Remove table page
212 data = {
213 section: 'info',
214 page: 'colors'
215 };
216 assert.strictEqual( this.$ui.find( '*[rel="info"].section *[rel="colors"].page' ).length, 1, 'Before removing table page' );
217 this.$target.wikiEditor( 'removeFromToolbar', data );
218 assert.strictEqual( this.$ui.find( '*[rel="info"].section *[rel="colors"].page' ).length, 0, 'After removing table page' );
219
220 // Add character page
221 data = {
222 section: 'info',
223 pages: {
224 emoticons: {
225 layout: 'characters',
226 label: 'Emoticons'
227 }
228 }
229 };
230 assert.strictEqual( this.$ui.find( '*[rel="info"].section *[rel="emoticons"].page' ).length, 0, 'Before adding character page' );
231 this.$target.wikiEditor( 'addToToolbar', data );
232 assert.strictEqual( this.$ui.find( '*[rel="info"].section *[rel="emoticons"].page' ).length, 1, 'After adding character page' );
233
234 // Add characters
235 data = {
236 section: 'info',
237 page: 'emoticons',
238 characters: [
239 ':)', ':))', ':(', '<3', ';)',
240 {
241 label: ':-s',
242 title: 'unsure-face',
243 action: {
244 type: 'replace',
245 options: {
246 peri: ':-s',
247 selectPeri: false
248 }
249 }
250 } ]
251 };
252 assert.strictEqual( this.$ui.find( '*[rel="info"].section *[rel="emoticons"].page *[rel=":))"]' ).length, 0, 'Before adding characters' );
253 this.$target.wikiEditor( 'addToToolbar', data );
254 assert.strictEqual( this.$ui.find( '*[rel="info"].section *[rel="emoticons"].page *[rel=":))"]' ).length, 1, 'After adding characters' );
255 assert.strictEqual( this.$ui.find( '*[rel="info"].section *[rel="emoticons"].page *[title="unsure-face"]' ).length, 1, 'After adding characters find the set title' );
256
257 // Remove character
258 data = {
259 section: 'info',
260 page: 'emoticons',
261 character: ':))'
262 };
263 assert.strictEqual( this.$ui.find( '*[rel="info"].section *[rel="emoticons"].page *[rel=":))"]' ).length, 1, 'Before removing character' );
264 this.$target.wikiEditor( 'removeFromToolbar', data );
265 assert.strictEqual( this.$ui.find( '*[rel="info"].section *[rel="emoticons"].page *[rel=":))"]' ).length, 0, 'After removing character' );
266
267 // Remove character page
268 data = {
269 section: 'info',
270 page: 'emoticons'
271 };
272 assert.strictEqual( this.$ui.find( '*[rel="info"].section *[rel="emoticons"].page' ).length, 1, 'Before removing character page' );
273 this.$target.wikiEditor( 'removeFromToolbar', data );
274 assert.strictEqual( this.$ui.find( '*[rel="info"].section *[rel="emoticons"].page' ).length, 0, 'After removing character page' );
275
276 // Remove booklet section
277 data = {
278 section: 'info'
279 };
280 assert.strictEqual( this.$ui.find( '*[rel="info"].section' ).length, 1, 'Before removing booklet section' );
281 this.$target.wikiEditor( 'removeFromToolbar', data );
282 assert.strictEqual( this.$ui.find( '*[rel="info"].section' ).length, 0, 'After removing booklet section' );
283 } );
284
285 } );