diff options
| author | Misko Hevery | 2010-09-21 19:20:34 +0200 |
|---|---|---|
| committer | Misko Hevery | 2010-09-21 19:20:34 +0200 |
| commit | 006fd2ca252400e87a419b929e00ea0277ff86ad (patch) | |
| tree | fcf3c021aa5c1e95dc2a43cc0d3f019b541d3ce5 /test | |
| parent | 125d725e7dcd76b838925ac997b35afad4266752 (diff) | |
| download | angular.js-006fd2ca252400e87a419b929e00ea0277ff86ad.tar.bz2 | |
HEAD is now at 10c0151 Fixes on issue when a SELECT has OPTION which are data bound (ie OPTION has repeater or OPTION.value is bound), then SELECT does not update to match the correct OPTION after the change in model (ie after the OPTION repeater unrolls or OPTION.value is changed.)
Diffstat (limited to 'test')
| -rw-r--r-- | test/ScopeSpec.js | 23 | ||||
| -rw-r--r-- | test/testabilityPatch.js | 3 | ||||
| -rw-r--r-- | test/widgetsSpec.js | 32 |
3 files changed, 54 insertions, 4 deletions
diff --git a/test/ScopeSpec.js b/test/ScopeSpec.js index ea63fea4..66e9d489 100644 --- a/test/ScopeSpec.js +++ b/test/ScopeSpec.js @@ -192,4 +192,27 @@ describe('scope/model', function(){ }); }); + + describe('$postEval', function(){ + it('should eval function once and last', function(){ + var log = ''; + var scope = createScope(); + function onceOnly(){log+= '@';} + scope.$onEval(function(){log+= '.';}); + scope.$postEval(function(){log+= '!';}); + scope.$postEval(onceOnly); + scope.$postEval(onceOnly); + scope.$postEval(); // ignore + scope.$eval(); + expect(log).toEqual('.!@'); + scope.$eval(); + expect(log).toEqual('.!@.'); + + scope.$postEval(onceOnly); + scope.$postEval(onceOnly); + scope.$eval(); + expect(log).toEqual('.!@..@'); + }); + }); + }); diff --git a/test/testabilityPatch.js b/test/testabilityPatch.js index bbe2876e..955dccfa 100644 --- a/test/testabilityPatch.js +++ b/test/testabilityPatch.js @@ -59,7 +59,7 @@ extend(angular, { function sortedHtml(element) { var html = ""; - foreach(element, function toString(node) { + foreach(jqLite(element), function toString(node) { if (node.nodeName == "#text") { html += escapeHtml(node.nodeValue); } else { @@ -188,6 +188,7 @@ function click(element) { } } if (name == 'option') { + element.parent().val(element.val()); JQLite.prototype.trigger.call(element.parent(), 'change'); } else { JQLite.prototype.trigger.call(element, 'click'); diff --git a/test/widgetsSpec.js b/test/widgetsSpec.js index 3861ef4f..d113e6ee 100644 --- a/test/widgetsSpec.js +++ b/test/widgetsSpec.js @@ -355,9 +355,9 @@ describe("widget", function(){ it('should honor the value field in option', function(){ compile( '<select name="selection" ng:format="number">' + - '<option value="{{$index}}" ng:repeat="name in [\'A\', \'B\']">{{name}}</option>' + + '<option value="{{$index}}" ng:repeat="name in [\'A\', \'B\', \'C\']">{{name}}</option>' + '</select>'); - // childNodes[0] is repeater + // childNodes[0] is repeater comment expect(scope.selection).toEqual(undefined); click(element[0].childNodes[1]); @@ -367,6 +367,32 @@ describe("widget", function(){ scope.$eval(); expect(element[0].childNodes[2].selected).toEqual(true); }); + + it('should unroll select options before eval', function(){ + compile( + '<select name="selection" ng:required>' + + '<option value="{{$index}}" ng:repeat="opt in options">{{opt}}</option>' + + '</select>'); + scope.selection = 1; + scope.options = ['one', 'two']; + scope.$eval(); + expect(element[0].value).toEqual('1'); + expect(element.hasClass(NG_VALIDATION_ERROR)).toEqual(false); + }); + + it('should update select when value changes', function(){ + compile( + '<select name="selection">' + + '<option value="...">...</option>' + + '<option value="{{value}}">B</option>' + + '</select>'); + scope.selection = 'B'; + scope.$eval(); + expect(element[0].childNodes[1].selected).toEqual(false); + scope.value = 'B'; + scope.$eval(); + expect(element[0].childNodes[1].selected).toEqual(true); + }); }); it('should support type="select-multiple"', function(){ @@ -468,7 +494,7 @@ describe("widget", function(){ scope.url = undefined; scope.$eval(); - + expect(element.text()).toEqual(''); }); }); |
