|
1 |
| -describe('typeaheadHighlight', function() { |
2 |
| - var highlightFilter; |
| 1 | +describe('typeaheadHighlight', function () { |
| 2 | + |
| 3 | + var highlightFilter, $log, $sce, logSpy; |
3 | 4 |
|
4 | 5 | beforeEach(module('ui.bootstrap.typeahead'));
|
| 6 | + |
| 7 | + beforeEach(inject(function(_$log_, _$sce_) { |
| 8 | + $log = _$log_; |
| 9 | + $sce = _$sce_; |
| 10 | + logSpy = spyOn($log, 'warn'); |
| 11 | + })); |
| 12 | + |
5 | 13 | beforeEach(inject(function(typeaheadHighlightFilter) {
|
6 | 14 | highlightFilter = typeaheadHighlightFilter;
|
7 | 15 | }));
|
8 | 16 |
|
9 | 17 | it('should higlight a match', function() {
|
10 |
| - expect(highlightFilter('before match after', 'match')).toEqual('before <strong>match</strong> after'); |
| 18 | + expect($sce.getTrustedHtml(highlightFilter('before match after', 'match'))).toEqual('before <strong>match</strong> after'); |
11 | 19 | });
|
12 | 20 |
|
13 | 21 | it('should higlight a match with mixed case', function() {
|
14 |
| - expect(highlightFilter('before MaTch after', 'match')).toEqual('before <strong>MaTch</strong> after'); |
| 22 | + expect($sce.getTrustedHtml(highlightFilter('before MaTch after', 'match'))).toEqual('before <strong>MaTch</strong> after'); |
15 | 23 | });
|
16 | 24 |
|
17 | 25 | it('should higlight all matches', function() {
|
18 |
| - expect(highlightFilter('before MaTch after match', 'match')).toEqual('before <strong>MaTch</strong> after <strong>match</strong>'); |
| 26 | + expect($sce.getTrustedHtml(highlightFilter('before MaTch after match', 'match'))).toEqual('before <strong>MaTch</strong> after <strong>match</strong>'); |
19 | 27 | });
|
20 | 28 |
|
21 | 29 | it('should do nothing if no match', function() {
|
22 |
| - expect(highlightFilter('before match after', 'nomatch')).toEqual('before match after'); |
| 30 | + expect($sce.getTrustedHtml(highlightFilter('before match after', 'nomatch'))).toEqual('before match after'); |
23 | 31 | });
|
24 | 32 |
|
25 | 33 | it('should do nothing if no or empty query', function() {
|
26 |
| - expect(highlightFilter('before match after', '')).toEqual('before match after'); |
27 |
| - expect(highlightFilter('before match after', null)).toEqual('before match after'); |
28 |
| - expect(highlightFilter('before match after', undefined)).toEqual('before match after'); |
| 34 | + expect($sce.getTrustedHtml(highlightFilter('before match after', ''))).toEqual('before match after'); |
| 35 | + expect($sce.getTrustedHtml(highlightFilter('before match after', null))).toEqual('before match after'); |
| 36 | + expect($sce.getTrustedHtml(highlightFilter('before match after', undefined))).toEqual('before match after'); |
29 | 37 | });
|
30 | 38 |
|
31 | 39 | it('issue 316 - should work correctly for regexp reserved words', function() {
|
32 |
| - expect(highlightFilter('before (match after', '(match')).toEqual('before <strong>(match</strong> after'); |
| 40 | + expect($sce.getTrustedHtml(highlightFilter('before (match after', '(match'))).toEqual('before <strong>(match</strong> after'); |
33 | 41 | });
|
34 | 42 |
|
35 | 43 | it('issue 1777 - should work correctly with numeric values', function() {
|
36 |
| - expect(highlightFilter(123, '2')).toEqual('1<strong>2</strong>3'); |
| 44 | + expect($sce.getTrustedHtml(highlightFilter(123, '2'))).toEqual('1<strong>2</strong>3'); |
| 45 | + }); |
| 46 | + |
| 47 | + it('should show a warning when this component is being used unsafely', function() { |
| 48 | + highlightFilter('<i>before</i> match after', 'match'); |
| 49 | + expect(logSpy).toHaveBeenCalled(); |
37 | 50 | });
|
38 | 51 | });
|
0 commit comments