Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

T/16938 Extract common PFW tests loop. #333

Merged
merged 4 commits into from
Apr 6, 2017
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions tests/plugins/pastefromword/generated/_helpers/createTestCase.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/* global assertWordFilter,Q */
/* bender-include: _helpers/pfwTools.js */
/* global assertWordFilter,Q,console */
/* exported createTestCase */

// @param {boolean} [compareRawData=false] If `true` test case will assert against raw paste's `data.dataValue` rather than
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we're adding docs in other places, then we can also add missing docs for createTestCase as only one parameter is described.

Expand Down Expand Up @@ -43,11 +42,13 @@ function createTestCase( fixtureName, wordVersion, browser, tickets, compareRawD

var nbspListener = editor.once( 'paste', function( evt ) {
// Clipboard strips white spaces from pasted content if those are not encoded.
// This is **needed only for non-IE/Edge fixtures**, as these browsers doesn't encode nbsp char on
// it's own.
if ( CKEDITOR.env.ie &&
CKEDITOR.tools.array.indexOf( [ 'chrome', 'firefox', 'safari' ], browser ) !== -1 ) {
evt.data.dataValue = evt.data.dataValue.replace( / /g, ' ' );
// This is **needed only for non-IE/Edge fixtures**, as these browsers doesn't encode nbsp char on it's own.
if ( CKEDITOR.env.ie && CKEDITOR.tools.array.indexOf( [ 'chrome', 'firefox', 'safari' ], browser ) !== -1 ) {
var encodedData;
/* jshint ignore:start */
encodedData = evt.data.dataValue.replace( / /g, ' ' );
/* jshint ignore:end */
evt.data.dataValue = encodedData;
}
}, null, null, 5 );

Expand Down
73 changes: 73 additions & 0 deletions tests/plugins/pastefromword/generated/_helpers/createTestSuite.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/* global createTestCase */
/* exported createTestSuite */

// Creates a test suite based on the options provided. The test suite then should be passed to `bender.test` to run tests.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not standard JSDoc comments, similar to our existing tests? Comments from tests don't leak into documentation, so it's safe to use JSDoc in a normal way.

//
// @param {Object} options
// @param {Array} options.browsers Array of browser names.
// @param {Array} options.wordVersions Array of word version names.
// @param {Object} options.tests Object containing tests to be generated. It contains key - value pairs, where key is name of the test file and value
// is an array of wordVersions name for which tests should be generated or a boolean indicating: true - generate for all versions, false - for none.
// @param {Object} [options.ticketTests] Object containing tests to be generated. It has same structure as `options.tests`.
// @param {Array} [options.testData] Test data object (may contain e.g. information about ignored tests). All created tests will be added into testData object.
// @param {Array} [options.customFilters] Array of custom filters (like [ pfwTools.filters.font ]) which will be used during assertions.
// @param {Boolean} [options.compareRawData=false] If `true` test case will assert against raw paste's `data.dataValue` rather than
// what will appear in the editor after all transformations and filtering.
// @param {Boolean} [options.ignoreAll=false] Whenever to ignore all tests.
// @returns {Object} Test data object which should be passed to `bender.test` function.
function createTestSuite( options ) {

var browsers = options.browsers || [],
wordVersions = options.wordVersions || [],
tests = options.tests || [],
ticketTests = options.ticketTests || [],
testData = options.testData || { _should: { ignore: {} } },
ignoreAll = options.ignoreAll === true,
compareRawData = options.compareRawData === true,
customFilters = options.customFilters ? options.customFilters : null;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO it can be much simplified by using CKEDITOR.tools.extend to set default values for undefined options.


_prepareTests( testData, tests, browsers, wordVersions, compareRawData, customFilters, false, ignoreAll );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And if we're going with simplified handling of options object, we can also pass it straight to _prepareTests instead of passing absurdly high number of parameters.


_prepareTests( testData, ticketTests, browsers, wordVersions, compareRawData, customFilters, true, ignoreAll );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I'm seeing correctly, the only place that uses the information if the tests are ticket ones or not is inside createTestCase to correctly choose the right path to lookup tests. In that case IMO we could drop ticketTests at all and make all tests… well, just tests. The info that these tests are ticket ones could be moved into their name.

I'm not seeing any sense in a special treatment of Tickets subdirectory, especially when we have also some others (e.g. No_heuristics). And this change will simplify test code even more.


return testData;
}

// Iterates over given tests, browsers and wordVersions creating tests based on all possible combinations.
//
// @private
// @param {Object} testData
// @param {Array} tests
// @param {Array} browsers
// @param {Array} wordVersions
// @param {Boolean} compareRawData
// @param {Array} customFilters
// @param {Boolean} areTicketsTests Whenever tests should be generated using `tickets/` directory.
// @param {Boolean} ignoreAll
function _prepareTests( testData, tests, browsers, wordVersions, compareRawData, customFilters, areTicketsTests, ignoreAll ) {
var testsKeys = CKEDITOR.tools.objectKeys( tests ),
wordVersion, testKey, testName, i, k, j;

if ( testsKeys.length ) {
for ( i = 0; i < testsKeys.length; i++ ) {
for ( k = 0; k < browsers.length; k++ ) {
for ( j = 0; j < wordVersions.length; j++ ) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't it be before browsers loop? I mean, j is usually before k… :P


wordVersion = wordVersions[ j ];
testKey = testsKeys[ i ];

if ( tests[ testKey ] === true || CKEDITOR.tools.indexOf( tests[ testKey ], wordVersion ) !== -1 ) {

testName = [ 'test', testKey, wordVersion, browsers[ k ] ].join( ' ' );

if ( ignoreAll ) {
testData._should.ignore[ testName ] = true;
}

testData[ testName ] = createTestCase( testKey, wordVersion, browsers[ k ], areTicketsTests, compareRawData, customFilters );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a big fan of options object! Maybe we could use this approach also in createTestCase? It would be much more readable than 6 parameters.

}
}
}
}
}
}
28 changes: 9 additions & 19 deletions tests/plugins/pastefromword/generated/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
/* bender-ckeditor-plugins: pastefromword,ajax,basicstyles,bidi,font,link,toolbar,colorbutton,image */
/* bender-ckeditor-plugins: list,liststyle,sourcearea,format,justify,table,tableresize,tabletools,indent,indentblock,div,dialog */
/* jshint ignore:end */
/* bender-include: _lib/q.js,_helpers/promisePasteEvent.js,_lib/q.js,_helpers/assertWordFilter.js,_helpers/createTestCase.js,_helpers/pfwTools.js */
/* global createTestCase */
/* bender-include: _lib/q.js,_helpers/promisePasteEvent.js,_helpers/assertWordFilter.js,_helpers/createTestCase.js */
/* bender-include: _helpers/createTestSuite.js,_helpers/pfwTools.js */
/* global createTestSuite */

( function() {
'use strict';
Expand All @@ -16,32 +17,21 @@
}
};

var browsers = [
bender.test( createTestSuite( {
browsers: [
'chrome',
'firefox',
'ie8',
'ie11',
'safari'
],
wordVersions = [
wordVersions: [
'word2007',
'word2013'
],
tests = {
tests: {
'Config_remove_font_styles': true
},
keys = CKEDITOR.tools.objectKeys( tests ),
testData = {};

for ( var i = 0; i < keys.length; i++ ) {
for ( var j = 0; j < wordVersions.length; j++ ) {
for ( var k = 0; k < browsers.length; k++ ) {
if ( tests[ keys[ i ] ] === true || CKEDITOR.tools.indexOf( tests[ keys[ i ] ], wordVersions[ j ] ) !== -1 ) {
testData[ [ 'test', keys[ i ], wordVersions[ j ], browsers[ k ] ].join( ' ' ) ] = createTestCase( keys[ i ], wordVersions[ j ], browsers[ k ], false, true );
}
}
}
}

bender.test( testData );
compareRawData: true
} ) );
} )();
41 changes: 12 additions & 29 deletions tests/plugins/pastefromword/generated/generic.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
/* bender-ckeditor-plugins: pastefromword,ajax,basicstyles,bidi,font,link,toolbar,colorbutton,image */
/* bender-ckeditor-plugins: list,liststyle,sourcearea,format,justify,table,tableresize,tabletools,indent,indentblock,div,dialog */
/* jshint ignore:end */
/* bender-include: _lib/q.js,_helpers/promisePasteEvent.js,_lib/q.js,_helpers/assertWordFilter.js,_helpers/createTestCase.js,_helpers/pfwTools.js */
/* global createTestCase,pfwTools */
/* bender-include: _lib/q.js,_helpers/promisePasteEvent.js,_helpers/assertWordFilter.js,_helpers/createTestCase.js */
/* bender-include: _helpers/createTestSuite.js,_helpers/pfwTools.js */
/* global pfwTools,createTestSuite */

( function() {
'use strict';
Expand All @@ -13,18 +14,19 @@
config: pfwTools.defaultConfig
};

var browsers = [
bender.test( createTestSuite( {
browsers: [
'chrome',
'firefox',
'ie8',
'ie11',
'safari'
],
wordVersions = [
wordVersions: [
'word2007',
'word2013'
],
tests = {
tests: {
'Bold': true,
'Colors': true,
'Custom_list_markers': true,
Expand All @@ -45,28 +47,9 @@
'Table_alignment': true,
'Table_vertical_alignment': true
},
keys = CKEDITOR.tools.objectKeys( tests ),
testData = {
_should: {
ignore: {}
}
};

for ( var i = 0; i < keys.length; i++ ) {
for ( var j = 0; j < wordVersions.length; j++ ) {
for ( var k = 0; k < browsers.length; k++ ) {
if ( tests[ keys[ i ] ] === true || CKEDITOR.tools.indexOf( tests[ keys[ i ] ], wordVersions[ j ] ) !== -1 ) {
var testName = [ 'test', keys[ i ], wordVersions[ j ], browsers[ k ] ].join( ' ' );

if ( CKEDITOR.env.ie && CKEDITOR.env.version <= 11 ) {
testData._should.ignore[ testName ] = true;
}

testData[ testName ] = createTestCase( keys[ i ], wordVersions[ j ], browsers[ k ], false, false, [ pfwTools.filters.span ] );
}
}
}
}

bender.test( testData );
customFilters: [
pfwTools.filters.span
],
ignoreAll: CKEDITOR.env.ie && CKEDITOR.env.version <= 11
} ) );
} )();
36 changes: 12 additions & 24 deletions tests/plugins/pastefromword/generated/generic_strict.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
/* bender-ckeditor-plugins: pastefromword,ajax,basicstyles,bidi,font,link,toolbar,colorbutton,image */
/* bender-ckeditor-plugins: list,liststyle,sourcearea,format,justify,table,tableresize,tabletools,indent,indentblock,div,dialog */
/* jshint ignore:end */
/* bender-include: _lib/q.js,_helpers/promisePasteEvent.js,_lib/q.js,_helpers/assertWordFilter.js,_helpers/createTestCase.js,_helpers/pfwTools.js */
/* global pfwTools,createTestCase */
/* bender-include: _lib/q.js,_helpers/promisePasteEvent.js,_helpers/assertWordFilter.js,_helpers/createTestCase.js */
/* bender-include: _helpers/createTestSuite.js,_helpers/pfwTools.js */
/* global pfwTools,createTestSuite */

( function() {
'use strict';
Expand All @@ -15,39 +16,26 @@
}
};

var browsers = [
bender.test( createTestSuite( {
browsers: [
'chrome',
'firefox',
'ie8',
'ie11',
'edge',
'safari'
],
wordVersions = [
wordVersions: [
'word2007',
'word2013'
],
// To test only particular word versions set the key value to an array in the form: [ 'word2007', 'word2013' ].
tests = {
tests: {
'Unordered_list_multiple': true,
'White_space': true
},
keys = CKEDITOR.tools.objectKeys( tests ),
testData = {
_should: {
ignore: {}
}
};

for ( var i = 0; i < keys.length; i++ ) {
for ( var j = 0; j < wordVersions.length; j++ ) {
for ( var k = 0; k < browsers.length; k++ ) {
if ( tests[ keys[ i ] ] === true || CKEDITOR.tools.indexOf( tests[ keys[ i ] ], wordVersions[ j ] ) !== -1 ) {
testData[ [ 'test', keys[ i ], wordVersions[ j ], browsers[ k ] ].join( ' ' ) ] = createTestCase( keys[ i ], wordVersions[ j ], browsers[ k ], false, true, [ pfwTools.filters.font ] );
}
}
}
}

bender.test( testData );
customFilters: [
pfwTools.filters.font
],
compareRawData: true
} ) );
} )();
43 changes: 12 additions & 31 deletions tests/plugins/pastefromword/generated/inline_styles.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
/* bender-ckeditor-plugins: pastefromword,ajax,basicstyles,bidi,font,link,toolbar,colorbutton,image */
/* bender-ckeditor-plugins: list,liststyle,sourcearea,format,justify,table,tableresize,tabletools,indent,indentblock,div,dialog */
/* jshint ignore:end */
/* bender-include: _lib/q.js,_helpers/promisePasteEvent.js,_lib/q.js,_helpers/assertWordFilter.js,_helpers/createTestCase.js,_helpers/pfwTools.js */
/* global createTestCase,pfwTools */
/* bender-include: _lib/q.js,_helpers/promisePasteEvent.js,_helpers/assertWordFilter.js,_helpers/createTestCase.js */
/* bender-include: _helpers/createTestSuite.js,_helpers/pfwTools.js */
/* global pfwTools,createTestSuite */

( function() {
'use strict';
Expand All @@ -13,42 +14,22 @@
config: pfwTools.defaultConfig
};

var browsers = [
bender.test( createTestSuite( {
browsers: [
'chrome',
'firefox',
'safari'
],
wordVersions = [
wordVersions: [
'word2007',
'word2013'
],
tests = {
tests: {
'InlineStyles': true
},
keys = CKEDITOR.tools.objectKeys( tests ),
testData = {
_should: {
ignore: {
'InlineStyles': true
}
}
};

for ( var i = 0; i < keys.length; i++ ) {
for ( var j = 0; j < wordVersions.length; j++ ) {
for ( var k = 0; k < browsers.length; k++ ) {
if ( tests[ keys[ i ] ] === true || CKEDITOR.tools.indexOf( tests[ keys[ i ] ], wordVersions[ j ] ) !== -1 ) {
var testName = [ 'test', keys[ i ], wordVersions[ j ], browsers[ k ] ].join( ' ' );

if ( CKEDITOR.env.ie ) {
testData._should.ignore[ testName ] = true;
}

testData[ testName ] = createTestCase( keys[ i ], wordVersions[ j ], browsers[ k ], false, false, [ pfwTools.filters.style ] );
}
}
}
}

bender.test( testData );
customFilters: [
pfwTools.filters.style
],
ignoreAll: CKEDITOR.env.ie
} ) );
} )();
32 changes: 10 additions & 22 deletions tests/plugins/pastefromword/generated/new.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
/* bender-ckeditor-plugins: pastefromword,ajax,basicstyles,bidi,font,link,toolbar,colorbutton,image */
/* bender-ckeditor-plugins: list,liststyle,sourcearea,format,justify,table,tableresize,tabletools,indent,indentblock,div,dialog */
/* jshint ignore:end */
/* bender-include: _lib/q.js,_helpers/promisePasteEvent.js,_lib/q.js,_helpers/assertWordFilter.js,_helpers/createTestCase.js,_helpers/pfwTools.js */
/* global createTestCase */
/* bender-include: _lib/q.js,_helpers/promisePasteEvent.js,_helpers/assertWordFilter.js,_helpers/createTestCase.js */
/* bender-include: _helpers/createTestSuite.js,_helpers/pfwTools.js */
/* global createTestSuite */

( function() {
'use strict';
Expand All @@ -16,30 +17,17 @@
}
};

var browsers = [
bender.test( createTestSuite( {
browsers: [
'chrome',
'ie8'
],
wordVersion = 'word2013',
ticketTests = {
wordVersions: [
'word2013'
],
tests: {
'Multi_dig_list': [ 'word2013' ],
'List_skipped_numbering': [ 'word2013' ]
},
testData = {
_should: {
ignore: {}
}
},
ticketKeys = CKEDITOR.tools.objectKeys( ticketTests ),
i, k;

for ( i = 0; i < ticketKeys.length; i++ ) {
for ( k = 0; k < browsers.length; k++ ) {
if ( ticketTests[ ticketKeys[ i ] ] === true || CKEDITOR.tools.indexOf( ticketTests[ ticketKeys[ i ] ], wordVersion ) !== -1 ) {
testData[ [ 'test', ticketKeys[ i ], wordVersion, browsers[ k ] ].join( ' ' ) ] = createTestCase( ticketKeys[ i ], wordVersion, browsers[ k ] );
}
}
}

bender.test( testData );
} ) );
} )();
Loading