Skip to content

Commit

Permalink
Fix testing to take into account both jqlite and jquery options.
Browse files Browse the repository at this point in the history
  • Loading branch information
Simeon authored and Simeon committed Mar 31, 2014
1 parent 6f7e026 commit 311bdc0
Show file tree
Hide file tree
Showing 11 changed files with 462 additions and 302 deletions.
7 changes: 5 additions & 2 deletions Gruntfile.js
Expand Up @@ -41,8 +41,11 @@ module.exports = function (grunt) {
}
},
karma: {
unit: {
options: testConfig('karma.conf.js')
jquery: {
options: testConfig('karma-jquery.conf.js')
},
jqlite: {
options: testConfig('karma-jqlite.conf.js')
}
},
jshint: {
Expand Down
4 changes: 2 additions & 2 deletions dist/textAngular.min.js

Large diffs are not rendered by default.

86 changes: 86 additions & 0 deletions karma-jqlite.conf.js
@@ -0,0 +1,86 @@

module.exports = function (config) {
'use strict';
config.set({

frameworks: ['jasmine'],

plugins: [
'karma-jasmine',
'karma-phantomjs-launcher',
'karma-coverage'
],

files: [
'bower_components/rangy/rangy-core.js',
'bower_components/rangy/rangy-selectionsaverestore.js',
'bower_components/angular/angular.min.js',
'bower_components/angular-mocks/angular-mocks.js',
'src/textAngular-sanitize.js',
'src/textAngularSetup.js',
'src/textAngular.js',
'bower_components/jquery/jquery.min.js',
'test/**/*.spec.js'
],

// list of files to exclude
exclude: [

],

preprocessors: {
'src/textAngular.js': ['coverage'],
'src/textAngularSetup.js': ['coverage']
},

// test results reporter to use
// possible values: 'dots', 'progress', 'junit'
reporters: ['progress', 'coverage'],
coverageReporter: {
reporters: [
{type: 'json', dir: 'coverage/'},
{type: 'lcov', dir: 'coverage/'}
]
},

// web server port
port: 9876,


// cli runner port
runnerPort: 9100,


// enable / disable colors in the output (reporters and logs)
colors: true,


// level of logging
// possible values: LOG_DISABLE || LOG_ERROR || LOG_WARN || LOG_INFO || LOG_DEBUG
logLevel: config.LOG_INFO,


// enable / disable watching file and executing tests whenever any file changes
autoWatch: false,


// Start these browsers, currently available:
// - Chrome
// - ChromeCanary
// - Firefox
// - Opera
// - Safari (only Mac)
// - PhantomJS
// - IE (only Windows)
browsers: ['PhantomJS'],


// If browser does not capture in given timeout [ms], kill it
captureTimeout: 60000,


// Continuous Integration mode
// if true, it capture browsers, run tests and exit
singleRun: true
});
};
File renamed without changes.
47 changes: 35 additions & 12 deletions src/textAngular.js
Expand Up @@ -42,6 +42,15 @@ See README.md or https://github.com/fraywing/textAngular/wiki for requirements a
return ((rv > -1) ? rv : undef);
}());

// tests against the current jqLite/jquery implementation if this can be an element
function validElementString(string){
try{
return angular.element(string).length !== 0;
}catch(any){
return false;
}
}

/*
Custom stylesheet for the placeholders rules.
Credit to: http://davidwalsh.name/add-rules-stylesheets
Expand Down Expand Up @@ -169,7 +178,7 @@ See README.md or https://github.com/fraywing/textAngular/wiki for requirements a
function registerTextAngularTool(name, toolDefinition){
if(!name || name === '' || taTools.hasOwnProperty(name)) throw('textAngular Error: A unique name is required for a Tool Definition');
if(
(toolDefinition.display && (toolDefinition.display === '' || angular.element(toolDefinition.display).length === 0)) ||
(toolDefinition.display && (toolDefinition.display === '' || !validElementString(toolDefinition.display))) ||
(!toolDefinition.display && !toolDefinition.buttontext && !toolDefinition.iconclass)
)
throw('textAngular Error: Tool Definition for "' + name + '" does not have a valid display/iconclass/buttontext value');
Expand Down Expand Up @@ -250,20 +259,27 @@ See README.md or https://github.com/fraywing/textAngular/wiki for requirements a
scope.displayElements.popover.append(scope.displayElements.popoverContainer);
element.append(scope.displayElements.popover);

scope.displayElements.popover.on('mousedown', function(e){
scope.displayElements.popover.on('mousedown', function(e, eventData){
/* istanbul ignore else: this is for catching the jqLite testing*/
if(eventData) angular.extend(e, eventData);
// this prevents focusout from firing on the editor when clicking anything in the popover
e.preventDefault();
return false;
});

