Skip to content
This repository has been archived by the owner on May 29, 2019. It is now read-only.

Commit

Permalink
feat(typeahead): add uib- prefix
Browse files Browse the repository at this point in the history
Closes #4542
  • Loading branch information
BobbieBarker authored and wesleycho committed Oct 7, 2015
1 parent 038157d commit 9e5e1a2
Show file tree
Hide file tree
Showing 8 changed files with 745 additions and 107 deletions.
12 changes: 6 additions & 6 deletions src/typeahead/docs/demo.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
<script type="text/ng-template" id="customTemplate.html">
<a>
<img ng-src="http://upload.wikimedia.org/wikipedia/commons/thumb/{{match.model.flag}}" width="16">
<span ng-bind-html="match.label | typeaheadHighlight:query"></span>
<span ng-bind-html="match.label | uibTypeaheadHighlight:query"></span>
</a>
</script>

Expand All @@ -44,7 +44,7 @@
<ul class="dropdown-menu" role="listbox">
<li ng-repeat="match in matches track by $index" ng-class="{active: isActive($index) }"
ng-mouseenter="selectActive($index)" ng-click="selectMatch($index)" role="option" id="{{::match.id}}">
<div typeahead-match index="$index" match="match" query="query" template-url="templateUrl"></div>
<div uib-typeahead-match index="$index" match="match" query="query" template-url="templateUrl"></div>
</li>
</ul>
</div>
Expand All @@ -54,21 +54,21 @@

<h4>Static arrays</h4>
<pre>Model: {{selected | json}}</pre>
<input type="text" ng-model="selected" typeahead="state for state in states | filter:$viewValue | limitTo:8" class="form-control">
<input type="text" ng-model="selected" uib-typeahead="state for state in states | filter:$viewValue | limitTo:8" class="form-control">

<h4>Asynchronous results</h4>
<pre>Model: {{asyncSelected | json}}</pre>
<input type="text" ng-model="asyncSelected" placeholder="Locations loaded via $http" typeahead="address for address in getLocation($viewValue)" typeahead-loading="loadingLocations" typeahead-no-results="noResults" class="form-control">
<input type="text" ng-model="asyncSelected" placeholder="Locations loaded via $http" uib-typeahead="address for address in getLocation($viewValue)" typeahead-loading="loadingLocations" typeahead-no-results="noResults" class="form-control">
<i ng-show="loadingLocations" class="glyphicon glyphicon-refresh"></i>
<div ng-show="noResults">
<i class="glyphicon glyphicon-remove"></i> No Results Found
</div>

<h4>Custom templates for results</h4>
<pre>Model: {{customSelected | json}}</pre>
<input type="text" ng-model="customSelected" placeholder="Custom template" typeahead="state as state.name for state in statesWithFlags | filter:{name:$viewValue}" typeahead-template-url="customTemplate.html" class="form-control">
<input type="text" ng-model="customSelected" placeholder="Custom template" uib-typeahead="state as state.name for state in statesWithFlags | filter:{name:$viewValue}" typeahead-template-url="customTemplate.html" class="form-control">

