Skip to content

Commit dbbf367

Browse files
committed
Merge branch 't/12101'
2 parents d888ea2 + 2c17a73 commit dbbf367

File tree

2 files changed

+164
-0
lines changed

2 files changed

+164
-0
lines changed
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/* bender-tags: editor,unit,utils */
2+
3+
( function() {
4+
'use strict';
5+
6+
var htmlTools = bender.tools.html,
7+
shouldReturn, called, expected, actual, options;
8+
9+
htmlTools.compareInnerHtml = function( argExpected, argActual, argOptions ) {
10+
called = true;
11+
expected = argExpected;
12+
actual = argActual;
13+
options = argOptions;
14+
15+
return shouldReturn;
16+
};
17+
18+
bender.test( {
19+
setUp: function() {
20+
called = expected = actual = options = undefined;
21+
shouldReturn = true;
22+
},
23+
24+
'test passes - no opts': function() {
25+
assert.isInnerHtmlMatching( 'a', 'b' );
26+
assert.isTrue( called, 'compareInnerHtml was called' );
27+
assert.areSame( 'a', expected, 'expected' );
28+
assert.areSame( 'b', actual, 'actual' );
29+
assert.isNull( options, 'options' );
30+
},
31+
32+
'test passes - opts': function() {
33+
var obj = {};
34+
35+
assert.isInnerHtmlMatching( 'a', 'b', obj );
36+
assert.isTrue( called, 'compareInnerHtml was called' );
37+
assert.areSame( 'a', expected, 'expected' );
38+
assert.areSame( 'b', actual, 'actual' );
39+
assert.areSame( obj, options, 'options' );
40+
},
41+
42+
'test passes - message': function() {
43+
assert.isInnerHtmlMatching( 'a', 'b', 'msg' );
44+
assert.isTrue( called, 'compareInnerHtml was called' );
45+
assert.areSame( 'a', expected, 'expected' );
46+
assert.areSame( 'b', actual, 'actual' );
47+
assert.isNull( options, 'options' );
48+
},
49+
50+
'test fails': function() {
51+
shouldReturn = false;
52+
53+
var error,
54+
failed = false;
55+
56+
try {
57+
assert.isInnerHtmlMatching( 'a', 'b', 'msg' );
58+
} catch ( e ) {
59+
error = e;
60+
failed = true;
61+
}
62+
63+
assert.isTrue( failed, 'failed' );
64+
assert.isTrue( called, 'compareInnerHtml was called' );
65+
assert.areSame( 'a', expected, 'expected' );
66+
assert.areSame( 'b', actual, 'actual' );
67+
assert.isNull( options, 'options' );
68+
assert.areSame( 'msg', error.message, 'message' )
69+
}
70+
} );
71+
} )();

