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

Commit

Permalink
chore(typeahead): unify code style
Browse files Browse the repository at this point in the history
  • Loading branch information
wesleycho committed Aug 11, 2015
1 parent f3b68b3 commit 581161d
Show file tree
Hide file tree
Showing 5 changed files with 466 additions and 526 deletions.
19 changes: 9 additions & 10 deletions src/typeahead/test/typeahead-highlight.spec.js
Original file line number Diff line number Diff line change
@@ -1,39 +1,38 @@
describe('typeaheadHighlight', function () {

describe('typeaheadHighlight', function() {
var highlightFilter;

beforeEach(module('ui.bootstrap.typeahead'));
beforeEach(inject(function (typeaheadHighlightFilter) {
beforeEach(inject(function(typeaheadHighlightFilter) {
highlightFilter = typeaheadHighlightFilter;
}));

it('should higlight a match', function () {
it('should higlight a match', function() {
expect(highlightFilter('before match after', 'match')).toEqual('before <strong>match</strong> after');
});

it('should higlight a match with mixed case', function () {
it('should higlight a match with mixed case', function() {
expect(highlightFilter('before MaTch after', 'match')).toEqual('before <strong>MaTch</strong> after');
});

it('should higlight all matches', function () {
it('should higlight all matches', function() {
expect(highlightFilter('before MaTch after match', 'match')).toEqual('before <strong>MaTch</strong> after <strong>match</strong>');
});

it('should do nothing if no match', function () {
it('should do nothing if no match', function() {
expect(highlightFilter('before match after', 'nomatch')).toEqual('before match after');
});

it('should do nothing if no or empty query', function () {
it('should do nothing if no or empty query', function() {
expect(highlightFilter('before match after', '')).toEqual('before match after');
expect(highlightFilter('before match after', null)).toEqual('before match after');
expect(highlightFilter('before match after', undefined)).toEqual('before match after');
});

it('issue 316 - should work correctly for regexp reserved words', function () {
it('issue 316 - should work correctly for regexp reserved words', function() {
expect(highlightFilter('before (match after', '(match')).toEqual('before <strong>(match</strong> after');
});

it('issue 1777 - should work correctly with numeric values', function () {
it('issue 1777 - should work correctly with numeric values', function() {
expect(highlightFilter(123, '2')).toEqual('1<strong>2</strong>3');
});
});
15 changes: 6 additions & 9 deletions src/typeahead/test/typeahead-parser.spec.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
describe('syntax parser', function () {

describe('syntax parser', function() {
var typeaheadParser, scope, filterFilter;

beforeEach(module('ui.bootstrap.typeahead'));
beforeEach(inject(function (_$rootScope_, _filterFilter_, _typeaheadParser_) {
beforeEach(inject(function(_$rootScope_, _filterFilter_, _typeaheadParser_) {
typeaheadParser = _typeaheadParser_;
scope = _$rootScope_;
filterFilter = _filterFilter_;
}));

it('should parse the simplest array-based syntax', function () {
it('should parse the simplest array-based syntax', function() {
scope.states = ['Alabama', 'California', 'Delaware'];
var result = typeaheadParser.parse('state for state in states | filter:$viewValue');

Expand All @@ -22,8 +21,8 @@ describe('syntax parser', function () {
expect(result.modelMapper(scope, locals)).toEqual('Alabama');
});

it('should parse the simplest function-based syntax', function () {
scope.getStates = function ($viewValue) {
it('should parse the simplest function-based syntax', function() {
scope.getStates = function($viewValue) {
return filterFilter(['Alabama', 'California', 'Delaware'], $viewValue);
};
var result = typeaheadParser.parse('state for state in getStates($viewValue)');
Expand All @@ -38,7 +37,6 @@ describe('syntax parser', function () {
});

it('should allow to specify custom model mapping that is used as a label as well', function () {

scope.states = [
{code:'AL', name:'Alabama'},
{code:'CA', name:'California'},
Expand All @@ -59,8 +57,7 @@ describe('syntax parser', function () {
expect(result.modelMapper(scope, locals)).toEqual('Alabama');
});

it('should allow to specify custom view and model mappers', function () {

it('should allow to specify custom view and model mappers', function() {
scope.states = [
{code:'AL', name:'Alabama'},
{code:'CA', name:'California'},
Expand Down
14 changes: 5 additions & 9 deletions src/typeahead/test/typeahead-popup.spec.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
describe('typeaheadPopup - result rendering', function () {

describe('typeaheadPopup - result rendering', function() {
var scope, $rootScope, $compile;

beforeEach(module('ui.bootstrap.typeahead'));
beforeEach(module('template/typeahead/typeahead-popup.html'));
beforeEach(module('template/typeahead/typeahead-match.html'));
beforeEach(inject(function (_$rootScope_, _$compile_) {
beforeEach(inject(function(_$rootScope_, _$compile_) {
$rootScope = _$rootScope_;
scope = $rootScope.$new();
$compile = _$compile_;
}));

it('should render initial results', function () {

it('should render initial results', function() {
scope.matches = ['foo', 'bar', 'baz'];
scope.active = 1;

Expand All @@ -26,8 +24,7 @@ describe('typeaheadPopup - result rendering', function () {
expect(liElems.eq(2)).not.toHaveClass('active');
});

it('should change active item on mouseenter', function () {

it('should change active item on mouseenter', function() {
scope.matches = ['foo', 'bar', 'baz'];
scope.active = 1;

Expand All @@ -44,8 +41,7 @@ describe('typeaheadPopup - result rendering', function () {
expect(liElems.eq(2)).toHaveClass('active');
});

it('should select an item on mouse click', function () {

it('should select an item on mouse click', function() {
scope.matches = ['foo', 'bar', 'baz'];
scope.active = 1;
$rootScope.select = angular.noop;
Expand Down
Loading

0 comments on commit 581161d

Please sign in to comment.