forked from darylrowland/angucomplete
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove controller function as it was not used as controller function …
…and move the functions under link function. Remove setTimeout and use for better testability. Remove ng-keyup and use element.on
- Loading branch information
Showing
7 changed files
with
103 additions
and
31 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
node_modules | ||
bower_components | ||
components | ||
.*.swp | ||
.DS_Store |
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
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 |
---|---|---|
@@ -1,10 +1,88 @@ | ||
'use strict'; | ||
|
||
describe('angucomplete', function() { | ||
var $compile, $scope, $timeout; | ||
|
||
beforeEach(module('angucomplete')); | ||
|
||
it('should pass this simple test', function() { | ||
expect(true).toBe(true); | ||
beforeEach(inject(function(_$compile_, $rootScope, _$timeout_) { | ||
$compile = _$compile_; | ||
$scope = $rootScope.$new(); | ||
$timeout = _$timeout_; | ||
})); | ||
|
||
describe('Render', function() { | ||
|
||
it('should render input element with given id plus _value', function() { | ||
var element = angular.element('<div angucomplete id="ex1" selectedobject="selectedCountry" titlefield="name"></div>'); | ||
$scope.selectedCountry = null; | ||
$compile(element)($scope); | ||
$scope.$digest(); | ||
expect(element.find('#ex1_value').length).toBe(1); | ||
}); | ||
|
||
it('should render planceholder string', function() { | ||
var element = angular.element('<div angucomplete id="ex1" placeholder="Search countries" selectedobject="selectedCountry" localdata="countries" searchfields="name" titlefield="name"/>'); | ||
$scope.selectedCountry = null; | ||
$compile(element)($scope); | ||
$scope.$digest(); | ||
expect(element.find('#ex1_value').attr('placeholder')).toEqual('Search countries'); | ||
}); | ||
|
||
}); | ||
|
||
describe('Local data', function() { | ||
|
||
it('should show search results after 3 letter is entered', function() { | ||
var element = angular.element('<div angucomplete id="ex1" placeholder="Search countries" selectedobject="selectedCountry" localdata="countries" searchfields="name" titlefield="name"/>'); | ||
$scope.selectedCountry = undefined; | ||
$scope.countries = [ | ||
{name: 'Afghanistan', code: 'AF'}, | ||
{name: 'Aland Islands', code: 'AX'}, | ||
{name: 'Albania', code: 'AL'} | ||
]; | ||
$compile(element)($scope); | ||
$scope.$digest(); | ||
var inputField = element.find('#ex1_value'); | ||
var e = $.Event('keyup'); | ||
e.which = 97; // letter: a | ||
|
||
inputField.val('a'); | ||
inputField.trigger('input'); | ||
inputField.trigger(e); | ||
expect(element.find('#ex1_dropdown').length).toBe(0); | ||
|
||
inputField.val('aa'); | ||
inputField.trigger('input'); | ||
inputField.trigger(e); | ||
expect(element.find('#ex1_dropdown').length).toBe(0); | ||
|
||
inputField.val('aaa'); | ||
inputField.trigger('input'); | ||
inputField.trigger(e); | ||
$timeout.flush(); | ||
expect(element.find('#ex1_dropdown').length).toBe(1); | ||
}); | ||
|
||
it('should show search results after 1 letter is entered with minlength being set to 1', function() { | ||
var element = angular.element('<div angucomplete id="ex1" placeholder="Search countries" selectedobject="selectedCountry" localdata="countries" searchfields="name" titlefield="name" minlength="1"/>'); | ||
$scope.selectedCountry = undefined; | ||
$scope.countries = [ | ||
{name: 'Afghanistan', code: 'AF'}, | ||
{name: 'Aland Islands', code: 'AX'}, | ||
{name: 'Albania', code: 'AL'} | ||
]; | ||
$compile(element)($scope); | ||
$scope.$digest(); | ||
var inputField = element.find('#ex1_value'); | ||
var e = $.Event('keyup'); | ||
e.which = 97; // letter: a | ||
inputField.val('a'); | ||
inputField.trigger('input'); | ||
inputField.trigger(e); | ||
$timeout.flush(); | ||
expect(element.find('#ex1_dropdown').length).toBe(1); | ||
}); | ||
}); | ||
|
||
}); |
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