diff --git a/package.json b/package.json index 78cd771b6..dda889ca1 100644 --- a/package.json +++ b/package.json @@ -29,5 +29,9 @@ "karma-ng-html2js-preprocessor": "^0.1.0", "karma-phantomjs-launcher": "~0.1.4" }, + "scripts": { + "postinstall": "bower install", + "test": "gulp test" + }, "license": "MIT" } diff --git a/test/select.spec.js b/test/select.spec.js index a9709ab0c..79486df60 100644 --- a/test/select.spec.js +++ b/test/select.spec.js @@ -8,7 +8,7 @@ describe('ui-select tests', function() { $rootScope = _$rootScope_; scope = $rootScope.$new(); $compile = _$compile_; - + scope.selection = {} scope.getGroupLabel = function(person) { return person.age % 2 ? 'even' : 'odd'; }; @@ -42,7 +42,7 @@ describe('ui-select tests', function() { } return compileTemplate( - ' \ + ' \ {{$select.selected.name}} \ \
\ @@ -102,7 +102,7 @@ describe('ui-select tests', function() { }); it('should correctly render initial state', function() { - scope.selection = scope.people[0]; + scope.selection.selected = scope.people[0]; var el = createUiSelect(); @@ -178,7 +178,7 @@ describe('ui-select tests', function() { scope.items = ['false']; var el = compileTemplate( - ' \ + ' \ {{$select.selected}} \ \
\ @@ -199,7 +199,7 @@ describe('ui-select tests', function() { } function createUiSelect() { return compileTemplate( - ' \ + ' \ {{$select.selected.name}} \ \
\ @@ -249,7 +249,7 @@ describe('ui-select tests', function() { describe('choices group by function', function() { function createUiSelect() { return compileTemplate( - ' \ + ' \ {{$select.selected.name}} \ \
\ @@ -268,7 +268,7 @@ describe('ui-select tests', function() { it('should throw when no ui-select-choices found', function() { expect(function() { compileTemplate( - ' \ + ' \ \ ' ); @@ -278,7 +278,7 @@ describe('ui-select tests', function() { it('should throw when no repeat attribute is provided to ui-select-choices', function() { expect(function() { compileTemplate( - ' \ + ' \ \ ' ); @@ -288,9 +288,96 @@ describe('ui-select tests', function() { it('should throw when no ui-select-match found', function() { expect(function() { compileTemplate( - ' \ + ' \ \ ' ); }).toThrow(new Error('[ui.select:transcluded] Expected 1 .ui-select-match but got \'0\'.')); - });}); + }); + + it('should format the model correctly using alias', function() { + var el = compileTemplate( + ' \ + {{$select.selected.name}} \ + \ +
\ +
\ +
\ +
' + ); + clickItem(el, 'Samantha'); + expect(scope.selection.selected).toBe(scope.people[5]); + }); + + it('should parse the model correctly using alias', function() { + var el = compileTemplate( + ' \ + {{$select.selected.name}} \ + \ +
\ +
\ +
\ +
' + ); + scope.selection.selected = scope.people[5]; + scope.$digest(); + expect(getMatchLabel(el)).toEqual('Samantha'); + }); + + it('should format the model correctly using property of alias', function() { + var el = compileTemplate( + ' \ + {{$select.selected.name}} \ + \ +
\ +
\ +
\ +
' + ); + clickItem(el, 'Samantha'); + expect(scope.selection.selected).toBe('Samantha'); + }); + + it('should parse the model correctly using property of alias', function() { + var el = compileTemplate( + ' \ + {{$select.selected.name}} \ + \ +
\ +
\ +
\ +
' + ); + scope.selection.selected = 'Samantha'; + scope.$digest(); + expect(getMatchLabel(el)).toEqual('Samantha'); + }); + + it('should parse the model correctly using property of alias but passed whole object', function() { + var el = compileTemplate( + ' \ + {{$select.selected.name}} \ + \ +
\ +
\ +
\ +
' + ); + scope.selection.selected = scope.people[5]; + scope.$digest(); + expect(getMatchLabel(el)).toEqual('Samantha'); + }); + + it('should format the model correctly without alias', function() { + var el = createUiSelect(); + clickItem(el, 'Samantha'); + expect(scope.selection.selected).toBe(scope.people[5]); + }); + + it('should parse the model correctly without alias', function() { + var el = createUiSelect(); + scope.selection.selected = scope.people[5]; + scope.$digest(); + expect(getMatchLabel(el)).toEqual('Samantha'); + }); +});