forked from angular-ui/bootstrap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtypeahead-highlight.spec.js
78 lines (61 loc) · 3.12 KB
/
typeahead-highlight.spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
describe('typeaheadHighlight', function () {
var highlightFilter, $log, $sce, logSpy;
beforeEach(module('ui.bootstrap.typeahead'));
beforeEach(inject(function(_$log_, _$sce_) {
$log = _$log_;
$sce = _$sce_;
logSpy = spyOn($log, 'warn');
}));
beforeEach(inject(function(uibTypeaheadHighlightFilter) {
highlightFilter = uibTypeaheadHighlightFilter;
}));
it('should higlight a match', function() {
expect($sce.getTrustedHtml(highlightFilter('before match after', 'match'))).toEqual('before <strong>match</strong> after');
});
it('should higlight a match with mixed case', function() {
expect($sce.getTrustedHtml(highlightFilter('before MaTch after', 'match'))).toEqual('before <strong>MaTch</strong> after');
});
it('should higlight all matches', function() {
expect($sce.getTrustedHtml(highlightFilter('before MaTch after match', 'match'))).toEqual('before <strong>MaTch</strong> after <strong>match</strong>');
});
it('should do nothing if no match', function() {
expect($sce.getTrustedHtml(highlightFilter('before match after', 'nomatch'))).toEqual('before match after');
});
it('should do nothing if no or empty query', function() {
expect($sce.getTrustedHtml(highlightFilter('before match after', ''))).toEqual('before match after');
expect($sce.getTrustedHtml(highlightFilter('before match after', null))).toEqual('before match after');
expect($sce.getTrustedHtml(highlightFilter('before match after', undefined))).toEqual('before match after');
});
it('issue 316 - should work correctly for regexp reserved words', function() {
expect($sce.getTrustedHtml(highlightFilter('before (match after', '(match'))).toEqual('before <strong>(match</strong> after');
});
it('issue 1777 - should work correctly with numeric values', function() {
expect($sce.getTrustedHtml(highlightFilter(123, '2'))).toEqual('1<strong>2</strong>3');
});
it('should show a warning when this component is being used unsafely', function() {
highlightFilter('<i>before</i> match after', 'match');
expect(logSpy).toHaveBeenCalled();
});
});
describe('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.']);
}));
});