// define the popover show and hide functions
scope.showPopover = function(element){
scope.displayElements.popover.css('top', element[0].offsetTop + element[0].offsetHeight + 'px');
scope.displayElements.popover.css('left', element[0].offsetLeft + (element[0].offsetWidth / 2.0) - 152.5 + 'px');
scope.showPopover = function(_el){
scope.displayElements.popover.css('top', _el[0].offsetTop + _el[0].offsetHeight + 'px');
scope.displayElements.popover.css('left', _el[0].offsetLeft + (_el[0].offsetWidth / 2.0) - 152.5 + 'px');
scope.displayElements.popover.css('display', 'block');
$animate.addClass(scope.displayElements.popover, 'in');
$timeout(function(){
scope.displayElements.html.parent().one('click', scope.hidePopover);
// shim the .one till fixed
var _func = function(){
element.off('click', _func);
scope.hidePopover();
};
element.on('click', _func);
}, 100);
};
scope.hidePopover = function(){
Expand Down Expand Up @@ -519,7 +535,9 @@ See README.md or https://github.com/fraywing/textAngular/wiki for requirements a
scope.displayElements.html.on('keyup', _keyup);
scope.displayElements.text.on('keyup', _keyup);
// stop updating on key up and update the display/model
_keypress = function(event){
_keypress = function(event, eventData){
/* istanbul ignore else: this is for catching the jqLite testing*/
if(eventData) angular.extend(event, eventData);
scope.$apply(function(){
if(_toolbars.sendKeyCommand(event)){
/* istanbul ignore else: don't run if already running */
Expand Down Expand Up @@ -602,8 +620,9 @@ See README.md or https://github.com/fraywing/textAngular/wiki for requirements a
}, 0);
else e.preventDefault();
});
element.on('paste', function(e){
// timeout to next is needed as otherwise the paste/cut event has not finished actually changing the display
element.on('paste', function(e, eventData){
/* istanbul ignore else: this is for catching the jqLite testing*/
if(eventData) angular.extend(e, eventData);
var text;
// for non-ie
if(e.clipboardData || (e.originalEvent && e.originalEvent.clipboardData))
Expand Down Expand Up @@ -676,9 +695,11 @@ See README.md or https://github.com/fraywing/textAngular/wiki for requirements a
event.preventDefault();
return false;
};
var fileDropHandler = function(event){
var fileDropHandler = function(event, eventData){
/* istanbul ignore else: this is for catching the jqLite testing*/
if(eventData) angular.extend(event, eventData);
// emit the drop event, pass the element, preventing should be done elsewhere
if(!dropFired){
if(!dropFired && !_isReadonly){
dropFired = true;
var dataTransfer;
if(event.originalEvent) dataTransfer = event.originalEvent.dataTransfer;
Expand Down Expand Up @@ -960,7 +981,9 @@ See README.md or https://github.com/fraywing/textAngular/wiki for requirements a
toolElement.attr('tabindex', '-1');
toolElement.attr('ng-click', 'executeAction()');
toolElement.attr('ng-class', 'displayActiveToolClass(active)');
toolElement.on('mousedown', function(e){
toolElement.on('mousedown', function(e, eventData){
/* istanbul ignore else: this is for catching the jqLite testing*/
if(eventData) angular.extend(e, eventData);
// this prevents focusout from firing on the editor when clicking toolbar buttons
e.preventDefault();
return false;
Expand Down

0 comments on commit 311bdc0

Please sign in to comment.