|
1 | 1 | describe('typeaheadHighlight', function () {
|
2 | 2 |
|
3 |
| - var highlightFilter; |
| 3 | + var highlightFilter, $log, $sce, logSpy; |
4 | 4 |
|
5 | 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 | + |
6 | 13 | beforeEach(inject(function (typeaheadHighlightFilter) {
|
7 | 14 | highlightFilter = typeaheadHighlightFilter;
|
8 | 15 | }));
|
9 | 16 |
|
10 | 17 | it('should higlight a match', function () {
|
11 |
| - 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'); |
12 | 19 | });
|
13 | 20 |
|
14 | 21 | it('should higlight a match with mixed case', function () {
|
15 |
| - 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'); |
16 | 23 | });
|
17 | 24 |
|
18 | 25 | it('should higlight all matches', function () {
|
19 |
| - 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>'); |
20 | 27 | });
|
21 | 28 |
|
22 | 29 | it('should do nothing if no match', function () {
|
23 |
| - expect(highlightFilter('before match after', 'nomatch')).toEqual('before match after'); |
| 30 | + expect($sce.getTrustedHtml(highlightFilter('before match after', 'nomatch'))).toEqual('before match after'); |
24 | 31 | });
|
25 | 32 |
|
26 | 33 | it('should do nothing if no or empty query', function () {
|
27 |
| - expect(highlightFilter('before match after', '')).toEqual('before match after'); |
28 |
| - expect(highlightFilter('before match after', null)).toEqual('before match after'); |
29 |
| - 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'); |
30 | 37 | });
|
31 | 38 |
|
32 | 39 | it('issue 316 - should work correctly for regexp reserved words', function () {
|
33 |
| - 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'); |
34 | 41 | });
|
35 | 42 |
|
36 | 43 | it('issue 1777 - should work correctly with numeric values', function () {
|
37 |
| - expect(highlightFilter(123, '2')).toEqual('1<strong>2</strong>3'); |
| 44 | + expect($sce.getTrustedHtml(highlightFilter(123, '2'))).toEqual('1<strong>2</strong>3'); |
38 | 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(); |
| 50 | + }); |
| 51 | + |
39 | 52 | });
|
0 commit comments