File: functions.js

package info (click to toggle)
ckeditor 4.22.1%2Bdfsg1-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 290,692 kB
  • sloc: javascript: 237,176; sh: 202; makefile: 64; python: 37; php: 15; xml: 5
file content (87 lines) | stat: -rw-r--r-- 2,689 bytes parent folder | download | duplicates (2)
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
/* bender-tags: editor, dialog */
/* bender-ckeditor-plugins: dialog */

bender.test( {
	'test functions invoke all passed validators joined with default VALIDATE_AND with value': function() {
		var testValue = 'value',
			stubValidator = sinon.stub().returns( true );

		CKEDITOR.dialog.validate.functions(
			stubValidator,
			stubValidator,
			stubValidator
		)( testValue );

		assert.areSame( stubValidator.callCount, 3, 'Validator should be called 3 times.' );
		assert.isTrue( stubValidator.calledWith( testValue ), 'Validator should be called with "' + testValue + '".' );
	},

	'test functions returns true if all inner validators returns true - joined with default VALIDATE_AND': function() {
		var stubValidator = sinon.stub().returns( true );

		var result = CKEDITOR.dialog.validate.functions(
			stubValidator,
			stubValidator,
			stubValidator
		)( 'any value' );

		assert.isTrue( result );
	},

	// (#4449)
	'test functions returns error message if any inner validator returns not true - joined with default VALIDATE_AND': function() {
		var stubTrueValidator = sinon.stub().returns( true ),
			stubFalseValidator = sinon.stub().returns( 'error message' ),
			errorMsg = 'error!';

		var result = CKEDITOR.dialog.validate.functions(
			stubTrueValidator,
			stubFalseValidator,
			errorMsg
		)( 'any value' );

		assert.areSame( errorMsg, result );
	},

	'test functions returns true if any inner validator returns true - joined with VALIDATE_OR': function() {
		var stubTrueValidator = sinon.stub().returns( true ),
			stubFalseValidator = sinon.stub().returns( false );

		var result = CKEDITOR.dialog.validate.functions(
			stubTrueValidator,
			stubFalseValidator,
			'error message',
			CKEDITOR.VALIDATE_OR
		)( 'any value' );

		assert.isTrue( result );
	},

	'test functions returns error message if all inner validator returns not true - joined with VALIDATE_OR': function() {
		var stubFalseValidator = sinon.stub().returns( 'error message' ),
			errorMsg = 'error!';

		var result = CKEDITOR.dialog.validate.functions(
			stubFalseValidator,
			stubFalseValidator,
			errorMsg,
			CKEDITOR.VALIDATE_OR
		)( 'any value' );

		assert.areSame( errorMsg, result );
	},

	'test functions favor getValue context method instead of value parameter': function() {
		var stubValidator = sinon.stub().returns( true ),
			context = {
				getValue: function() {
					return 'getValue';
				}
			};

		CKEDITOR.dialog.validate.functions( stubValidator ).call( context, 'value' );

		assert.areSame( stubValidator.callCount, 1, 'Validator should be called once.' );
		assert.isTrue( stubValidator.calledWith( 'getValue' ), 'Validator should use "getValue" value.' );
	}
} );