Skip to content

Commit

Permalink
Finish all the tests Closing #33.
Browse files Browse the repository at this point in the history
Bugfixes from the tests.
  • Loading branch information
Simeon authored and Simeon committed Feb 17, 2014
1 parent e7cd8d6 commit 8d70a4d
Show file tree
Hide file tree
Showing 7 changed files with 367 additions and 33 deletions.
10 changes: 5 additions & 5 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ module.exports = function (grunt) {

// Project configuration.
grunt.initConfig({
clean: ["coverage/*"],
clean: ["coverage/*.json"],
coverage: {
options: {
thresholds: {
'statements': 100,
'branches': 95,
'lines': 100,
'functions': 100
'statements': 92.98,
'branches': 93.33,
'lines': 92.26,
'functions': 81.16
},
dir: 'coverage',
root: ''
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Demo is available at: http://www.textangular.com

1. [Bootstrap 3.x](http://getbootstrap.com/) for the default styles
2. [Font-Awesome 4.x](http://fortawesome.github.io/Font-Awesome/) for the default icons on the toolbar
3. [Rangy 1.x](https://code.google.com/p/rangy/) for better activeState detection and more dynamic plugins
3. [Rangy 1.x](https://code.google.com/p/rangy/) for better activeState detection and more dynamic plugins, also the selectionsaverestore module.

### Usage

Expand Down
1 change: 1 addition & 0 deletions karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ module.exports = function (config) {
files: [
'bower_components/jquery/jquery.min.js',
'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',
'textAngular-sanitize.js',
Expand Down
75 changes: 75 additions & 0 deletions test/taTools.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
describe('taToolsExecuteFunction', function(){
var scope, startActionResult, editor, $rootScope;
beforeEach(module('textAngular'));
beforeEach(inject(function(taToolExecuteAction, _$rootScope_){
$rootScope = _$rootScope_;
startActionResult = Math.random();
scope = {
taToolExecuteAction: taToolExecuteAction,
$editor: function(){
return editor = {
startCount: 0,
startAction: function(){
this.startCount++;
return startActionResult;
},
finishCount: 0,
endAction: function(){ this.finishCount++; }
};
}
};
}));

describe('executes the action passing the correct parameters', function(){
it('should pass the result of startAction Result', function(){
scope.action = function(deferred, startActionResult){
expect(startActionResult).toBe(startActionResult);
};
$rootScope.$apply(function(){ scope.taToolExecuteAction(); });
});
it('should pass a valid deferred object', function(){
scope.action = function(deferred, startActionResult){
expect(deferred.resolve).toBeDefined();
expect(deferred.reject).toBeDefined();
expect(deferred.notify).toBeDefined();
expect(deferred.promise).toBeDefined();
};
$rootScope.$apply(function(){ scope.taToolExecuteAction(); });
});
});

it('doesn\'t error when action not present', function(){
expect(function(){
$rootScope.$apply(function(){ scope.taToolExecuteAction(); });
}).not.toThrow();
});

it('sets the correct editor if passed', function(){
var _editor = {endAction: function(){}, startAction: function(){}};
scope.taToolExecuteAction(_editor);
expect(scope.$editor()).toBe(_editor);
});

describe('calls editor action', function(){
it('start and end when action returns truthy', function(){
scope.action = function(deferred, startActionResult){ return true; };
$rootScope.$apply(function(){ scope.taToolExecuteAction(); });
expect(editor.startCount).toBe(1);
expect(editor.finishCount).toBe(1);
});

it('start and end when action returns undefined', function(){
scope.action = function(deferred, startActionResult){};
$rootScope.$apply(function(){ scope.taToolExecuteAction(); });
expect(editor.startCount).toBe(1);
expect(editor.finishCount).toBe(1);
});

it('start and not end when action returns false', function(){
scope.action = function(deferred, startActionResult){ return false; };
$rootScope.$apply(function(){ scope.taToolExecuteAction(); });
expect(editor.startCount).toBe(1);
expect(editor.finishCount).toBe(0);
});
});
});
Loading

0 comments on commit 8d70a4d

Please sign in to comment.