tests/utils/html/compareinnerhtml.js

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
/* bender-tags: editor,unit,utils */
2+
3+
( function() {
4+
'use strict';
5+
6+
var compatHtmlArgs,
7+
originalCompatHtml = bender.tools.compatHtml,
8+
htmlTools = bender.tools.html;
9+
10+
bender.tools.compatHtml = function( html, noInterWS, sortAttributes, fixZWS, fixStyles, fixNbsp ) {
11+
compatHtmlArgs = {
12+
noInterWS: !!noInterWS,
13+
sortAttributes: !!sortAttributes,
14+
fixZWS: !!fixZWS,
15+
fixStyles: !!fixStyles,
16+
fixNbsp: !!fixNbsp
17+
};
18+
19+
return originalCompatHtml.call( bender.tools, html, noInterWS, sortAttributes, fixZWS, fixStyles, fixNbsp );
20+
};
21+
22+
function t( ret, expected, actual, options, expectedCompatHtmlArgs ) {
23+
return function() {
24+
// In case compatHtml was not called at all.
25+
compatHtmlArgs = {};
26+
assert.areSame( ret, htmlTools.compareInnerHtml( expected, actual, options ), 'returned value' );
27+
28+
if ( expectedCompatHtmlArgs ) {
29+
for ( var arg in expectedCompatHtmlArgs ) {
30+
assert.areSame( expectedCompatHtmlArgs[ arg ], compatHtmlArgs[ arg ],
31+
'compatHtml\'s argument: ' + arg );
32+
}
33+
}
34+
};
35+
}
36+
37+
bender.test( {
38+
// Options ------------------------------------------------------------
39+
40+
'opts.noInterWS defaults to false': t( true, '', '', null, { noInterWS: false } ),
41+
'opts.noInterWS defaults to false 2': t( true, '', '', {}, { noInterWS: false } ),
42+
'opts.noInterWS is passed': t( true, '', '', { noInterWS: true }, { noInterWS: true } ),
43+
44+
'opts.fixStyles defaults to false': t( true, '', '', null, { fixStyles: false } ),
45+
'opts.fixStyles is passed': t( true, '', '', { fixStyles: true }, { fixStyles: true } ),
46+
47+
'opts.sortAttributes defaults to true': t( true, '', '', null, { sortAttributes: true } ),
48+
'opts.fixZWS defaults to true': t( true, '', '', null, { fixZWS: true } ),
49+
'opts.fixNbsp defaults to true': t( true, '', '', null, { fixNbsp: true } ),
50+
51+
'multiple opts': t( true, '', '', { fixNbsp: false, fixStyles: true }, { fixZWS: true, fixNbsp: false, fixStyles: true } ),
52+
53+
// Passing ------------------------------------------------------------
54+
55+
'simple string': t( true, 'foo', 'foo' ),
56+
'simple element': t( true, '<b>foo</b>', '<B>foo</B>' ),
57+
'bogus expected, not exists': t( true, 'a@', 'a' ),
58+
'bogus expected, exists': t( true, 'a@', 'a<br />' ),
59+
'multiple boguses': t( true, '<p>a@</p><p>b@</p><p>c@</p>', '<p>a<br /></p><p>b</p><p>c<br /></p>' ),
60+
'regexp conflict [': t( true, 'ba[r', 'ba[r' ),
61+
62+
'markers 1 - no opts.compareSelection': t( true, 'ba[r]', 'ba[r]' ),
63+
'markers 2 - no opts.compareSelection': t( true, 'ba{}r', 'ba{}r' ),
64+
'markers 3 - no opts.compareSelection': t( true, '<ul><li>[</li><li>a</li></ul>', '<ul>[<li>a</li></ul>' ),
65+
66+
'markers 1 - opts.compareSelection': t( true, 'ba[r}', 'ba[r}', { compareSelection: true } ),
67+
'markers 2 - opts.compareSelection': t( true, 'ba{}r', 'ba{}r', { compareSelection: true } ),
68+
'markers 3 - opts.compareSelection': t( true, 'ba[]r', 'ba[]r', { compareSelection: true } ),
69+
'markers 4 - opts.compareSelection': t( true, '<ul>[<li>a</li>]</ul>', '<ul>[<li>a</li>]</ul>', { compareSelection: true } ),
70+
71+
'markers 1 - opts.compare&normalizeSelection': t( true, 'ba[r]', 'ba{r}', { compareSelection: true, normalizeSelection: true } ),
72+
'markers 2 - opts.compare&normalizeSelection': t( true, 'ba^r', 'ba{}r', { compareSelection: true, normalizeSelection: true } ),
73+
'markers 3 - opts.compare&normalizeSelection': t( true, 'ba^r', 'ba[]r', { compareSelection: true, normalizeSelection: true } ),
74+
'markers 4 - opts.compare&normalizeSelection': t( true, '<ul>[<li>a</li>]</ul>', '<ul>[<li>a</li>]</ul>', { compareSelection: true, normalizeSelection: true } ),
75+
76+
// Failing ------------------------------------------------------------
77+
78+
'simple string - fail': t( false, 'foo', 'bar' ),
79+
'simple element - fail': t( false, '<b>foo</b>', '<I>foo</I>' ),
80+
'not expected bogus - fail': t( false, '<p>foo<br /></p>', '<p>foo</p>' ),
81+
82+
// Expected part has to be regexified if special characters are not escaped
83+
// bad things may happen.
84+
'regexp conflict * - fail': t( false, 'ba*r', 'br' ),
85+
'regexp - partial match - start - fail': t( false, 'bar', 'barx' ),
86+
'regexp - partial match - end - fail': t( false, 'bar', 'xbar' ),
87+
88+
'markers 1 - no opts.compareSelection - fail': t( false, 'bar', 'ba[]r' ),
89+
'markers 2 - no opts.compareSelection - fail': t( false, 'ba{}r', 'ba[]r' ),
90+
'markers - opts.compareSelection - fail': t( false, 'ba{}r', 'ba[]r', { compareSelection: true } ),
91+
'markers - opts.compare&normalizeSelection - fail': t( false, 'ba[]r', 'ba[]r', { compareSelection: true, normalizeSelection: true } ),
92+
} );
93+
} )();

0 commit comments

Comments
 (0)