From 36928858104ba793dfc7372dbaa28048123d6e63 Mon Sep 17 00:00:00 2001 From: TEHEK Firefox Date: Tue, 11 Oct 2011 22:37:00 +0000 Subject: fix(ng:options): compile null/blank option tag Fixes #562 --- test/widget/selectSpec.js | 78 +++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 76 insertions(+), 2 deletions(-) (limited to 'test/widget/selectSpec.js') diff --git a/test/widget/selectSpec.js b/test/widget/selectSpec.js index 63699d01..c3fdc2e6 100644 --- a/test/widget/selectSpec.js +++ b/test/widget/selectSpec.js @@ -130,8 +130,8 @@ describe('select', function() { } }); html += '>' + - (blank ? '' : '') + - (unknown ? '' : '') + + (blank ? (isString(blank) ? blank : '') : '') + + (unknown ? (isString(unknown) ? unknown : '') : '') + ''; select = jqLite(html); scope = compile(select); @@ -445,6 +445,80 @@ describe('select', function() { }); }); + + describe('blank option', function () { + it('should be compiled as template, be watched and updated', function () { + var option; + + createSingleSelect(''); + scope.blankVal = 'so blank'; + scope.values = [{name:'A'}]; + scope.$digest(); + + // check blank option is first and is compiled + expect(select.find('option').length == 2); + option = jqLite(select.find('option')[0]); + expect(option.val()).toBe(''); + expect(option.text()).toBe('blank is so blank'); + + // change blankVal and $digest + scope.blankVal = 'not so blank'; + scope.$digest(); + + // check blank option is first and is compiled + expect(select.find('option').length == 2); + option = jqLite(select.find('option')[0]); + expect(option.val()).toBe(''); + expect(option.text()).toBe('blank is not so blank'); + }); + + it('should support binding via ng:bind-template attribute', function () { + var option; + + createSingleSelect(''); + scope.blankVal = 'so blank'; + scope.values = [{name:'A'}]; + scope.$digest(); + + // check blank option is first and is compiled + expect(select.find('option').length == 2); + option = jqLite(select.find('option')[0]); + expect(option.val()).toBe(''); + expect(option.text()).toBe('blank is so blank'); + }); + + it('should support biding via ng:bind attribute', function () { + var option; + + createSingleSelect(''); + scope.blankVal = 'is blank'; + scope.values = [{name:'A'}]; + scope.$digest(); + + // check blank option is first and is compiled + expect(select.find('option').length == 2); + option = jqLite(select.find('option')[0]); + expect(option.val()).toBe(''); + expect(option.text()).toBe('is blank'); + }); + + it('should be rendered with the attributes preserved', function () { + var option; + + createSingleSelect(''); + scope.blankVal = 'is blank'; + scope.$digest(); + + // check blank option is first and is compiled + option = jqLite(select.find('option')[0]); + expect(option.hasClass('coyote')).toBeTruthy(); + expect(option.attr('id')).toBe('road-runner'); + expect(option.attr('custom-attr')).toBe('custom-attr'); + }); + }); + + describe('on change', function() { it('should update model on change', function() { createSingleSelect(); -- cgit v1.2.3