<h4>Custom popup templates for typeahead's dropdown</h4>
<pre>Model: {{customPopupSelected | json}}</pre>
<input type="text" ng-model="customPopupSelected" placeholder="Custom popup template" typeahead="state as state.name for state in statesWithFlags | filter:{name:$viewValue}" typeahead-popup-template-url="customPopupTemplate.html" class="form-control">
<input type="text" ng-model="customPopupSelected" placeholder="Custom popup template" uib-typeahead="state as state.name for state in statesWithFlags | filter:{name:$viewValue}" typeahead-popup-template-url="customPopupTemplate.html" class="form-control">
</div>
4 changes: 2 additions & 2 deletions src/typeahead/test/typeahead-highlight-ngsanitize.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ describe('Security concerns', function() {

beforeEach(module('ui.bootstrap.typeahead', 'ngSanitize'));

beforeEach(inject(function (typeaheadHighlightFilter, _$sanitize_, $log) {
highlightFilter = typeaheadHighlightFilter;
beforeEach(inject(function (uibTypeaheadHighlightFilter, _$sanitize_, $log) {
highlightFilter = uibTypeaheadHighlightFilter;
$sanitize = _$sanitize_;
logSpy = spyOn($log, 'warn');
}));
Expand Down
33 changes: 31 additions & 2 deletions src/typeahead/test/typeahead-highlight.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ describe('typeaheadHighlight', function () {
logSpy = spyOn($log, 'warn');
}));

beforeEach(inject(function(typeaheadHighlightFilter) {
highlightFilter = typeaheadHighlightFilter;
beforeEach(inject(function(uibTypeaheadHighlightFilter) {
highlightFilter = uibTypeaheadHighlightFilter;
}));

it('should higlight a match', function() {
Expand Down Expand Up @@ -49,3 +49,32 @@ describe('typeaheadHighlight', function () {
expect(logSpy).toHaveBeenCalled();
});
});

/* Deprecation tests below */

describe('typeahead highlightFilter deprecated', function(){
var highlightFilter, $log, $sce, logSpy;

beforeEach(module('ui.bootstrap.typeahead'));

it('should supress the warning by default', function(){
module(function($provide) {
$provide.value('$typeaheadSuppressWarning', true);
});

inject(function($compile, $log, $rootScope, typeaheadHighlightFilter, $sce){
spyOn($log, 'warn');
var highlightFilter = typeaheadHighlightFilter;
$sce.getTrustedHtml(highlightFilter('before match after', 'match'));
expect($log.warn.calls.count()).toBe(0);
});
});

it('should decrecate typeaheadHighlightFilter', inject(function($compile, $log, $rootScope, typeaheadHighlightFilter, $sce){
spyOn($log, 'warn');
var highlightFilter = typeaheadHighlightFilter;
$sce.getTrustedHtml(highlightFilter('before match after', 'match'));
expect($log.warn.calls.count()).toBe(1);
expect($log.warn.calls.argsFor(0)).toEqual(['typeaheadHighlight is now deprecated. Use uibTypeaheadHighlight instead.']);
}));
});
50 changes: 47 additions & 3 deletions src/typeahead/test/typeahead-popup.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ describe('typeaheadPopup - result rendering', function() {
scope.matches = ['foo', 'bar', 'baz'];
scope.active = 1;

var el = $compile('<div><typeahead-popup matches="matches" active="active" select="select(activeIdx)"></typeahead-popup></div>')(scope);
var el = $compile('<div><uib-typeahead-popup matches="matches" active="active" select="select(activeIdx)"></uib-typeahead-popup></div>')(scope);
$rootScope.$digest();

var liElems = el.find('li');
Expand All @@ -28,7 +28,7 @@ describe('typeaheadPopup - result rendering', function() {
scope.matches = ['foo', 'bar', 'baz'];
scope.active = 1;

var el = $compile('<div><typeahead-popup matches="matches" active="active" select="select(activeIdx)"></typeahead-popup></div>')(scope);
var el = $compile('<div><uib-typeahead-popup matches="matches" active="active" select="select(activeIdx)"></uib-typeahead-popup></div>')(scope);
$rootScope.$digest();

var liElems = el.find('li');
Expand All @@ -47,11 +47,55 @@ describe('typeaheadPopup - result rendering', function() {
$rootScope.select = angular.noop;
spyOn($rootScope, 'select');

var el = $compile('<div><typeahead-popup matches="matches" active="active" select="select(activeIdx)"></typeahead-popup></div>')(scope);
var el = $compile('<div><uib-typeahead-popup matches="matches" active="active" select="select(activeIdx)"></uib-typeahead-popup></div>')(scope);
$rootScope.$digest();

var liElems = el.find('li');
liElems.eq(2).find('a').trigger('click');
expect($rootScope.select).toHaveBeenCalledWith(2);
});
});

/* Deprecation tests below */

describe('typeaheadPopup deprecation', function() {
beforeEach(module('ui.bootstrap.typeahead'));
beforeEach(module('ngSanitize'));
beforeEach(module('template/typeahead/typeahead-popup.html'));
beforeEach(module('template/typeahead/typeahead-match.html'));

it('should suppress warning', function() {
module(function($provide) {
$provide.value('$typeaheadSuppressWarning', true);
});

inject(function($compile, $log, $rootScope) {
var scope = $rootScope.$new();
scope.matches = ['foo', 'bar', 'baz'];
scope.active = 1;
$rootScope.select = angular.noop;
spyOn($log, 'warn');

var element = '<div><typeahead-popup matches="matches" active="active" select="select(activeIdx)"></typeahead-popup></div>';
element = $compile(element)(scope);
$rootScope.$digest();
expect($log.warn.calls.count()).toBe(0);
});
});

it('should give warning by default', inject(function($compile, $log, $rootScope) {
var scope = $rootScope.$new();
scope.matches = ['foo', 'bar', 'baz'];
scope.active = 1;
$rootScope.select = angular.noop;
spyOn($log, 'warn');

var element = '<div><typeahead-popup matches="matches" active="active" select="select(activeIdx)"></typeahead-popup></div>';
element = $compile(element)(scope);

$rootScope.$digest();

expect($log.warn.calls.count()).toBe(1);
expect($log.warn.calls.argsFor(0)).toEqual(['typeahead-popup is now deprecated. Use uib-typeahead-popup instead.']);
}));
});
Loading

0 comments on commit 9e5e1a2

Please sign in to comment.