-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bugfixes from the tests.
- Loading branch information
Simeon
authored and
Simeon
committed
Feb 17, 2014
1 parent
e7cd8d6
commit 8d70a4d
Showing
7 changed files
with
367 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.