TinyMCE: wptextpattern: make tests ~2x faster

* Reuse the same instance for all tests in the module.
* Run without CSS (skin).
* Less typing.

See #31441.


git-svn-id: https://develop.svn.wordpress.org/trunk@32706 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Ella Iseulde Van Dorpe 2015-06-07 22:15:47 +00:00
parent ea5ba64400
commit 11de1cedaa
1 changed files with 35 additions and 21 deletions

View File

@ -1,5 +1,6 @@
( function( $, QUnit, tinymce, _type, setTimeout ) { ( function( $, QUnit, tinymce, _type, setTimeout ) {
var editor; var editor,
count = 0;
if ( tinymce.Env.ie && tinymce.Env.ie < 9 ) { if ( tinymce.Env.ie && tinymce.Env.ie < 9 ) {
return; return;
@ -31,35 +32,48 @@
QUnit.module( 'tinymce.plugins.wptextpattern', { QUnit.module( 'tinymce.plugins.wptextpattern', {
beforeEach: function( assert ) { beforeEach: function( assert ) {
var done = assert.async(); var done;
$( '#qunit-fixture' ).append( '<textarea id="editor">' ); if ( ! editor ) {
done = assert.async();
tinymce.init( { $( document.body ).append( '<textarea id="editor">' );
selector: '#editor',
plugins: 'wptextpattern', tinymce.init( {
init_instance_callback: function() { selector: '#editor',
editor = arguments[0]; skin: false,
editor.focus(); plugins: 'wptextpattern',
editor.selection.setCursorLocation(); init_instance_callback: function() {
setTimeout( done ); editor = arguments[0];
} editor.focus();
} ); editor.selection.setCursorLocation();
done();
}
} );
} else {
editor.setContent( '' );
editor.selection.setCursorLocation();
}
}, },
afterEach: function() { afterEach: function( assert ) {
editor.remove(); count++;
if ( count === assert.test.module.tests.length ) {
editor.remove();
$( '#editor' ).remove();
}
} }
} ); } );
QUnit.test( 'Unordered list.', function( assert ) { QUnit.test( 'Unordered list.', function( assert ) {
type( '* test', function() { type( '* a', function() {
assert.equal( editor.getContent(), '<ul>\n<li>test</li>\n</ul>' ); assert.equal( editor.getContent(), '<ul>\n<li>a</li>\n</ul>' );
}, assert.async() ); }, assert.async() );
} ); } );
QUnit.test( 'Ordered list.', function( assert ) { QUnit.test( 'Ordered list.', function( assert ) {
type( '1. test', function() { type( '1. a', function() {
assert.equal( editor.getContent(), '<ol>\n<li>test</li>\n</ol>' ); assert.equal( editor.getContent(), '<ol>\n<li>a</li>\n</ol>' );
}, assert.async() ); }, assert.async() );
} ); } );
@ -94,8 +108,8 @@
editor.setContent( '<p>* test</p>' ); editor.setContent( '<p>* test</p>' );
editor.selection.setCursorLocation( editor.$( 'p' )[0].firstChild, 6 ); editor.selection.setCursorLocation( editor.$( 'p' )[0].firstChild, 6 );
type( ' test', function() { type( ' a', function() {
assert.equal( editor.getContent(), '<p>* test test</p>' ); assert.equal( editor.getContent(), '<p>* test a</p>' );
}, assert.async() ); }, assert.async() );
} ); } );