File: items.js

package info (click to toggle)
ckeditor 4.4.4%2Bdfsg1-3
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 25,632 kB
  • ctags: 2,419
  • sloc: sh: 190; python: 37; makefile: 29; php: 15; xml: 5
file content (138 lines) | stat: -rw-r--r-- 3,687 bytes parent folder | download
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
/* bender-tags: editor,unit */
/* bender-ckeditor-plugins: menu */

bender.editor = {
	config : {
		allowedContent: true
	}
};

bender.test( {
	getMenuMockup: function() {
		var editor = this.editor,
			menu = {
				_: {},
				id: 'cke_32',
				editor: editor,
				items: [],
				onHide: function() {}
			};

		return menu;
	},

	getMenuItemMockup: function( customDefinition ) {
		var editor = this.editor,
			definition = customDefinition || {};

		return new CKEDITOR.menuItem( editor, 'foo', definition );
	},

	// Tests menuItems rener function.
	// @param {String} expectedRole Expected role attribute value.
	// @param {Object} definition
	// @param {Function} callback Receives ouptut string as a first parameter. It should contain assertions.
	_testMenuItemRender: function( expectedRole, definition, callback ) {
		var menu = this.getMenuMockup(),
			index = 0,
			output = [],
			outputHtml;

		definition = definition || {};
		callback = callback || function( html ) {};

		var mock = this.getMenuItemMockup( definition );

		// Calling render.
		CKEDITOR.menuItem.prototype.render.call( mock, menu, index, output );

		outputHtml = output.join( '' );

		assert.areNotEqual( -1, outputHtml.search( 'role="' + expectedRole + '"' ), '[role="' + expectedRole + '"] attribute not found in html generated by CKEDITOR.menuItem.proto.render()' );

		callback.call( this, outputHtml );

		return outputHtml;
	},

	// Asserts that given string contains aria-checked attribute.
	// @param {Boolean} expectedValue
	// @param {String} html Tested html code.
	_assertAriaChecked: function( expectedValue, html ) {
		var expectedSubstring = 'aria-checked="' + ( expectedValue ? 'true' : 'false' ) + '"',
			assertMessage = '"' + expectedSubstring + '" substring has not been found';

		assert.areNotEqual( -1 , String( html ).search( expectedSubstring ), assertMessage );
	},

	'test default role' : function() {
		this._testMenuItemRender( 'menuitem', {} );
	},

	'test default menuitem state ON' : function() {
		// Ensures that menuitem does not get aria-checked attr, since it would
		// violate specs.
		this._testMenuItemRender( 'menuitem', {}, function( html ) {
			assert.areEqual( -1, html.search( 'aria-checked' ), 'aria-checked attribute should not be present in output html' );
		} );
	},

	'test menuitemcheckbox role' : function() {
		var definition = {
				role: 'menuitemcheckbox'
			};

		this._testMenuItemRender( 'menuitemcheckbox', definition );
	},

	'test menuitemcheckbox sate OFF' : function() {
		var definition = {
				role: 'menuitemcheckbox',
				state: CKEDITOR.TRISTATE_ON
			};

		this._testMenuItemRender( 'menuitemcheckbox', definition, function( html ) {
			this._assertAriaChecked( true, html );
		} );
	},

	'test menuitemcheckbox state ON' : function() {
		var definition = {
				role: 'menuitemcheckbox',
				state: CKEDITOR.TRISTATE_OFF
			};

		this._testMenuItemRender( 'menuitemcheckbox', definition, function( html ) {
			this._assertAriaChecked( false, html );
		} );
	},

	'test menuitemcheckbox undefined state' : function() {
		var definition = {
				role: 'menuitemcheckbox'
			};

		this._testMenuItemRender( 'menuitemcheckbox', definition, function( html ) {
			this._assertAriaChecked( false, html );
		} );
	},

	'test menuitemradio role' : function() {
		var definition = {
				role: 'menuitemradio'
			};
		this._testMenuItemRender( 'menuitemradio', definition );
	},

	'test menuitemradio state ON' : function() {
		var definition = {
				role: 'menuitemradio',
				state: CKEDITOR.TRISTATE_ON
			};

		this._testMenuItemRender( 'menuitemradio', definition, function( html ) {
			this._assertAriaChecked( true, html );
		} );
	}

} );