Skip to content

Commit

Permalink
Rewrite the tests so now they actually test something.
Browse files Browse the repository at this point in the history
  • Loading branch information
Tade0 committed Aug 30, 2016
1 parent b608bf5 commit 30fe225
Showing 1 changed file with 78 additions and 15 deletions.
93 changes: 78 additions & 15 deletions tests/quailinclude.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,20 @@
( function() {
'use strict';

bender.editors = {
pathDefined: {
config: {
language: 'en',
a11ychecker_quailPath: 'test/path'
}
},
pathNotDefined: {
config: {
language: 'en'
}
}
};

CKEDITOR.plugins.a11ychecker = {
Engine: {}
};
Expand All @@ -18,9 +32,14 @@
define( 'EngineQuail', [], function() {} );

define( 'callback', [], function() {
return function() {};
return function() {
resume( function() {
assert.isTrue( true );
} );
};
} );


function mockLoad( success, onEnd ) {
CKEDITOR.scriptLoader.load = function( path, callback ) {
try {
Expand All @@ -33,25 +52,69 @@
};
}

mockLoad( true, function() {} );
bender.test( {
'test loading Quail from the path defined in the config': function() {
var editor = this.editors.pathDefined;
define( 'editor', [], function() {
return editor;
} );


var load = CKEDITOR.scriptLoader.load;
CKEDITOR.scriptLoader.load = sinon.spy();

require( [ 'quailInclude' ], function( quailInclude ) {
resume( function() {
assert.isTrue( CKEDITOR.scriptLoader.load.calledWith( [ 'test/path' ] ) );

// Cleanup after the test.
CKEDITOR.scriptLoader.load = load;
requirejs.undef( 'quailInclude' );
requirejs.undef( 'editor' );
} );
} );

bender.require( [ 'quailInclude' ], function( quailInclude ) {
bender.test( {
'test wrong Quail path throws exception': function() {
mockLoad( false, function( error ) {
wait();
},
'test loading Quail from the default path': function() {
var editor = this.editors.pathNotDefined;
define( 'editor', [], function() {
return editor;
} );

var load = CKEDITOR.scriptLoader.load;
CKEDITOR.scriptLoader.load = sinon.spy();

require( [ 'quailInclude' ], function( quailInclude ) {
resume( function() {
assert.isTrue( CKEDITOR.scriptLoader.load.calledWith( [ 'plugins/a11ychecker/libs/quail/quail.jquery.min.js' ] ) );

CKEDITOR.scriptLoader.load = load;
requirejs.undef( 'quailInclude' );
requirejs.undef( 'editor' );

} );
} );

wait();
},
'test wrong Quail path throws exception': function() {
var editor = this.editors.pathNotDefined;
define( 'editor', [], function() {
return editor;
} );

mockLoad( false, function( error ) {
resume( function() {
assert.isObject( error );
assert.areEqual( 'Could not load Quail', error.message );
} );
} );

quailInclude();
},
'test correct Quail path does not throw exception': function() {
mockLoad( true, function( error ) {
assert.isNull( error );
} );
require( [ 'quailInclude' ], function( quailInclude ) {} );

quailInclude();
}
} );
wait();
}
} );

} )();

0 comments on commit 30fe225

Please sign in to comment.