summaryrefslogtreecommitdiff
path: root/extensions/WikiEditor/tests/qunit/ext.wikiEditor.toolbar.test.js
blob: 674b5e167c2382481cfb06f0e3756ef62d7c6025 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
( function ( $ ) {
	QUnit.module( 'ext.wikiEditor.toolbar', QUnit.newMwEnvironment( {
		setup: function () {
			var $fixture = $( '#qunit-fixture' );
			var $target = $( '<textarea id="wpTextBox1">' );
			this.$target = $target;
			$fixture.append( $target );
			$target.wikiEditor( 'addModule', 'toolbar' );
			this.$ui = $target.data( 'wikiEditor-context' ).$ui;
		}
	} ) );

	QUnit.test( 'Toolbars', 16, function ( assert ) {
		// Add toolbar section
		var data = {
			sections: {
				emoticons: {
					type: 'toolbar',
					label: 'Emoticons'
				}
			}
		};
		assert.equal( this.$ui.find( '*[rel="emoticons"].section' ).length, 0, 'Before adding toolbar section' );
		this.$target.wikiEditor( 'addToToolbar', data );
		assert.equal( this.$ui.find( '*[rel="emoticons"].section' ).length, 1, 'After adding toolbar section' );

		// Add toolbar group
		data = {
			section: 'emoticons',
			groups: {
				faces: {
					label: 'Faces'
				}
			}
		};
		assert.equal( this.$ui.find( '*[rel="emoticons"].section *[rel="faces"].group' ).length, 0, 'Before adding toolbar group' );
		this.$target.wikiEditor( 'addToToolbar', data );
		assert.equal( this.$ui.find( '*[rel="emoticons"].section *[rel="faces"].group' ).length, 1, 'After adding toolbar group' );

		// Add button tool
		data = {
			section: 'emoticons',
			group: 'faces',
			tools: {
				smile: {
					label: 'Smile!',
					type: 'button',
					icon: 'http://upload.wikimedia.org/wikipedia/commons/thumb/a/a4/Gnome-face-smile.svg/22px-Gnome-face-smile.svg.png',
					action: {
						type: 'encapsulate',
						options: {
							pre: ':)'
						}
					}
				}
			}
		};
		assert.equal( this.$ui.find( '*[rel="emoticons"].section *[rel="faces"].group *[rel="smile"].tool' ).length, 0, 'Before adding button' );
		this.$target.wikiEditor( 'addToToolbar', data );
		assert.equal( this.$ui.find( '*[rel="emoticons"].section *[rel="faces"].group *[rel="smile"].tool' ).length, 1, 'After adding button' );

		// Remove button tool
		data = {
			section: 'emoticons',
			group: 'faces',
			tool: 'smile'
		};
		assert.equal( this.$ui.find( '*[rel="emoticons"].section *[rel="faces"].group *[rel="smile"].tool' ).length, 1, 'Before removing button' );
		this.$target.wikiEditor( 'removeFromToolbar', data );
		assert.equal( this.$ui.find( '*[rel="emoticons"].section *[rel="faces"].group *[rel="smile"].tool' ).length, 0, 'After removing button' );

		// Add select tool
		data = {
			section: 'emoticons',
			group: 'faces',
			tools: {
				icons: {
					label: 'Icons',
					type: 'select',
					list: {
						wink : {
							label: 'Wink',
							action: {
								type: 'encapsulate',
								options: {
									pre: ';)'
								}
							}
						},
						frown : {
							label: 'Frown',
							action: {
								type: 'encapsulate',
								options: {
									pre: ':('
								}
							}
						},
						bigSmile : {
							label: 'Big smile',
							action: {
								type: 'encapsulate',
								options: {
									pre: ':D'
								}
							}
						}
					}
				}
			}
		};
		assert.equal( this.$ui.find( '*[rel="emoticons"].section *[rel="faces"].group *[rel="icons"].tool' ).length, 0, 'Before adding select' );
		this.$target.wikiEditor( 'addToToolbar', data );
		assert.equal( this.$ui.find( '*[rel="emoticons"].section *[rel="faces"].group *[rel="icons"].tool' ).length, 1, 'After adding select' );

		// Remove select tool
		data = {
			section: 'emoticons',
			group: 'faces',
			tool: 'icons'
		};
		assert.equal( this.$ui.find( '*[rel="emoticons"].section *[rel="faces"].group *[rel="icons"].tool' ).length, 1, 'Before removing select' );
		this.$target.wikiEditor( 'removeFromToolbar', data );
		assert.equal( this.$ui.find( '*[rel="emoticons"].section *[rel="faces"].group *[rel="icons"].tool' ).length, 0, 'After removing select' );

		// Remove toolbar group
		data = {
			section: 'emoticons',
			group: 'faces'
		};
		assert.equal( this.$ui.find( '*[rel="emoticons"].section *[rel="faces"].group' ).length, 1, 'Before removing toolbar group' );
		this.$target.wikiEditor( 'removeFromToolbar', data );
		assert.equal( this.$ui.find( '*[rel="emoticons"].section *[rel="faces"].group' ).length, 0, 'After removing toolbar group' );

		// Remove toolbar section
		data = {
			section: 'emoticons'
		};
		assert.equal( this.$ui.find( '*[rel="emoticons"].section' ).length, 1, 'Before removing toolbar section' );
		this.$target.wikiEditor( 'removeFromToolbar', data );
		assert.equal( this.$ui.find( '*[rel="emoticons"].section' ).length, 0, 'After removing toolbar section' );
	} );

	QUnit.test( 'Booklets', 20, function ( assert ) {
		// Add booklet section
		var data = {
			sections: {
				info: {
					type: 'booklet',
					label: 'Info'
				}
			}
		};
		assert.equal( this.$ui.find( '*[rel="info"].section' ).length, 0, 'Before adding booklet section' );
		this.$target.wikiEditor( 'addToToolbar', data );
		assert.equal( this.$ui.find( '*[rel="info"].section' ).length, 1, 'After adding booklet section' );

		// Add table page
		data = {
			section: 'info',
			pages: {
				colors: {
					layout: 'table',
					label: 'Colors',
					headings: [
						{ text: 'Name' },
						{ text: 'Temperature' },
						{ text: 'Swatch' }
					]
				}
			}
		};
		assert.equal( this.$ui.find( '*[rel="info"].section *[rel="colors"].page' ).length, 0, 'Before adding table page' );
		this.$target.wikiEditor( 'addToToolbar', data );
		assert.equal( this.$ui.find( '*[rel="info"].section *[rel="colors"].page' ).length, 1, 'After adding table page' );

		// Add table rows
		data = {
			section: 'info',
			page: 'colors',
				rows: [
					{
						name: { text: 'Red' },
						temp: { text: 'Warm' },
						swatch: { html: '<div style="width: 10px; height: 10px; background-color: red;">' }
					},
					{
						name: { text: 'Blue' },
						temp: { text: 'Cold' },
						swatch: { html: '<div style="width: 10px; height: 10px; background-color: blue;">' }
					},
					{
						name: { text: 'Silver' },
						temp: { text: 'Neutral' },
						swatch: { html: '<div style="width: 10px; height: 10px; background-color: silver;">' }
					}
				]
		};
		assert.equal( this.$ui.find( '*[rel="info"].section *[rel="colors"].page tr td' ).length, 0, 'Before adding table rows' );
		this.$target.wikiEditor( 'addToToolbar', data );
		assert.equal( this.$ui.find( '*[rel="info"].section *[rel="colors"].page tr td' ).length, 9, 'After adding table rows' );

		// Remove table row
		data = {
			section: 'info',
			page: 'colors',
			row: 0
		};
		assert.equal( this.$ui.find( '*[rel="info"].section *[rel="colors"].page tr td' ).length, 9, 'Before removing table row' );
		this.$target.wikiEditor( 'removeFromToolbar', data );
		assert.equal( this.$ui.find( '*[rel="info"].section *[rel="colors"].page tr td' ).length, 6, 'After removing table row' );

		// Remove table page
		data = {
			section: 'info',
			page: 'colors'
		};
		assert.equal( this.$ui.find( '*[rel="info"].section *[rel="colors"].page' ).length, 1, 'Before removing table page' );
		this.$target.wikiEditor( 'removeFromToolbar', data );
		assert.equal( this.$ui.find( '*[rel="info"].section *[rel="colors"].page' ).length, 0, 'After removing table page' );

		// Add character page
		data = {
			section: 'info',
			pages: {
				emoticons: {
					layout: 'characters',
					label: 'Emoticons'
				}
			}
		};
		assert.equal( this.$ui.find( '*[rel="info"].section *[rel="emoticons"].page' ).length, 0, 'Before adding character page' );
		this.$target.wikiEditor( 'addToToolbar', data );
		assert.equal( this.$ui.find( '*[rel="info"].section *[rel="emoticons"].page' ).length, 1, 'After adding character page' );

		// Add characters
		data = {
			section: 'info',
			page: 'emoticons',
			characters: [ ':)', ':))', ':(', '<3', ';)' ]
		};
		assert.equal( this.$ui.find( '*[rel="info"].section *[rel="emoticons"].page *[rel=":))"]' ).length, 0, 'Before adding characters' );
		this.$target.wikiEditor( 'addToToolbar', data );
		assert.equal( this.$ui.find( '*[rel="info"].section *[rel="emoticons"].page *[rel=":))"]' ).length, 1, 'After adding characters' );

		// Remove character
		data = {
			section: 'info',
			page: 'emoticons',
			character: ':))'
		};
		assert.equal( this.$ui.find( '*[rel="info"].section *[rel="emoticons"].page *[rel=":))"]' ).length, 1, 'Before removing character' );
		this.$target.wikiEditor( 'removeFromToolbar', data );
		assert.equal( this.$ui.find( '*[rel="info"].section *[rel="emoticons"].page *[rel=":))"]' ).length, 0, 'After removing character' );

		// Remove character page
		data = {
			section: 'info',
			page: 'emoticons'
		};
		assert.equal( this.$ui.find( '*[rel="info"].section *[rel="emoticons"].page' ).length, 1, 'Before removing character page' );
		this.$target.wikiEditor( 'removeFromToolbar', data );
		assert.equal( this.$ui.find( '*[rel="info"].section *[rel="emoticons"].page' ).length, 0, 'After removing character page' );

		// Remove booklet section
		data = {
			section: 'info'
		};
		assert.equal( this.$ui.find( '*[rel="info"].section' ).length, 1, 'Before removing booklet section' );
		this.$target.wikiEditor( 'removeFromToolbar', data );
		assert.equal( this.$ui.find( '*[rel="info"].section' ).length, 0, 'After removing booklet section' );
	} );

}( jQuery ) );